diff --git a/application/modules/admin/controllers/AccueilController.php b/application/modules/admin/controllers/AccueilController.php index 3a1cae3b98e9ca44d5a85dd42a28f44e7964bfce..09e3a9c5551627be0d30c149c3bcd07f88141428 100644 --- a/application/modules/admin/controllers/AccueilController.php +++ b/application/modules/admin/controllers/AccueilController.php @@ -56,7 +56,7 @@ class Admin_AccueilController extends Zend_Controller_Action { $user = Class_Users::getIdentity(); - if (($user->getRoleLevel() < ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB) + if ((!$user->isAdminBib() && !$user->hasRightConfigFront()) || ($user->isAdminBib() && ($user->getIdSite() !== $this->profil->getIdSite()))) { $this->_redirect('admin/index'); return; diff --git a/library/Class/UserGroup.php b/library/Class/UserGroup.php index c7a6556ff5d024491a5da30a43b3e69b08de14cd..545109f6bbd4b101992903d2279ca87fb26200ba 100644 --- a/library/Class/UserGroup.php +++ b/library/Class/UserGroup.php @@ -49,7 +49,9 @@ class Class_UserGroup extends Storm_Model_Abstract { const RIGHT_USER_BIB_NUM = 8192; const RIGHT_USER_OPDS_READ = 16384; const RIGHT_USER_NOTICES_LIEES = 32768; - const RIGHT_USER_SIGB_USER_READ =65536; + const RIGHT_USER_SIGB_USER_READ = 65536; + const RIGHT_USER_CONFIG_FRONT = 131072; + // Type de groupe const TYPE_MANUAL = 0; const TYPE_DYNAMIC = 1; @@ -64,7 +66,7 @@ class Class_UserGroup extends Storm_Model_Abstract { self::RIGHT_ACCES_VODECLIC => 'Accéder à Vodéclic', self::RIGHT_ACCES_TOUTAPPRENDRE => 'Accéder à Tout Apprendre', self::RIGHT_ACCES_MUSICME => 'Accéder à Music Me', - self::RIGHT_USER_DOMAINES_SUPPRESSION_LIMIT => 'Domaines : accès , suppression limité au créateur', + self::RIGHT_USER_DOMAINES_SUPPRESSION_LIMIT => 'Domaines : accès , suppression limitée au créateur', self::RIGHT_USER_FILE_ACCESS => 'Articles : Accès sur les répertoires images et file', self::RIGHT_USER_SITOTHEQUE => 'Accès sitothèque', self::RIGHT_USER_MODO => 'Accès modération', @@ -72,7 +74,8 @@ class Class_UserGroup extends Storm_Model_Abstract { self::RIGHT_USER_BIB_NUM => 'Accès bibliothèque numèrique', self::RIGHT_USER_OPDS_READ=> 'Accès OPDS en lecture', self::RIGHT_USER_NOTICES_LIEES => 'Accès Notices liées', - self::RIGHT_USER_SIGB_USER_READ => 'Accès en lecture aux fiches adhérents SIGB' + self::RIGHT_USER_SIGB_USER_READ => 'Accès en lecture aux fiches adhérents SIGB', + self::RIGHT_USER_CONFIG_FRONT => 'Accès à la configuration des boîtes et modules depuis l\'interface publique' ]; @@ -176,6 +179,12 @@ class Class_UserGroup extends Storm_Model_Abstract { } + /** @return Class_UserGroup */ + public function addRightConfigFront() { + return $this->addRight(self::RIGHT_USER_CONFIG_FRONT); + } + + /** * @param int right * @return Class_UserGroup diff --git a/library/Class/Users.php b/library/Class/Users.php index 1fb4d74ceb990ecab2691431489098c64033d31c..864448bd0e084d246e3d7421a562e811b967bc43 100644 --- a/library/Class/Users.php +++ b/library/Class/Users.php @@ -121,6 +121,13 @@ class UsersLoader extends Storm_Model_Loader { } + public function isCurrentUserCanConfigFront() { + if (!$user = $this->getIdentity()) + return false; + return $user->hasRightConfigFront(); + } + + /** * @param Class_Article * @return bool @@ -387,7 +394,7 @@ class Class_Users extends Storm_Model_Abstract { if (!$article->hasCategorie()) return false; - return $this->getIdSite() == $article->getCategorie()->getIdSite(); + return ($this->getIdSite() == $article->getCategorie()->getIdSite()); } @@ -581,6 +588,14 @@ class Class_Users extends Storm_Model_Abstract { } + /** + * @return bool + */ + public function hasRightConfigFront() { + return $this->isAdmin() || in_array(Class_UserGroup::RIGHT_USER_CONFIG_FRONT, $this->getRights()); + } + + /** * @return bool */ diff --git a/library/ZendAfi/View/Helper/ComboCategories.php b/library/ZendAfi/View/Helper/ComboCategories.php index e94e8fc902114c42e4c42cf3078beee2464eaa0c..bf04d45c833c4a11d8283fc7497c1a57eacc6e14 100644 --- a/library/ZendAfi/View/Helper/ComboCategories.php +++ b/library/ZendAfi/View/Helper/ComboCategories.php @@ -26,7 +26,7 @@ class ZendAfi_View_Helper_ComboCategories extends ZendAfi_View_Helper_BaseHelper else { $bib = $category->getBib(); if (0 == $bib->getId()) - $bib = $this->_bib; + $bib = Class_Bib::getPortail(); $bibs = array($bib); } diff --git a/library/ZendAfi/View/Helper/FonctionsAdmin.php b/library/ZendAfi/View/Helper/FonctionsAdmin.php index 55d8ccc14fc7f0b018a280e4cd42a5dad2dbcfb1..9f025ddb305ad1896ff9e4962d542ef2d60145b0 100644 --- a/library/ZendAfi/View/Helper/FonctionsAdmin.php +++ b/library/ZendAfi/View/Helper/FonctionsAdmin.php @@ -32,7 +32,7 @@ class ZendAfi_View_Helper_FonctionsAdmin extends ZendAfi_View_Helper_BaseHelper // Main routine //------------------------------------------------------------------------------------------------------ public function fonctionsAdmin($id_module=0, $type_module=false) { - if (!Class_Users::isCurrentUserAdmin()) + if (!Class_Users::isCurrentUserCanConfigFront()) return false; $this->id_profil = Class_Profil::getCurrentProfil()->getId(); diff --git a/library/ZendAfi/View/Helper/Notice/Exemplaires.php b/library/ZendAfi/View/Helper/Notice/Exemplaires.php index 31dc38a0511239fd349095f444ce871057eb2b04..cbc98d722ba3c1a15234d5519b5f9f4a28d08512 100644 --- a/library/ZendAfi/View/Helper/Notice/Exemplaires.php +++ b/library/ZendAfi/View/Helper/Notice/Exemplaires.php @@ -180,7 +180,7 @@ class ZendAfi_View_Helper_Notice_Exemplaires extends Zend_View_Helper_HtmlElemen public function _fonctionsAdmin() { - if (!Class_Users::isCurrentUserAdmin()) + if (!Class_Users::isCurrentUserCanConfigFront()) return ''; return $this->view->tagAnchor($this->view->url(['module' => 'admin', diff --git a/tests/application/modules/admin/controllers/AccueilControllerTest.php b/tests/application/modules/admin/controllers/AccueilControllerTest.php index b8530f1069cadf2799f53ede5b996f9dd8eae9b7..1f7d5357abd755c3bdcb88035553718dc03a73d2 100644 --- a/tests/application/modules/admin/controllers/AccueilControllerTest.php +++ b/tests/application/modules/admin/controllers/AccueilControllerTest.php @@ -571,6 +571,10 @@ abstract class AccueilControllerConfigBoiteKiosqueProfilLognesTestCase extends A 'id_module' => 32, 'preferences' => array())) ->setIdSite(3); + } + + + public function dispatchConfigModule() { $this->dispatch('/admin/accueil/kiosque?config=accueil&type_module=KIOSQUE&id_module=32', true); } } @@ -579,6 +583,11 @@ abstract class AccueilControllerConfigBoiteKiosqueProfilLognesTestCase extends A class AccueilControllerConfigBoiteKiosqueProfilLognesAsAdminPortailTest extends AccueilControllerConfigBoiteKiosqueProfilLognesTestCase { + public function setUp() { + parent::setUp(); + $this->dispatchConfigModule(); + } + /** @test **/ public function testConfigPageShouldDisableMultipleSelection() { $this->assertXPath('//script[contains(@src, "treeselect")]', $this->_response->getBody()); @@ -631,10 +640,35 @@ class AccueilControllerConfigBoiteKiosqueAsAdminBibOtherSiteTest extends Accueil $account->ID_SITE = 5; } + public function setUp() { + parent::setUp(); + $this->dispatchConfigModule(); + } + /** @test */ public function responseShouldRedirectToPageAccueil() { - $this->assertRedirect(); + $this->assertRedirectTo('/admin/index'); + } +} + + + + +class AccueilControllerConfigBoiteWithRightConfigFrontTest extends AccueilControllerConfigBoiteKiosqueProfilLognesTestCase { + public function setUp() { + parent::setUp(); + + Class_Users::getIdentity()->beModoBib()->setUserGroups([Class_UserGroup::newInstanceWithId(2) + ->addRightConfigFront()]); + + $this->dispatchConfigModule(); + } + + + /** @test */ + public function responseShouldNotRedirectToPageAccueil() { + $this->assertNotRedirect(); } } diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php index c9212e74786c861514ae9f4fb75a0fd1e6e14707..8dfbea9dd41c1d366b16e22dfdb9db1ff839de28 100644 --- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php +++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php @@ -381,6 +381,17 @@ class NoticeAjaxControllerExemplairesTest extends AbstractControllerTestCase { $this->dispatch('noticeajax/exemplaires?id_notice=123'); $this->assertXPath('//a[@data-popup="true"][@href="/admin/modulesnotice/exemplaires/config/admin/id_profil/2"]', $this->_response->getBody()); } + + + /** @test */ + public function fonctionsAdminShouldBeVisibleIfCurrentUserHasRightConfigurerBoites() { + ZendAfi_Auth::getInstance()->logUser($user = Class_Users::newInstanceWithId(5) + ->beModoBib() + ->setUserGroups([Class_UserGroup::newInstanceWithId(2) + ->addRightConfigFront()])); + $this->dispatch('noticeajax/exemplaires?id_notice=123', true); + $this->assertXPath('//a[@data-popup="true"][@href="/admin/modulesnotice/exemplaires/config/admin/id_profil/2"]', $this->_response->getBody()); + } }