mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
APICHANGE: add the ability to remove some permissions specified by their code in the rendered field html of PermissionChecksetBoxField and full-covered unit tests of this ability.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@92428 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
e9e63a3bbd
commit
65b1bc4839
@ -82,7 +82,13 @@ class Permission extends DataObject {
|
||||
* @var bool
|
||||
*/
|
||||
static $admin_implies_all = true;
|
||||
|
||||
|
||||
/**
|
||||
* a list of permission codes which doesn't appear in the Permission list
|
||||
* when make the {@link PermissionCheckboxSetField}
|
||||
* @var array;
|
||||
*/
|
||||
static $hidden_permissions = array();
|
||||
|
||||
/**
|
||||
* Check that the current member has the given permission.
|
||||
@ -559,6 +565,26 @@ class Permission extends DataObject {
|
||||
return $a['sort'] < $b['sort'] ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* add a permission represented by the $code to the {@link slef::$hidden_permissions} list
|
||||
*
|
||||
* @param $code string - the permissions code
|
||||
* @return void
|
||||
*/
|
||||
static function add_to_hidden_permissions($code){
|
||||
self::$hidden_permissions[] = $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* remove a permission represented by the $code from the {@link slef::$hidden_permissions} list
|
||||
*
|
||||
* @param $code string - the permissions code
|
||||
* @return void
|
||||
*/
|
||||
static function remove_from_hidden_permissions($code){
|
||||
self::$hidden_permissions = array_diff(self::$hidden_permissions, array($code));
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare an array of permissions for the system.
|
||||
|
@ -69,7 +69,9 @@ class PermissionCheckboxSetField extends CheckboxSetField {
|
||||
if($source) {
|
||||
foreach($source as $categoryName => $permissions) {
|
||||
$options .= "<li><h5>$categoryName</h5></li>";
|
||||
$hiddens = Permission::$hidden_permissions;
|
||||
foreach($permissions as $code => $permission) {
|
||||
if(in_array($code, $hiddens)) continue;
|
||||
$key = $code;
|
||||
$value = $permission['name'];
|
||||
|
||||
|
@ -41,4 +41,17 @@ class PermissionTest extends SapphireTest {
|
||||
$this->assertFalse(Permission::checkMember($member, "CMS_ACCESS_SecurityAdmin"));
|
||||
}
|
||||
|
||||
function testHiddenPermissions(){
|
||||
$permissionCheckboxSet = new PermissionCheckboxSetField('Permissions','Permissions','Permission','GroupID');
|
||||
$this->assertContains('CMS_ACCESS_CMSMain', $permissionCheckboxSet->Field());
|
||||
$this->assertContains('CMS_ACCESS_AssetAdmin', $permissionCheckboxSet->Field());
|
||||
|
||||
Permission::add_to_hidden_permissions('CMS_ACCESS_CMSMain');
|
||||
Permission::add_to_hidden_permissions('CMS_ACCESS_AssetAdmin');
|
||||
$this->assertNotContains('CMS_ACCESS_CMSMain', $permissionCheckboxSet->Field());
|
||||
$this->assertNotContains('CMS_ACCESS_AssetAdmin', $permissionCheckboxSet->Field());
|
||||
|
||||
Permission::remove_from_hidden_permissions('CMS_ACCESS_AssetAdmin');
|
||||
$this->assertContains('CMS_ACCESS_AssetAdmin', $permissionCheckboxSet->Field());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user