Commit e3a51554 authored by Geoffroy ARNOUD's avatar Geoffroy ARNOUD

Manage $disableRemoteLogo directly in the generation of the JSON stream #K11

parent 980db79e
<?php // Copyright (c) 2019, SWITCH ?>
<?php // Copyright (c) 2019, SWITCH?>
<!DOCTYPE HTML>
<html>
<head>
......@@ -13,7 +13,8 @@
<?php
if ($useSelect2) {
echo '<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />'.PHP_EOL;
echo '<link rel="stylesheet" href="'. $_SERVER['SCRIPT_NAME'] .'/select2.css" type="text/css" >'.PHP_EOL;
// echo '<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet" />'.PHP_EOL;
echo '<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>'.PHP_EOL;
echo '<script type="text/javascript" src="'.$javascriptURL .'/select2Functions.js"></script>'.PHP_EOL;
} elseif ($useImprovedDropDownList) {
......@@ -94,8 +95,8 @@
if (<?php echo ($useSelect2) ? 'true' : 'false' ?>){
$('.userIdPSelection').select2({
ajax: {
url: <?php echo "'".$_SERVER['REQUEST_URI']."api/idps'" ?>,
delay: 1000,
url: <?php echo "'".$apiURL."/idps'" ?>,
delay: 250,
dataType: 'json',
data: function (params) {
var query = {
......
......@@ -10,6 +10,27 @@ $topLevelDir = dirname(__DIR__);
require_once($topLevelDir . '/lib/functions.php');
function getImage($imageString)
{
global $disableRemoteLogos;
$image = '';
$pos = strpos($imageString, "data:image");
if ($pos === false) {
// remote image
if (!$disableRemoteLogos) {
$image = $imageString;
}
} else {
// embedded image
$image = $imageString;
}
return $image;
}
/*
* This class models an IdP to be easily translated to Json
*/
......@@ -52,7 +73,7 @@ final class IdpObject
}
if ($key == "Logo") {
if (sizeof($value) > 0) {
$this->logo = $value{"URL"};
$this->logo = getImage($value{"URL"});
}
}
// languages
......@@ -101,11 +122,22 @@ final class IdpRepository
public function __construct(array $IDProviders = array(), array $previouslySelectedIdps = null)
{
if ($previouslySelectedIdps != null) {
foreach ($previouslySelectedIdps as $selIdp) {
global $showNumOfPreviouslyUsedIdPs;
if (isset($previouslySelectedIdps) && count($previouslySelectedIdps) > 0) {
$counter = (isset($showNumOfPreviouslyUsedIdPs)) ? $showNumOfPreviouslyUsedIdPs : 3;
for ($n = count($previouslySelectedIdps) - 1; $n >= 0; $n--) {
if ($counter <= 0) {
break;
}
$selIdp = $previouslySelectedIdps[$n];
$idp = new IdpObject($selIdp, $IDProviders[$selIdp]);
$idp->type = getLocalString('last_used');
$this->idpObjects[] = $idp;
$counter--;
}
}
......
......@@ -27,11 +27,48 @@ final class IdpApiTest extends TestCase
require("test.IDProvider.metadata.php");
$repo = new IdpRepository($metadataIDProviders);
$this->assertEquals(
'{"results":[{"text":"Ecole avec accents","children":[{"id":"https://rigal.enpc.fr/idp/shibboleth","text":"\u00c9cole des Ponts ParisTech","entityId":"https://rigal.enpc.fr/idp/shibboleth","SSO":"https://rigal.enpc.fr/idp/profile/Shibboleth/SSO","name":"\u00c9cole des Ponts ParisTech","names":{"en":"\u00c9cole des Ponts ParisTech","fr":"\u00c9cole des Ponts ParisTech"},"protocols":"urn:oasis:names:tc:SAML:1.1:protocol urn:mace:shibboleth:1.0 urn:oasis:names:tc:SAML:2.0:protocol","logo":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAAAQAAAAEABcxq3DAAAB7ElEQVQoz42Rz2/SYBjHX/rSvmW0sK6WhLLLPIhwdX+C2YWYGdDIMJpF/Z+W6XHxJgtTTCZb0xX5ddOMpWNhbiCQFHugykvXtQIeZjAq030vT57n+X6e7+EB40tUq9WmzgkwTUo+n9l6Xa+f/L2aAti2fXhY43m+WHx/JeBdLufz+Z49fWJZ5/l84T+A1taOjuosy8qywnFctboPgP0vICdLPpYV5vhIJMzz3HA4yr7duRSoVqvn1tnq6mNsDnRdh5CMx++22x1dNyYe13g8njRra+sQQp6f6/f7hvFVEK55PDOtdksQhNRK8s+EQqHQM3qI9tA0EoRAOHzDP+tHCHloz+dmS1XVC5v7ohiGcXCgLt5a7HTasVhsckXX9Wy2G4ncLJUr0Wj0V8LurkTTaGnpNgFhJrM1Aba3cxzHLS/fGY9GiqL8BJrN5snpKULoVXqTdLuPjz9pmgYAUFW12/3iOE46vQkh/PBxH9g2AQDIF4pBURTF4L1EPBAQQvPi3p4CACiXK6IYDIXmE4n4wsJ1lmHe5HaIUqmCv/UfPUwBACRJpih6JZnEeLCx8ZKiUCqVNM2BJMkkCRMP7jcaDdf68xcYY5Zhvg+Hpml6Z7wQuswzC2M86/eTFOU4jmVZjJdxES7D6P32h6voB98GBPZakOIQAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE1LTA3LTIwVDEwOjUwOjIwKzAyOjAwq4YxQQAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxNS0wNy0yMFQxMDo1MDoyMCswMjowMNrbif0AAAAASUVORK5CYII=","type":"Ecole avec accents"}]}],"paginate":{"more":false}}',
'{"results":[{"text":"Ecole avec accents","children":[{"id":"https://rigal.enpc.fr/idp/shibboleth","text":"\u00c9cole des Ponts ParisTech","entityId":"https://rigal.enpc.fr/idp/shibboleth","SSO":"https://rigal.enpc.fr/idp/profile/Shibboleth/SSO","name":"\u00c9cole des Ponts ParisTech","names":{"en":"\u00c9cole des Ponts ParisTech","fr":"\u00c9cole des Ponts ParisTech"},"protocols":"urn:oasis:names:tc:SAML:1.1:protocol urn:mace:shibboleth:1.0 urn:oasis:names:tc:SAML:2.0:protocol","logo":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAACXBIWXMAAABIAAAASABGyWs+AAAACXZwQWcAAAAQAAAAEABcxq3DAAAB7ElEQVQoz42Rz2/SYBjHX/rSvmW0sK6WhLLLPIhwdX+C2YWYGdDIMJpF/Z+W6XHxJgtTTCZb0xX5ddOMpWNhbiCQFHugykvXtQIeZjAq030vT57n+X6e7+EB40tUq9WmzgkwTUo+n9l6Xa+f/L2aAti2fXhY43m+WHx/JeBdLufz+Z49fWJZ5/l84T+A1taOjuosy8qywnFctboPgP0vICdLPpYV5vhIJMzz3HA4yr7duRSoVqvn1tnq6mNsDnRdh5CMx++22x1dNyYe13g8njRra+sQQp6f6/f7hvFVEK55PDOtdksQhNRK8s+EQqHQM3qI9tA0EoRAOHzDP+tHCHloz+dmS1XVC5v7ohiGcXCgLt5a7HTasVhsckXX9Wy2G4ncLJUr0Wj0V8LurkTTaGnpNgFhJrM1Aba3cxzHLS/fGY9GiqL8BJrN5snpKULoVXqTdLuPjz9pmgYAUFW12/3iOE46vQkh/PBxH9g2AQDIF4pBURTF4L1EPBAQQvPi3p4CACiXK6IYDIXmE4n4wsJ1lmHe5HaIUqmCv/UfPUwBACRJpih6JZnEeLCx8ZKiUCqVNM2BJMkkCRMP7jcaDdf68xcYY5Zhvg+Hpml6Z7wQuswzC2M86/eTFOU4jmVZjJdxES7D6P32h6voB98GBPZakOIQAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE1LTA3LTIwVDEwOjUwOjIwKzAyOjAwq4YxQQAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxNS0wNy0yMFQxMDo1MDoyMCswMjowMNrbif0AAAAASUVORK5CYII=","type":"Ecole avec accents"}]}],"pagination":{"more":false}}',
$repo->toJsonByQuery($query, 1)
);
}
public function getImageTest()
{
// Remote logo disabled
$disableRemoteLogos = true;
$imageString = "https://super-image.com";
$this->assertEquals(
'',
getImage($imageString)
);
$imageString = "data:image/png;base64";
$this->assertEquals(
$imageString,
getImage($imageString)
);
// Remote logo enabled
$disableRemoteLogos = false;
$imageString = "https://super-image.com";
$this->assertEquals(
$imageString,
getImage($imageString)
);
$imageString = "data:image/png;base64";
$this->assertEquals(
$imageString,
getImage($imageString)
);
}
// public function testIdpObject()
// {
// require("test.idps.php");
......
......@@ -12,34 +12,27 @@ function formatList(idp) {
if (idp.loading) {
return idp.text;
}
if (idp.children == null) {
// IDP
var img = "";
if (idp.logo !== null) {
// Logo present
if (idp.logo.toLowerCase().indexOf('data:image') !== 0) {
// TODO : gérer le cas où on ne veut pas fetcher les logos distants
// remote logo
img = "<img src='" + idp.logo + "' />";
} else {
// local logo
img = "<img src='" + idp.logo + "' />";
}
img = "<img src='" + idp.logo + "' />";
} else {
img = "&nbsp;";
}
var markup = "<div class='select2-result-repository clearfix'>" +
"<div class='select2-result-repository__logo'>" + img + "</div>" +
"<div class='select2-result-repository__title'>" + idp.text + "</div></div>";
return markup;
} else {
// Group
var markup = "<div class='select2-result-repository clearfix'>" +
idp.text + "</div>";
return markup;
}
}
......@@ -47,6 +40,6 @@ function formatList(idp) {
/*
* Format for selected element
*/
function formatSelection(idp) {
function formatRepoSelection(idp) {
return idp.text;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment