Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

API CHANGE Refactored hiding of Permissions added in r92428. Added Pe…

…rmissionCheckboxSetField->setHiddenPermissions()

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@92865 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
commit d92bbbecfbdf3eea57a76f4d3a448848fa53ecf2 1 parent ea8fa50
@chillu chillu authored
View
24 security/PermissionCheckboxSetField.php
@@ -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 @@ function Field() {
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'];
View
24 tests/security/PermissionCheckboxSetFieldTest.php
@@ -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());
+ }
+}
View
14 tests/security/PermissionTest.php
@@ -40,18 +40,4 @@ function testRolesAndPermissionsFromParentGroupsAreInherited() {
// 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());
- }
}
Please sign in to comment.
Something went wrong with that request. Please try again.