Skip to content
Snippets Groups Projects
Commit 743eafe3 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

Merge branch 'hotline#74731_connecteur_skilleos' into 'hotline'

Hotline#74731 connecteur skilleos

See merge request !2639
parents ca7c3514 6476088f
Branches
Tags
4 merge requests!2660Master,!2642Master,!2641Hotline,!2639Hotline#74731 connecteur skilleos
Pipeline #4064 failed with stage
in 34 minutes and 42 seconds
- ticket #74731 : Connecteur Skilleos
\ No newline at end of file
......@@ -244,4 +244,42 @@ class Class_DigitalResource_Config extends Class_Entity {
$service = $this->getService();
return new $service($this);
}
public function renderHarvestDiagOn($view) {
return $view->tag('p',
$this->_('Cette ressource ne prend pas en charge l\'affichage du l\'url de moissonnage'), ['class' => 'error']);
}
public function getTestUser() {
$login = $this->getName() . '_test_user';
$user = ($user = Class_Users::findFirstBy(['login' => $login]))
? $user
: Class_Users::newInstance(['login' => $login,
'password' => $login]);
$user->save();
$group = $this->getTestGroup();
$group->addUser($user)->save();
return $user;
}
public function getTestGroup() {
$group_name = $this->getName() . '_test_group';
$group = ($group = Class_UserGroup::findFirstBy(['libelle' => $group_name]))
? $group
: Class_UserGroup::newInstance(['libelle' => $group_name]);
$group->save();
if(!$permission = Class_Permission::findFirstBy(['code' => $this->getName()]))
return $group;
$permission->permitTo($group, new Class_Entity());
return $group;
}
}
\ No newline at end of file
......@@ -62,6 +62,17 @@ class Class_DigitalResource_Controller extends ZendAfi_Controller_Action {
}
public function trySsoAction() {
if (!Class_Users::getIdentity()->isSuperAdmin()) {
$this->_helper->notify($this->_('Vous n\'avez pas les droits suffisants pour utiliser cette fonctionnalité.'));
return $this->_redirectToReferer();
}
ZendAfi_Auth::getInstance()->logUser($this->_config->getTestUser());
$this->_forward('sso');
}
protected function _afterLoginRedirectTo($url, $message = null) {
if($message)
$this->_helper->notify($message);
......
......@@ -192,24 +192,8 @@ class ZendAfi_View_Helper_DigitalResource_Dashboard extends ZendAfi_View_Helper_
return implode($html);
}
$login = $this->_config->getName() . '_test_user';
$user = ($user = Class_Users::findFirstBy(['login' => $login]))
? $user
: Class_Users::newInstance(['login' => $login,
'password' => $login]);
$user->save();
if(!$permission = Class_Permission::findFirstBy(['code' => $this->_config->getName()]))
return implode($html);
$group_name = $this->_config->getName() . '_test_group';
$group = ($group = Class_UserGroup::findFirstBy(['libelle' => $group_name]))
? $group
: Class_UserGroup::newInstance(['libelle' => $group_name]);
$group->addUser($user)->save();
$permission->permitTo($group, new Class_Entity());
$user = $this->_config->getTestUser();
$group = $this->_config->getTestGroup();
$html [] = $this->_tag('h5', $this->_('Groupe créé pour ce test'))
. $this->_tag('ul',
......@@ -238,7 +222,11 @@ class ZendAfi_View_Helper_DigitalResource_Dashboard extends ZendAfi_View_Helper_
$html [] = $this->_tag('h4', $this->_('URL SSO générée par /modules/%s pour l\'utilisateur "%s"',
$this->_config->getSsoAction(),
$user->getLogin()))
. $this->view->tagAnchor($url, $url, ['target' => '_blank']);
. $this->_tag('pre', $url)
. $this->view->button((new Class_Entity)
->setUrl($this->view->url(['action' => 'try-sso']))
->setText($this->_('Essayer le SSO avec l\'utilisateur "%s"',
$user->getLogin())));
if(!$this->_config->getSsoValidateUrl()) {
$html [] = $this->_tag('p', $this->_('Cette ressource ne prend pas en charge la validation du ticket de connexion SSO'), ['class' => 'error']) ;
......@@ -248,7 +236,7 @@ class ZendAfi_View_Helper_DigitalResource_Dashboard extends ZendAfi_View_Helper_
$url = $this->_config->validateUrlFor($user);
$html [] = $this->_tag('h4', $this->_('URL de validation du ticket de connexion générée pour l\'utilisateur "%s"',
$user->getLogin()))
. $this->view->tagAnchor($url, $url, ['target' => '_blank']);
. $this->_tag('pre', $url);
}
......@@ -337,10 +325,8 @@ class ZendAfi_View_Helper_DigitalResource_Dashboard extends ZendAfi_View_Helper_
$html [] = ($url = $this->_config->getHarvestUrl())
? ($this->_tag('h4',
$this->_('URL de moissonnage générée pour la première page'))
. $this->view->tagAnchor($url,
$url,
['target' => '_blank']))
: $this->_tag('p', $this->_('Cette ressource ne prend pas en charge l\'affichage du l\'url de moissonnage'), ['class' => 'error']);
. $this->_tag('pre', $url))
: $this->_config->renderHarvestDiagOn($this->view);
$html [] = $this->_tag('h4',
$this->_('Image du type de document: ')
......@@ -370,9 +356,8 @@ class ZendAfi_View_Helper_DigitalResource_Dashboard extends ZendAfi_View_Helper_
$html [] = $count
? ($this->_tag('h4',
$this->_('Tentative de vignettage de l\'album "%s" : ', $first_album->getTitre()))
. $this->view->tagAnchor($first_album->getPoster(),
$this->_('Image source : %s', $first_album->getPoster()),
['target' => '_blank'])
. $this->_tag('pre',
$this->_('Image source : %s', $first_album->getPoster()))
. $this->_renderThumbnailerLog($first_album))
: $this->_tag('p', $this->_('Le vignettage n\'est pas testable sans album'), ['class' => 'error']);
......
......@@ -76,4 +76,25 @@ class Skilleos_Config extends Class_DigitalResource_Config {
public function isEnabled() {
return '' != $this->getAdminVar('BIB_ID');
}
public function renderHarvestDiagOn($view) {
$service = $this->getServiceInstance();
$token_url = $service->getTokenUrl();
$catalogue_url = Skilleos_Service::$REST_URL;
$html = [$view->tag('p', $this->_('Ce moissonnage se compose de deux étapes:')),
$view->tag('h4', $this->_('Première étape: La récupération du token OAUTH à l\'adresse:')),
$view->tag('pre', $token_url),
$view->tag('p', $this->_('Réponse reçue à la demande de token :')),
$view->tag('pre', $service->httpGet($token_url)),
$view->tag('h4', $this->_('Deuxième étape: La récupération du catalogue à l\'adresse:')),
$view->tag('pre', $catalogue_url),
$view->tag('p', $this->_('Réponse reçue à la demande du catalogue:')),
$view->tag('pre', $service->httpGetCatalogue()),
];
return implode($html);
}
}
......@@ -37,11 +37,7 @@ class Skilleos_Service extends Class_DigitalResource_Service {
protected function getToken() {
$query = ['grant_type' => 'client_credentials',
'client_id' => $this->_config->getAdminVar('CLIENT_ID'),
'client_secret' => $this->_config->getAdminVar('CLIENT_SECRET')];
$url = static::$TOKEN_URL . '?' . http_build_query($query);
$url = $this->getTokenUrl();
if(!$response = $this->httpGet($url))
return;
......@@ -52,9 +48,17 @@ class Skilleos_Service extends Class_DigitalResource_Service {
}
public function getTokenUrl() {
$query = ['grant_type' => 'client_credentials',
'client_id' => $this->_config->getAdminVar('CLIENT_ID'),
'client_secret' => $this->_config->getAdminVar('CLIENT_SECRET')];
return static::$TOKEN_URL . '?' . http_build_query($query);
}
protected function loadPage($page_number = 1) {
$response = $this->httpGet(static::$REST_URL,
['headers' => [ 'Authorization' => 'Bearer ' . $this->getToken()]]);
$response = $this->httpGetCatalogue();
if(!$json = json_decode($response))
return $this;
......@@ -68,6 +72,12 @@ class Skilleos_Service extends Class_DigitalResource_Service {
}
public function httpGetCatalogue() {
return $this->httpGet(static::$REST_URL,
['headers' => [ 'Authorization' => 'Bearer ' . $this->getToken()]]);
}
public function getPageCount() {
return 1;
}
......
......@@ -366,3 +366,49 @@ class SkilleosBatchIndexTest extends Admin_AbstractControllerTestCase {
'Moissonner catalogue Skilleos');
}
}
class SkilleosDashboardTest extends SkilleosServiceTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/Skilleos_Plugin', true);
}
/** @test */
public function getTokenUrlShouldBePresent() {
$this->assertXPathContentContains('//pre', 'http://moncompte.skilleos.com/oauth/v2/token?grant_type=client_credentials');
}
/** @test */
public function getCatalogueUrlShouldBePresent() {
$this->assertXPathContentContains('//pre', 'http://moncompte.skilleos.com/rest/api/trainings');
}
}
class SkilleosDashboardTrySsoTest extends SkilleosServiceTestCase {
public function setUp() {
parent::setUp();
$user = $this->fixture('Class_Users',
['id' => 5,
'login' => 'super_admin',
'password' => 'super',
'role_level' => ZendAfi_Acl_AdminControllerRoles::SUPER_ADMIN]);
ZendAfi_Auth::getInstance()->logUser($user);
$this->dispatch('/Skilleos_Plugin/index/try-sso', true);
}
/** @test */
public function shouldJavascriptRedirectToMoncompteDotSkilleos() {
$this->assertXPathContentContains('//script', 'document.location.href="http://skilleos.com/sigb/sso/?casid=QUEST&ticket');
}
}
\ No newline at end of file
......@@ -142,19 +142,19 @@ class StoryPlayRDashboardActivatedTest extends StoryPlayRActivatedTestCase {
/** @test */
public function testSsoValidateUrlShoudlBeDisplay() {
$this->assertXPathContentContains('//a', '/StoryPlayR_Plugin/auth/validate?sessionid=ST-');
$this->assertXPathContentContains('//pre', '/StoryPlayR_Plugin/auth/validate?sessionid=ST-');
}
/** @test */
public function harvestUrlShouldContainsOpdsCatalogUrlAndProviderAndMediathequeid() {
$this->assertXPath('//a[@href="https://preprod.storyplayr.com/api/opds-with-links?portalProvider=bokeh&mediathequeid=123456"]');
$this->assertXPathContentContains('//pre', 'https://preprod.storyplayr.com/api/opds-with-links?portalProvider=bokeh');
}
/** @test */
public function sourceImageShouldBeValid() {
$this->assertXPathContentContains('//a','Image source : https://preprod');
$this->assertXPathContentContains('//pre','Image source : https://preprod');
}
......
......@@ -1649,3 +1649,10 @@ table#logs img {
#learn_more:hover {
background-color:var(--bokeh-event-highlight);
}
.modules pre {
margin: 1ex 1em;
padding: 1ex 1em;
overflow: auto;
max-height: 300px;
}
\ No newline at end of file
......@@ -1019,6 +1019,7 @@ table#logs img {
margin: 1ex 1em;
padding: 1ex 1em;
overflow: auto;
max-height: 300px;
}
#learn_more > * {
......
......@@ -884,4 +884,11 @@ body .error * {
#learn_more:hover {
background-color:var(--bokeh-event-highlight);
}
.modules pre {
margin: 1ex 1em;
padding: 1ex 1em;
overflow: auto;
max-height: 300px;
}
\ No newline at end of file
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