Commit 4b62cc96 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

hotline #78216 plug sso url

parent d2d31da4
Pipeline #4722 failed with stage
in 45 minutes and 37 seconds
......@@ -23,7 +23,6 @@ class ModulesController extends ZendAfi_Controller_Action {
public function preDispatch() {
$mapping = ['vodeclic' => 'Vodeclic',
'toutapprendre' => 'ToutApprendre',
'lesocial' => 'LeSocial',
'mycow' => 'MyCow',
'planetnemo' => 'PlanetNemo',
......
......@@ -109,11 +109,14 @@ class Class_DigitalResource extends Class_Entity {
public function getSsoActionForPlugin($name) {
return $this->getPlugins()
->detect(function($config) use ($name)
{
return ($name == $config->getName()) ? $config->getSsoAction() : '';
});
$action_name = $this->getPlugins()
->collect(function($config) use ($name)
{
return ($name == $config->getName()) ? $config->getSsoAction() : null;
})
->getArrayCopy();
$action_name = array_filter($action_name);
return reset($action_name);
}
......@@ -325,7 +328,7 @@ class Class_DigitalResource extends Class_Entity {
public function getAdminVar($plugin, $name) {
return Class_AdminVar::get($this->withNamespace($plugin, $name));
return Class_AdminVar::getValueOrDefault($this->withNamespace($plugin, $name));
}
......
......@@ -40,8 +40,13 @@ class ToutApprendre_Config extends Class_DigitalResource_Config {
'DocTypeLabel' => $this->_('Cours en ligne Tout Apprendre'),
'AdminVars' => ['SSO_URL' => Class_AdminVar_Meta::newDefault($this->_('URL SSO de la plateforme ToutApprendre'),
'AdminVars' => ['BIB_ID' => Class_AdminVar_Meta::newDefault($this->_('Identifiant de la bibliothèque fournit par la plateforme ToutApprendre'))->bePrivate(),
'KEY' => Class_AdminVar_Meta::newDefault($this->_('Clé de controle fournie par la plateforme ToutApprendre'))->bePrivate(),
'SSO_URL' => Class_AdminVar_Meta::newDefault($this->_('URL SSO de la plateforme ToutApprendre'),
['value' => 'http://biblio.toutapprendre.com/ws/wsUrl.aspx'])->bePrivate(),
'HARVEST_URL' => Class_AdminVar_Meta::newDefault($this->_('URL du catalogue de la plateforme ToutApprendre'),
['value' => 'http://biblio.toutapprendre.com/cours/catalogue.aspx'])->bePrivate()]
];
......@@ -49,7 +54,10 @@ class ToutApprendre_Config extends Class_DigitalResource_Config {
public function isEnabled() {
return '' != $this->getAdminVar('SSO_URL');
return $this->getAdminVar('SSO_URL')
&& $this->getAdminVar('HARVEST_URL')
&& $this->getAdminVar('BIB_ID')
&& $this->getAdminVar('KEY');
}
......@@ -57,14 +65,41 @@ class ToutApprendre_Config extends Class_DigitalResource_Config {
if(!$user)
return '';
return $this->getAdminVar('SSO_URL');
return $this->_ssoUrlFor($user, null);
}
public function getAlbumSsoUrl($user, $album) {
if(!$album)
if (!$user)
return '';
return $this->getAdminVar('SSO_URL');
if (!$album)
return '';
return $this->_ssoUrlFor($user, $album);
}
protected function _ssoUrlFor($user, $album) {
if (!$user)
return;
$login = strtolower($user->getLogin());
$formatted_date = date('YmdHi', $this->getCurrentTime());
$params = ['iduser' => $login,
'etablissement' => $this->getAdminVar('BIB_ID'),
'd' => $formatted_date,
'hash' => md5(implode([$login,
$formatted_date,
$this->getAdminVar('KEY')]))
];
if ($album)
$params['pkl'] = $album->getIdOrigine();
return $this->getAdminVar('SSO_URL')
. '?'
. http_build_query(array_filter($params));
}
}
\ No newline at end of file
......@@ -27,7 +27,11 @@ abstract class ToutApprendreActivatedTestCase extends AbstractControllerTestCase
public function setUp() {
parent::setUp();
Class_AdminVar::set('ToutApprendre_SSO_URL', 'https://test.org/api/bokeh/login');
ToutApprendre_Config::setTimeSource(new TimeSourceForTest('2018-08-14 12:10:07'));
Class_AdminVar::set('ToutApprendre_BIB_ID', '2220');
Class_AdminVar::set('ToutApprendre_KEY', '1111');
$group = $this->fixture('Class_UserGroup',
['id' => 1,
......@@ -53,19 +57,13 @@ class ToutApprendreSsoTest extends ToutApprendreActivatedTestCase {
public function setUp() {
parent::setUp();
ZendAfi_Auth::getInstance()->logUser($this->_user);
$this->dispatch('/opac/modules/' . Class_DigitalResource::getSsoActionForPlugin('ToutApprendre'), true);
$this->dispatch('/opac/modules/' . Class_DigitalResource::getInstance()->getSsoActionForPlugin('ToutApprendre'), true);
}
/** @test */
public function shouldRedirectToResource() {
$this->assertXPathContentContains('//script' , 'document.location.href="PLACEHOLDER', $this->_response->getBody());
}
/** @test */
public function scriptShouldContainsCheckUrl() {
$this->assertXPathContentContains('//script[contains(text(), "&check_url=")]' , '/ToutApprendre_Plugin/auth/validate');
$this->assertXPathContentContains('//script' , 'document.location.href="http://biblio.toutapprendre.com/ws/wsUrl.aspx?iduser=tom&etablissement=2220&d=201808141210&hash=ed57ad5fe457c2ea7b3ec14eaee50bef";', $this->_response->getBody());
}
}
......
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