diff --git a/VERSIONS_WIP/35308 b/VERSIONS_WIP/35308 new file mode 100644 index 0000000000000000000000000000000000000000..e2bfe060658fd094ba36866c34c537dd23d5432b --- /dev/null +++ b/VERSIONS_WIP/35308 @@ -0,0 +1 @@ + - ticket #35308 : Connecteur lesocial.fr : creation d'un lien dans les menus \ No newline at end of file diff --git a/application/modules/opac/controllers/ModulesController.php b/application/modules/opac/controllers/ModulesController.php index 72678e1fe2afdb07f98b84d699f75259122c5b7f..4652534dd02b629364c72ecbd320a2421d75e330 100644 --- a/application/modules/opac/controllers/ModulesController.php +++ b/application/modules/opac/controllers/ModulesController.php @@ -79,6 +79,12 @@ class ModulesController extends Zend_Controller_Action { $this->checkNotifyMessage($lekiosk, $lekiosk->getDynamiqueUrl()); } + public function lesocialAction() { + $lesocial = new Class_Systeme_ModulesMenu_LeSocial(); + $lesocial->afterLoginRedirectTo($this->_request->getServer('HTTP_REFERER')); + $this->checkNotifyMessage($lesocial, $lesocial->getDynamiqueUrl()); + } + public function mycowAction() { $mycow = new Class_Systeme_ModulesMenu_MyCow(); diff --git a/library/Class/AdminVar.php b/library/Class/AdminVar.php index 85ffea53603479f3d53e24bfd03db5f8957f19a2..03d4db0b71c9e2c7db7d6ef6c2e2c5466c755d0d 100644 --- a/library/Class/AdminVar.php +++ b/library/Class/AdminVar.php @@ -291,7 +291,10 @@ class Class_AdminVarLoader extends Storm_Model_Loader { 'users' => ['NDAYS_EXPIRY_NOTICE' => Class_AdminVar_Meta::newDefault($this->_('Prévenir l\'utilisateur xx jour(s) avant l\'expiration de son abonnement (par défaut 30 jours).'), ['value' => 30]), 'DISABLE_SUGGESTIONS' => Class_AdminVar_Meta::newOnOff($this->_('Désactivation des suggestions d\'achats'))->bePrivate()], 'redmine' => ['REDMINE_SERVER_URL' => Class_Adminvar_Meta::newDefault($this->_('Url du serveur redmine'))->bePrivate(), - 'REDMINE_PROJECT_ID' => Class_Adminvar_Meta::newDefault($this->_('Identifiant du project Redmine'))->bePrivate()]]; + 'REDMINE_PROJECT_ID' => Class_Adminvar_Meta::newDefault($this->_('Identifiant du project Redmine'))->bePrivate()], + 'lesocial' => ['LESOCIAL_URL' => Class_Adminvar_Meta::newDefault($this->_('Url du connecteur Le Social'))->bePrivate(), + 'LESOCIAL_ID' => Class_Adminvar_Meta::newDefault($this->_('Id du connecteur Le Social'))->bePrivate()] + ]; } @@ -543,6 +546,11 @@ class Class_AdminVarLoader extends Storm_Model_Loader { } + public function isLeSocialEnabled() { + return ('' != Class_AdminVar::get('LESOCIAL_ID')); + } + + public function isKidilanguesEnabled() { return ('' != Class_AdminVar::get('KIDILANGUES_ID')) && ('' != Class_AdminVar::get('KIDILANGUES_KEY')) diff --git a/library/Class/LeSocialLink.php b/library/Class/LeSocialLink.php new file mode 100644 index 0000000000000000000000000000000000000000..7339a555b8b22f3b2e1391e5e6b244a5cbf98ee6 --- /dev/null +++ b/library/Class/LeSocialLink.php @@ -0,0 +1,74 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_LeSocialLink { + const BASE_URL = "http://www.lesocial.fr/carel/acces.php"; + + + public static function forUser($user) { + return (new self())->setUser($user); + } + + public static function staticUrl() { + return Class_Url::assemble(['controller' => 'modules', + 'action' => 'lesocial']); + } + + + public function setUser($user) { + $this->_user=$user; + return $this; + } + + + public function baseUrl() { + return ($url=Class_AdminVar::get('LESOCIAL_URL'))? + $url : self::BASE_URL; + } + + + public function getId() { + return Class_AdminVar::get('LESOCIAL_ID'); + + } + + + public function getIdUser() { + return ($this->_user->getIdSigb() ? + $this->_user->getIdSigb() : + $this->_user->getIdabon()); + } + + + public function url() { + $params=[ + 'id' => $this->getId(), + 'user'=> $this->getIdUser() + ]; + + return $this->baseUrl().'?'.http_build_query(array_filter($params)); + + +} + +} +?> \ No newline at end of file diff --git a/library/Class/Systeme/ModulesMenu.php b/library/Class/Systeme/ModulesMenu.php index f5f83eeb25d653c7a1c688812c220cedb530abf0..8bc09c9758217d04259314b7c205b76dd694f4b1 100644 --- a/library/Class/Systeme/ModulesMenu.php +++ b/library/Class/Systeme/ModulesMenu.php @@ -125,6 +125,7 @@ class Class_Systeme_ModulesMenu extends Class_Systeme_ModulesAbstract { "MYCOW" => new Class_Systeme_ModulesMenu_MyCow(), "PLANETNEMO" => new Class_Systeme_ModulesMenu_PlanetNemo(), "KIDLILANGUES" => new Class_Systeme_ModulesMenu_Kidilangues(), + "LESOCIAL" => new Class_Systeme_ModulesMenu_LeSocial(), "RESERVER_POSTE" => new Class_Systeme_ModulesMenu_ReserverPoste(), 'SUGGESTION_ACHAT' => new Class_Systeme_ModulesMenu_SuggestionAchat(), 'WEBKIOSK_RESERVATION' => new Class_Systeme_ModulesMenu_WebkioskReservation() diff --git a/library/Class/Systeme/ModulesMenu/LeSocial.php b/library/Class/Systeme/ModulesMenu/LeSocial.php new file mode 100644 index 0000000000000000000000000000000000000000..7c3838ecf54fa019c1c51038f7cc835aed6ea60a --- /dev/null +++ b/library/Class/Systeme/ModulesMenu/LeSocial.php @@ -0,0 +1,54 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Systeme_ModulesMenu_LeSocial extends Class_Systeme_ModulesMenu_SSOAbstract { + protected $_group = Class_Systeme_ModulesMenu::GROUP_MENU_ABONNES; + protected $_type_module = 'LESOCIAL'; + protected $_libelle = 'Lien vers Le Social'; + protected $_url = [ + 'controller' => 'modules', + 'action' => 'lesocial' + ]; + + public function urlForUser($user) { + if ($user && $user->hasRightAccessLeSocial() && Class_AdminVar::isLeSocialEnabled()) + return ( Class_LeSocialLink::forUser($user)->url()); + $this->setMessage('Vous n\'avez pas accès à cette ressource.'); + return ''; + } + + + public function getUrl($preferences=[]) { + return Class_LeSocialLink::staticUrl(); + } + + public function shouldOpenInNewWindow($preferences) { + return null != Class_Users::getIdentity(); + } + + + public function isVisibleForProfil($profil) { + return Class_AdminVar::isLeSocialEnabled(); + } + +} +?> \ No newline at end of file diff --git a/library/Class/UserGroup.php b/library/Class/UserGroup.php index b2ce69a7e477a4dab8d5ff9ec799edf87e0a2572..ee0c21dc52b75abcb2081ff0daaa8267b0a52780 100644 --- a/library/Class/UserGroup.php +++ b/library/Class/UserGroup.php @@ -58,7 +58,7 @@ class Class_UserGroup extends Storm_Model_Abstract { const RIGHT_ACCES_PNB_DILICOM = 26; const RIGHT_ACCES_PLANETNEMO = 27; const RIGHT_ACCESS_ORTHODIDACTE = 28; - + const RIGHT_ACCESS_LESOCIAL = 29; // droits moderateurs const RIGHT_USER_DOMAINES_SUPPRESSION_LIMIT = 8; const RIGHT_USER_FILE_ACCESS = 9; @@ -98,6 +98,7 @@ class Class_UserGroup extends Storm_Model_Abstract { self::RIGHT_ACCES_PLANETNEMO => 'Bibliothèque numérique: accéder à planetnemo.fr', self::RIGHT_ACCES_KIDILANGUES => 'Bibliothèque numérique: accéder à Kidilangues', self::RIGHT_ACCESS_ORTHODIDACTE => 'Bibliothèque numérique: accéder à Orthodidacte.com', + self::RIGHT_ACCESS_LESOCIAL => 'Bibliothèque numérique: accéder à Le Social', self::RIGHT_ACCES_PNB_DILICOM => 'Bibliothèque numérique: autoriser le prêt numérique Dilicom', self::RIGHT_USER_DOMAINES_SUPPRESSION_LIMIT => 'Domaines: accès, modification et suppression limitée au créateur', self::RIGHT_USER_DOMAINES_TOTAL_ACCESS => 'Domaines: accès total en modification et suppression', @@ -148,6 +149,7 @@ class Class_UserGroup extends Storm_Model_Abstract { 'NumeriquePremium' => [Class_UserGroup::RIGHT_ACCES_NUMERIQUEPREMIUM], 'MyCow' => [Class_UserGroup::RIGHT_ACCES_MYCOW], 'Kidilangues' => [Class_UserGroup::RIGHT_ACCES_KIDILANGUES], + 'LeSocial' => [Class_UserGroup::RIGHT_ACCESS_LESOCIAL] ]; foreach($mapping as $type => $tokens) { diff --git a/library/Class/Users.php b/library/Class/Users.php index 9e80dece97bd53964880da30178d6e70deb50a3b..28e78fd5d3c6a3e9e93f865f0361684f6277a93d 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -834,6 +834,9 @@ class Class_Users extends Storm_Model_Abstract { return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCESS_ORTHODIDACTE); } + public function hasRightAccessLeSocial() { + return $this->isAbonneAndHasRightToAccess(Class_UserGroup::RIGHT_ACCESS_LESOCIAL); + } public function getFirstAvisByIdNotice($id_notice) { $notice = Class_Notice::getLoader()->find($id_notice); diff --git a/tests/application/modules/opac/controllers/ModulesControllerTest.php b/tests/application/modules/opac/controllers/ModulesControllerTest.php index 524d0e841cfcac74542102f39295375d4f81efc6..f99de2061357202a184c2c5a07c452a5b3794be9 100644 --- a/tests/application/modules/opac/controllers/ModulesControllerTest.php +++ b/tests/application/modules/opac/controllers/ModulesControllerTest.php @@ -87,7 +87,33 @@ class ModulesControllerLeKioskUserWithoutGroupTest extends AbstractControllerTes } } +class ModulesControllerLeSocialWithoutGroupTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + RessourcesNumeriquesFixtures::activateLeSocial(); + $this->dispatch('/opac/modules/lesocial',true); + } + /** @test */ + public function accesShouldBeForbidden() { + $this->assertFlashMessengerContentContains('Vous n\'avez pas accès à cette ressource'); + } +} +class ModulesControllerLeSocialWithGroupTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + RessourcesNumeriquesFixtures::activateLeSocial(); + $group = $this->fixture('Class_UserGroup', ['id' => 1]) + ->addRight(Class_UserGroup::RIGHT_ACCESS_LESOCIAL); + + Class_Users::getIdentity()->setUserGroups([$group]); + $this->dispatch('/opac/modules/lesocial',true); + } + /** @test */ + public function accesShouldBeForbidden() { + $this->assertContains('http://www.lesocial.fr',$this->_response->getBody()); + } +} class ModulesControllerLeKioskUserWithGroupWithoutRightTest extends AbstractControllerTestCase { public function setUp() { diff --git a/tests/fixtures/RessourcesNumeriquesFixtures.php b/tests/fixtures/RessourcesNumeriquesFixtures.php index 015d0cc592e61d896f078c27e54b345fe98fdba0..567eaf60f90512f043f685c0fbfba56b3853c66a 100644 --- a/tests/fixtures/RessourcesNumeriquesFixtures.php +++ b/tests/fixtures/RessourcesNumeriquesFixtures.php @@ -38,6 +38,7 @@ class RessourcesNumeriquesFixtures { self::deactivateJamendo(); self::deactivateDilicom(); self::deactivateOrthodidacte(); + self::deactivateLeSocial(); } @@ -60,6 +61,7 @@ class RessourcesNumeriquesFixtures { self::activateJamendo(); self::activateDilicom(); self::activateOrthodidacte(); + self::activateLeSocial(); } @@ -287,5 +289,17 @@ class RessourcesNumeriquesFixtures { public static function deactivateOrthodidacte() { Class_AdminVar::newInstanceWithId('ORTHODIDACTE', ['valeur' => '']); } + + + public static function activateLeSocial() { + Class_AdminVar::newInstanceWithId('LESOCIAL_ID', ['valeur' => '50']); + Class_AdminVar::newInstanceWithId('LESOCIAL_URL', ['valeur' => 'http://www.lesocial.fr']); + } + + public static function deactivateLeSocial() { + Class_AdminVar::newInstanceWithId('LESOCIAL_ID', ['valeur' => '']); + } + + } ?> diff --git a/tests/library/Class/LeSocialLinkTest.php b/tests/library/Class/LeSocialLinkTest.php new file mode 100644 index 0000000000000000000000000000000000000000..033525a51be00627cebcd043dc22182f53e68a21 --- /dev/null +++ b/tests/library/Class/LeSocialLinkTest.php @@ -0,0 +1,73 @@ +<?php +/** + * Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class LeSocialLinkTest extends Storm_Test_ModelTestCase { + protected $link; + protected $_storm_default_to_volatile = true; + protected $user; + + + public function setUp() { + parent::setUp(); + RessourcesNumeriquesFixtures::activateLeSocial(); + $this->mybib = $this->fixture('Class_Bib', ['id' => 100, + 'libelle' => 'Rubber rose ranch', + 'id_zone' => 1]); + + $this->user = $this->fixture('Class_Users', ['id' => 10, + 'prenom' => 'Sissy', + 'nom' => 'Hankshaw', + 'login' => 'sissy', + 'pseudo' => 'sissy', + 'password' => 'mysecret', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB, + 'idabon' => '00123', + 'bib' => $this->mybib, + 'ordreabon' => 1, + 'date_debut' => '19-07-2009', + 'date_fin' => '19-07-2010', + ]); + + + } + + /** @test */ + public function linkShouldBeDisplayedWithIdAbon() { + $this->link = Class_LeSocialLink::forUser($this->user); + $this->assertEquals('http://www.lesocial.fr?id=50&user=00123', $this->link->url()); + } + + + + /** @test */ + public function linkShouldBeDisplayedWithIdSIGB() { + $this->user->setIdSigb('A84'); + $this->link = Class_LeSocialLink::forUser($this->user); + $this->assertEquals('http://www.lesocial.fr?id=50&user=A84', $this->link->url()); + } + + public function tearDown() { + RessourcesNumeriquesFixtures::deactivateLeSocial(); + parent::tearDown(); + } +} +?> \ No newline at end of file diff --git a/tests/library/Class/Systeme/ModulesMenuTest.php b/tests/library/Class/Systeme/ModulesMenuTest.php index 8e0976d40d42296c92dde1a57d75a349fc6aff4c..a410fe1a13277c9e8df46c9ddeeda23f6bf90261 100644 --- a/tests/library/Class/Systeme/ModulesMenuTest.php +++ b/tests/library/Class/Systeme/ModulesMenuTest.php @@ -34,6 +34,7 @@ abstract class ModulesMenuBibNumeriqueTestCase extends Storm_Test_ModelTestCase ['MYCOW', 'MyCOW.EU'], ['PLANETNEMO', 'planetnemo.fr'], ['KIDILANGUES', 'Kidilangues'], + ['LESOCIAL', 'Le Social'] ]; } }