Permalink
Browse files

ENHANCEMENT Replaced SecurityAdmin tree view for groups with three to…

…p-level tabs: "Users", "Groups" and "Roles"
  • Loading branch information...
1 parent e2c21cc commit 6f71186e2ca61b1a8c583c7a3db715410afefc25 @chillu chillu committed Mar 5, 2012
Showing with 90 additions and 96 deletions.
  1. +54 −53 admin/code/SecurityAdmin.php
  2. +0 −21 admin/templates/Includes/SecurityAdmin_Content.ss
  3. +36 −22 security/Group.php
View
107 admin/code/SecurityAdmin.php
@@ -84,16 +84,29 @@ public function getEditForm($id = null, $fields = null) {
* @return FieldList
*/
function RootForm() {
- $config = new GridFieldConfig_RecordEditor();
- $config->addComponent(new GridFieldExporter());
- $config->getComponentByType('GridFieldPopupForms')->setValidator(new Member_Validator());
- $memberList = new GridField('Members', 'All members', DataList::create('Member'), $config);
- $memberList->addExtraClass("members_grid");
+ $memberList = Object::create('GridField',
+ 'Members',
+ false,
+ DataList::create('Member'),
+ $memberListConfig = GridFieldConfig_RecordEditor::create()
+ ->addComponent(new GridFieldExporter())
+ )->addExtraClass("members_grid");
+ $memberListConfig->getComponentByType('GridFieldPopupForms')->setValidator(new Member_Validator());
+
+ $groupList = Object::create('GridField',
+ 'Groups',
+ false,
+ DataList::create('Group'),
+ GridFieldConfig_RecordEditor::create()
+ )->setDisplayFields(array(
+ 'Breadcrumbs' => singleton('Group')->fieldLabel('Title')
+ ));
+
$fields = new FieldList(
$root = new TabSet(
'Root',
- new Tab('Members', singleton('Member')->i18n_plural_name(),
+ new Tab('Users', _t('SecurityAdmin.Users', 'Users'),
$memberList,
new LiteralField('MembersCautionText',
sprintf('<p class="caution-remove"><strong>%s</strong></p>',
@@ -104,14 +117,8 @@ function RootForm() {
)
)
),
- new Tab('Import', _t('SecurityAdmin.TABIMPORT', 'Import'),
- new LiteralField(
- 'GroupImportFormIframe',
- sprintf(
- '<iframe src="%s" id="GroupImportFormIframe" width="100%%" height="400px" border="0"></iframe>',
- $this->Link('groupimport')
- )
- )
+ new Tab('Groups', singleton('Group')->plural_name(),
+ $groupList
)
),
// necessary for tree node selection in LeftAndMain.EditForm.js
@@ -138,6 +145,17 @@ function RootForm() {
$rolesTab->push($rolesField);
}
+ $fields->findOrMakeTab('Root.Import', _t('SecurityAdmin.TABIMPORT', 'Import'));
+ $fields->addFieldToTab('Root.Import',
+ new LiteralField(
+ 'GroupImportFormIframe',
+ sprintf(
+ '<iframe src="%s" id="GroupImportFormIframe" width="100%%" height="400px" border="0"></iframe>',
+ $this->Link('groupimport')
+ )
+ )
+ );
+
$actions = new FieldList();
$this->extend('updateRootFormFields', $fields, $actions);
@@ -220,12 +238,28 @@ public function GroupImportForm() {
return $form;
}
- function getCMSTreeTitle() {
- return _t('SecurityAdmin.SGROUPS', 'Security Groups');
- }
+ public function Breadcrumbs($unlinked = false) {
+ $crumbs = parent::Breadcrumbs($unlinked);
+
+ // Name root breadcrumb based on which record is edited,
+ // which can only be determined by looking for the fieldname of the GridField.
+ // Note: Titles should be same titles as tabs in RootForm().
+ $params = $this->request->allParams();
+ if(isset($params['FieldName'])) {
+ if($params['FieldName'] == 'Groups') {
+ $crumbs->First()->Title = singleton('Group')->plural_name();
+ } elseif($params['FieldName'] == 'Users') {
+ $crumbs->First()->Title = _t('SecurityAdmin.Users', 'Users');
+ } elseif($params['FieldName'] == 'Roles') {
+ $crumbs->First()->Title = _t('SecurityAdmin.TABROLES', 'Roles');
+ }
+ } else {
+ // Avoid writing "Users" (the controller menu title) as a breadcrumb
+ // because its confusing and inaccurate.
+ $crumbs = new ArrayList();
+ }
- public function EditedMember() {
- if(Session::get('currentMember')) return DataObject::get_by_id('Member', (int) Session::get('currentMember'));
+ return $crumbs;
}
function providePermissions() {
@@ -286,37 +320,4 @@ static function get_hidden_permissions(){
static function clear_hidden_permissions(){
self::$hidden_permissions = array();
}
-}
-
-/**
- * Delete multiple {@link Group} records. Usually used through the {@link SecurityAdmin} interface.
- *
- * @package cms
- * @subpackage batchactions
- */
-class SecurityAdmin_DeleteBatchAction extends CMSBatchAction {
- function getActionTitle() {
- return _t('AssetAdmin_DeleteBatchAction.TITLE', 'Delete groups');
- }
-
- function run(SS_List $records) {
- $status = array(
- 'modified'=>array(),
- 'deleted'=>array()
- );
-
- foreach($records as $record) {
- // TODO Provide better feedback if permission was denied
- if(!$record->canDelete()) continue;
-
- $id = $record->ID;
- $record->delete();
- $status['deleted'][$id] = array();
- $record->destroy();
- unset($record);
- }
-
- return Convert::raw2json($status);
- }
-}
-
+}
View
21 admin/templates/Includes/SecurityAdmin_Content.ss
@@ -1,21 +0,0 @@
-<div class="cms-content center $BaseCSSClasses" data-layout-type="border">
- <div class="cms-content-tools west">
- <div class="cms-content-header north">
- <div>
- <h2>
- <% include CMSBreadcrumbs %>
- </h2>
- </div>
- </div>
-
- $AddForm
-
- <div data-url-tree="$Link(getsubtree)" data-url-savetreenode="$Link(savetreenode)" class="cms-tree draggable jstree jstree-apple">
- $SiteTreeAsUL
- </div>
-
- </div>
-
- $EditForm
-
-</div>
View
58 security/Group.php
@@ -62,23 +62,19 @@ function getAllChildren() {
public function getCMSFields() {
Requirements::javascript(SAPPHIRE_DIR . '/javascript/PermissionCheckboxSetField.js');
- $config = new GridFieldConfig_RelationEditor();
- $config->addComponents(new GridFieldExporter());
- $config->getComponentByType('GridFieldRelationAdd')
- ->setResultsFormat('$Title ($Email)')->setSearchFields(array('FirstName', 'Surname', 'Email'));
- $config->getComponentByType('GridFieldPopupForms')->setValidator(new Member_Validator());
-
- $memberList = new GridField('Members','Members', $this->Members(), $config);
- $memberList->addExtraClass('members_grid');
-
- // @todo Implement permission checking on GridField
- //$memberList->setPermissions(array('edit', 'delete', 'export', 'add', 'inlineadd'));
- //$memberList->setPopupCaption(_t('SecurityAdmin.VIEWUSER', 'View User'));
$fields = new FieldList(
new TabSet("Root",
new Tab('Members', _t('SecurityAdmin.MEMBERS', 'Members'),
new TextField("Title", $this->fieldLabel('Title')),
- $memberList
+ Object::create('DropdownField',
+ 'ParentID',
+ $this->fieldLabel('Parent'),
+ DataList::create('Group')->exclude('ID', $this->ID)->map('ID', 'Breadcrumbs')
+ )->setEmptyString(' '),
+ new LiteralField(
+ 'ParentIDDescription',
+ '<p><em>' . _t('Group.GroupReminder', 'If you choose a parent group, this group will take all it\'s roles') . '</em></p>'
+ )
),
$permissionsTab = new Tab('Permissions', _t('SecurityAdmin.PERMISSIONS', 'Permissions'),
@@ -92,6 +88,18 @@ public function getCMSFields() {
)
)
);
+
+ if($this->ID) {
+ $config = new GridFieldConfig_RelationEditor();
+ $config->addComponents(new GridFieldExporter());
+ $config->getComponentByType('GridFieldRelationAdd')
+ ->setResultsFormat('$Title ($Email)')->setSearchFields(array('FirstName', 'Surname', 'Email'));
+ $config->getComponentByType('GridFieldPopupForms')->setValidator(new Member_Validator());
+ $memberList = Object::create('GridField', 'Members',false, $this->Members(), $config)->addExtraClass('members_grid');
+ // @todo Implement permission checking on GridField
+ //$memberList->setPermissions(array('edit', 'delete', 'export', 'add', 'inlineadd'));
+ $fields->addFieldToTab('Root.Members', $memberList);
+ }
// Only add a dropdown for HTML editor configurations if more than one is available.
// Otherwise Member->getHtmlEditorConfigForCMS() will default to the 'cms' configuration.
@@ -109,7 +117,6 @@ public function getCMSFields() {
if(!Permission::check('EDIT_PERMISSIONS')) {
$fields->removeFieldFromTab('Root', 'Permissions');
- $fields->removeFieldFromTab('Root', 'IP Addresses');
}
// Only show the "Roles" tab if permissions are granted to edit them,
@@ -137,19 +144,26 @@ public function getCMSFields() {
// Add roles (and disable all checkboxes for inherited roles)
$allRoles = Permission::check('ADMIN') ? DataObject::get('PermissionRole') : DataObject::get('PermissionRole', 'OnlyAdminCanApply = 0');
- $groupRoles = $this->Roles();
- $inheritedRoles = new ArrayList();
- $ancestors = $this->getAncestors();
- foreach($ancestors as $ancestor) {
- $ancestorRoles = $ancestor->Roles();
- if($ancestorRoles) $inheritedRoles->merge($ancestorRoles);
+ if($this->ID) {
+ $groupRoles = $this->Roles();
+ $inheritedRoles = new ArrayList();
+ $ancestors = $this->getAncestors();
+ foreach($ancestors as $ancestor) {
+ $ancestorRoles = $ancestor->Roles();
+ if($ancestorRoles) $inheritedRoles->merge($ancestorRoles);
+ }
+ $groupRoleIDs = $groupRoles->column('ID') + $inheritedRoles->column('ID');
+ $inheritedRoleIDs = $inheritedRoles->column('ID');
+ } else {
+ $groupRoleIDs = array();
+ $inheritedRoleIDs = array();
}
- $groupRoleIDs = $groupRoles->column('ID') + $inheritedRoles->column('ID');
+
$rolesField = Object::create('ListboxField', 'Roles', false, $allRoles->map()->toArray())
->setMultiple(true)
->setDefaultItems($groupRoleIDs)
->setAttribute('data-placeholder', _t('Group.AddRole', 'Add a role for this group'))
- ->setDisabledItems($inheritedRoles->column('ID'));
+ ->setDisabledItems($inheritedRoleIDs);
if(!$allRoles->Count()) $rolesField->setAttribute('data-placeholder', _t('Group.NoRoles', 'No roles found'));
$fields->addFieldToTab('Root.Roles', $rolesField);
}

0 comments on commit 6f71186

Please sign in to comment.