silverstripe-framework/security/PermissionRole.php
Mateusz Uzdowski d6b4ad39d8 BUGFIX: adding onAfterDelete hooks to remove the no longer necessary permissions
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@94859 467b73ca-7a2a-4603-9d3b-597d59a354a9
2011-02-02 14:17:59 +13:00

50 lines
1.1 KiB
PHP

<?php
/**
* A PermissionRole represents a collection of permission codes that can be applied to groups.
*
* Because permission codes are very granular, this lets website administrators create more
* business-oriented units of access control - Roles - and assign those to groups.
*/
class PermissionRole extends DataObject {
static $db = array(
"Title" => "Varchar",
"OnlyAdminCanApply" => "Boolean"
);
static $has_many = array(
"Codes" => "PermissionRoleCode",
);
static $belongs_many_many = array(
"Groups" => "Group",
);
static $default_sort = 'Title';
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeFieldFromTab('Root', 'Codes');
$fields->removeFieldFromTab('Root', 'Groups');
$fields->addFieldToTab('Root.Main', new PermissionCheckboxSetField(
'Codes',
'Permissions',
'PermissionRoleCode',
'RoleID'));
return $fields;
}
function onAfterDelete() {
parent::onAfterDelete();
// Delete associated permission codes
$codes = $this->Codes();
foreach ( $codes as $code ) {
$code->delete();
}
}
}