mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API CHANGE Refactored hiding of Permissions added in r92428. Added PermissionCheckboxSetField->setHiddenPermissions()
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@92865 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
ea8fa5054d
commit
d92bbbecfb
@ -1,12 +1,33 @@
|
||||
<?php
|
||||
|
||||
class PermissionCheckboxSetField extends CheckboxSetField {
|
||||
|
||||
/**
|
||||
* @var Array Filter certain permission codes from the output.
|
||||
* Useful to simplify the interface
|
||||
*/
|
||||
protected $hiddenPermissions = array();
|
||||
|
||||
function __construct($name, $title, $managedClass, $filterField, $record = null) {
|
||||
$this->filterField = $filterField;
|
||||
$this->managedClass = $managedClass;
|
||||
$this->record = $record;
|
||||
parent::__construct($name, $title, Permission::get_codes(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Array $codes
|
||||
*/
|
||||
function setHiddenPermissions($codes) {
|
||||
$this->hiddenPermissions = $codes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Array
|
||||
*/
|
||||
function getHiddenPermissions() {
|
||||
return $this->hiddenPermissions;
|
||||
}
|
||||
|
||||
function Field() {
|
||||
Requirements::css(SAPPHIRE_DIR . '/css/CheckboxSetField.css');
|
||||
@ -69,9 +90,8 @@ 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;
|
||||
if(in_array($code, $this->hiddenPermissions)) continue;
|
||||
$key = $code;
|
||||
$value = $permission['name'];
|
||||
|
||||
|
24
tests/security/PermissionCheckboxSetFieldTest.php
Normal file
24
tests/security/PermissionCheckboxSetFieldTest.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* @package sapphire
|
||||
* @subpackage tests
|
||||
*/
|
||||
class PermissionCheckboxSetFieldTest extends SapphireTest {
|
||||
function testHiddenPermissions() {
|
||||
$f = new PermissionCheckboxSetField(
|
||||
'Permissions',
|
||||
'Permissions',
|
||||
'Permission',
|
||||
'GroupID'
|
||||
);
|
||||
$f->setHiddenPermissions(
|
||||
array('CMS_ACCESS_ReportAdmin')
|
||||
);
|
||||
$this->assertEquals(
|
||||
$f->getHiddenPermissions(),
|
||||
array('CMS_ACCESS_ReportAdmin')
|
||||
);
|
||||
$this->assertContains('CMS_ACCESS_CMSMain', $f->Field());
|
||||
$this->assertNotContains('CMS_ACCESS_ReportAdmin', $f->Field());
|
||||
}
|
||||
}
|
@ -40,18 +40,4 @@ class PermissionTest extends SapphireTest {
|
||||
// Check that a random permission that shouldn't be there isn't
|
||||
$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…
Reference in New Issue
Block a user