Commit 3f7f3ac6 authored by efalcy's avatar efalcy
Browse files

dev #62896 : manage permission on sito box configuration

parent e48e6747
......@@ -850,7 +850,7 @@ class Class_Users extends Storm_Model_Abstract {
* @return array
*/
public function getRights() {
$rights = array();
$rights = [];
$groups = $this->getUserGroups();
foreach ($groups as $group)
$rights = array_merge($rights, $group->getRights());
......@@ -884,6 +884,11 @@ class Class_Users extends Storm_Model_Abstract {
}
public function hasRightConfigSito() {
return $this->isAdmin() || $this->hasRightToAccess(Class_UserGroup::RIGHT_USER_SITOTHEQUE);
}
/**
* @return bool
*/
......
......@@ -33,9 +33,10 @@ class ZendAfi_View_Helper_Accueil_Sito extends ZendAfi_View_Helper_Accueil_Base
protected function addSitoAddButton() {
if (!Class_Users::isCurrentUserCanAccesBackend())
if (!$user = Class_Users::getIdentity())
return '';
if (!$user->hasRightConfigSito())
return '';
return $this->view
->tagAnchor($this->view->url(['module' => 'admin',
......
......@@ -34,9 +34,10 @@ class ZendAfi_View_Helper_TagEditSito extends ZendAfi_View_Helper_BaseHelper {
* @return string
*/
public function tagEditSito($sito) {
if (!Class_Users::isCurrentUserCanConfigFront())
if (!$user = Class_Users::getIdentity())
return '';
if (!$user->hasRightConfigSito())
return '';
return $this->_tag('div', $this->renderEdit($sito),
['class' => 'edit_sito']);
}
......
......@@ -390,6 +390,7 @@ class SitoViewHelperAdminTest extends SitoViewHelperTestCase {
$this->createBoxAndHelper();
}
protected function logModo() {
$joe = $this->fixture('Class_Users',
['id' => 23,
......@@ -406,6 +407,28 @@ class SitoViewHelperAdminTest extends SitoViewHelperTestCase {
}
protected function logModoAllowed() {
$group_sito= $this->fixture('Class_UserGroup',
['id' => 22,
'libelle' => 'Testing group',
'rights' => [Class_UserGroup::RIGHT_USER_SITOTHEQUE]]);
$joe = $this->fixture('Class_Users',
['id' => 23,
'login' => 'Joe',
'password' => 'unsupermotdepasse',
'id_site' => 1,
'settings' => Class_User_Settings::serializeSettings(['show_admin_icons' => '1']),
'role_level' => ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL,
'user_groups' => [$group_sito]]);
ZendAfi_Auth::getInstance()->logUser($joe);
$this->addFixturesSito();
$this->createBoxAndHelper();
}
/** @test */
public function editAdminButtonSitoShouldBeDisplayed() {
$this->logAdmin();
......@@ -433,6 +456,14 @@ class SitoViewHelperAdminTest extends SitoViewHelperTestCase {
}
/** @test */
public function addAdminButtonNewSitoShouldBeDisplayedWithUserWithRights() {
$this->logModoAllowed();
$this->assertXPath($this->html,
'//img[contains(@alt,"Ajouter un nouveau site")]',$this->html);
}
/** @test */
public function editAdminButtonAddSitoShouldBeDisplayed() {
......@@ -442,6 +473,15 @@ class SitoViewHelperAdminTest extends SitoViewHelperTestCase {
}
/** @test */
public function editWithUserGroupSitoButtonAddSitoShouldBeDisplayed() {
$this->logModoAllowed();
$this->assertXPath($this->html,
'//a[contains(@href,"/admin/sito/add/id_cat/9")]//img[@alt="Ajouter un site dans la catégorie: France"]',$this->html);
}
}
......
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