MINOR update PermissionCheckboxSetField to look at roles on the actual group

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90677 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Tom Rix 2009-11-03 01:00:54 +00:00
parent b5a5500ff4
commit a1fdff6910
2 changed files with 66 additions and 25 deletions

View File

@ -84,7 +84,8 @@ class Group extends DataObject {
'Permissions',
'Permissions',
'Permission',
'GroupID')
'GroupID',
$this)
),
new Tab(_t('Security.IPADDRESSES', 'IP Addresses'),
@ -108,15 +109,15 @@ class Group extends DataObject {
$fields->removeFieldFromTab('Root', 'Permissions');
$fields->removeFieldFromTab('Root', 'IP Addresses');
} else {
$parentGroups = $this->getAllParents();
if ($parentGroups) {
foreach ($parentGroups as $parent) {
if ($parent->Permissions()->Count()) {
$permissionsTab->push(new HeaderField('PermissionHeader-'.$parent->ID, 'Permissions inherited from '.$parent->Title));
$permissionsTab->push(new LiteralField('PermissionList-'.$parent->ID, join(', ', $parent->Permissions()->column('Code'))));
}
}
}
// $parentGroups = $this->getAllParents();
// if ($parentGroups) {
// foreach ($parentGroups as $parent) {
// if ($parent->Permissions()->Count()) {
// $permissionsTab->push(new HeaderField('PermissionHeader-'.$parent->ID, 'Permissions inherited from '.$parent->Title));
// $permissionsTab->push(new LiteralField('PermissionList-'.$parent->ID, join(', ', $parent->Permissions()->column('Code'))));
// }
// }
// }
}
if(Permission::check('APPLY_ROLES') && DataObject::get('PermissionRole')) {
@ -133,15 +134,15 @@ class Group extends DataObject {
$roleData = Permission::check('ADMIN') ? DataObject::get('PermissionRole') : DataObject::get('PermissionRole', 'OnlyAdminCanApply = 0');
$fields->addFieldToTab('Root.' . _t('SecurityAdmin.ROLES', 'Roles'), new CheckboxSetField('Roles', 'Roles', $roleData));
$parentGroups = $this->getAllParents();
if ($parentGroups) {
foreach ($parentGroups as $parent) {
if ($parent->Roles()->Count()) {
$fields->addFieldToTab('Root.' . _t('SecurityAdmin.ROLES', 'Roles'), new HeaderField('RolesHeader-'.$parent->ID, 'Roles inherited from '.$parent->Title));
$fields->addFieldToTab('Root.' . _t('SecurityAdmin.ROLES', 'Roles'), new LiteralField('RolesList-'.$parent->ID, join(', ', $parent->Roles()->column('Title'))));
}
}
}
// $parentGroups = $this->getAllParents();
// if ($parentGroups) {
// foreach ($parentGroups as $parent) {
// if ($parent->Roles()->Count()) {
// $fields->addFieldToTab('Root.' . _t('SecurityAdmin.ROLES', 'Roles'), new HeaderField('RolesHeader-'.$parent->ID, 'Roles inherited from '.$parent->Title));
// $fields->addFieldToTab('Root.' . _t('SecurityAdmin.ROLES', 'Roles'), new LiteralField('RolesList-'.$parent->ID, join(', ', $parent->Roles()->column('Title'))));
// }
// }
// }
}

View File

@ -1,9 +1,10 @@
<?php
class PermissionCheckboxSetField extends CheckboxSetField {
function __construct($name, $title, $managedClass, $filterField) {
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));
}
@ -31,6 +32,40 @@ class PermissionCheckboxSetField extends CheckboxSetField {
$odd = 0;
$options = '';
$inheritedItems = array();
if ($this->record) {
if ($this->record->Roles()->Count()) {
foreach($this->record->Roles() as $role) {
foreach($role->Codes() as $code) {
if (!isset($inheritedItems[$code->Code])) $inheritedItems[$code->Code] = array();
$inheritedItems[$code->Code][] = 'from role '.$role->Title;
}
}
}
$parentGroups = $this->record->getAllParents();
if ($parentGroups) {
foreach ($parentGroups as $parent) {
if ($parent->Roles()->Count()) {
foreach($parent->Roles() as $role) {
if ($role->Codes()) {
foreach($role->Codes() as $code) {
if (!isset($inheritedItems[$code->Code])) $inheritedItems[$code->Code] = array();
$inheritedItems[$code->Code][] = 'role '.$role->Title.' on group '.$parent->Title;
}
}
}
}
if ($parent->Permissions()->Count()) {
foreach($parent->Permissions() as $permission) {
if (!isset($inheritedItems[$permission->Code])) $inheritedItems[$permission->Code] = array();
$inheritedItems[$permission->Code][] = 'group '.$parent->Title;
}
}
}
}
}
if($source) {
foreach($source as $categoryName => $permissions) {
$options .= "<li><h5>$categoryName</h5></li>";
@ -42,14 +77,19 @@ class PermissionCheckboxSetField extends CheckboxSetField {
$extraClass = $odd ? 'odd' : 'even';
$extraClass .= ' val' . str_replace(' ', '', $key);
$itemID = $this->id() . '_' . ereg_replace('[^a-zA-Z0-9]+', '', $key);
$checked = '';
$checked = $disabled = $inheritMessage = '';
$checked = in_array($key, $values) ? ' checked="checked"' : '';
$title = $permission['help'] ? 'title="'.htmlentities($permission['help']).'" ' : '';
$options .= "<li class=\"$extraClass\"><input id=\"$itemID\" name=\"$this->name[$key]\" type=\"checkbox\" value=\"$key\"$checked class=\"checkbox\" /> <label {$title}for=\"$itemID\">$value</label></li>\n";
$title = $permission['help'] ? 'title="'.htmlentities($permission['help']).'" ' : '';
if (isset($inheritedItems[$code])) {
$disabled = ' disabled="true"';
$inheritMessage = ' inherited from '.join(', ', $inheritedItems[$code]).'';
$options .= "<li class=\"$extraClass\"><label {$title}for=\"$itemID\">$value is $inheritMessage</label></li>\n";
} else {
$options .= "<li class=\"$extraClass\"><input id=\"$itemID\"$disabled name=\"$this->name[$key]\" type=\"checkbox\" value=\"$key\"$checked class=\"checkbox\" /> <label {$title}for=\"$itemID\">$value$inheritMessage</label></li>\n";
}
}
}
}