Version: current

     1 <?php
     2 /**
     3  * A PermissionRole represents a collection of permission codes that can be applied to groups.
     4  *
     5  * Because permission codes are very granular, this lets website administrators create more
     6  * business-oriented units of access control - Roles - and assign those to groups.
     7  *
     8  * @package sapphire
     9  * @subpackage security
    10  */
    11 class PermissionRole extends DataObject {
    12     static $db = array(
    13         "Title" => "Varchar",
    14         "OnlyAdminCanApply" => "Boolean"
    15     );
    16
    17     static $has_many = array(
    18         "Codes" => "PermissionRoleCode",
    19     );
    20
    21     static $belongs_many_many = array(
    22         "Groups" => "Group",
    23     );
    24
    25     static $default_sort = '"Title"';
    26
    27     static $singular_name = 'Role';
    28
    29     static $plural_name = 'Roles';
    30
    31     function getCMSFields() {
    32         $fields = parent::getCMSFields();
    33
    34         $fields->removeFieldFromTab('Root', 'Codes');
    35         $fields->removeFieldFromTab('Root', 'Groups');
    36
    37         $fields->addFieldToTab(
    38             'Root.Main',
    39             $permissionField = new PermissionCheckboxSetField(
    40                 'Codes',
    41                 singleton('Permission')->i18n_plural_name(),
    42                 'PermissionRoleCode',
    43                 'RoleID'
    44             )
    45         );
    46         $permissionField->setHiddenPermissions(SecurityAdmin::$hidden_permissions);
    47
    48         return $fields;
    49     }
    50
    51     function onAfterDelete() {
    52         parent::onAfterDelete();
    53
    54         // Delete associated permission codes
    55         $codes = $this->Codes();
    56         foreach ( $codes as $code ) {
    57             $code->delete();
    58         }
    59     }
    60 }
    61

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -