From 73681b0afa62bba0a938e41416b5019b4f4cbee8 Mon Sep 17 00:00:00 2001 From: Normann Lou Date: Fri, 20 Nov 2009 03:49:57 +0000 Subject: [PATCH] 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/cms/branches/2.4@92428 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- code/SecurityAdmin.php | 12 ++++++++++++ tests/SecurityAdminTest.php | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/code/SecurityAdmin.php b/code/SecurityAdmin.php index bdce356f..f54fc3fc 100644 --- a/code/SecurityAdmin.php +++ b/code/SecurityAdmin.php @@ -276,6 +276,18 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider { ) ); } + + /** + * the permissions represented in the $codes will not appearing in the form + * containning {@link PermissionCheckboxSetField} so as not to be checked / unchecked. + * @param $codes array of permission code + * @return void + */ + static function hide_permissions($codes){ + foreach($codes as $code){ + Permission::add_to_hidden_permissions($code); + } + } } ?> diff --git a/tests/SecurityAdminTest.php b/tests/SecurityAdminTest.php index 4522c7eb..035c9a5e 100644 --- a/tests/SecurityAdminTest.php +++ b/tests/SecurityAdminTest.php @@ -36,6 +36,16 @@ class SecurityAdminTest extends FunctionalTest { $this->assertEquals($lines[1], '', "Empty export only has no content row"); } + function testHidePermissions() { + $permissionCheckboxSet = new PermissionCheckboxSetField('Permissions','Permissions','Permission','GroupID'); + $this->assertContains('CMS_ACCESS_CMSMain', $permissionCheckboxSet->Field()); + $this->assertContains('CMS_ACCESS_AssetAdmin', $permissionCheckboxSet->Field()); + + SecurityAdmin::hide_permissions(array('CMS_ACCESS_CMSMain','CMS_ACCESS_AssetAdmin')); + $this->assertNotContains('CMS_ACCESS_CMSMain', $permissionCheckboxSet->Field()); + $this->assertNotContains('CMS_ACCESS_AssetAdmin', $permissionCheckboxSet->Field()); + } + } ?> \ No newline at end of file