diff --git a/code/CMSMain.php b/code/CMSMain.php index 8e4ee6c3..8417f720 100755 --- a/code/CMSMain.php +++ b/code/CMSMain.php @@ -477,18 +477,8 @@ JS; $this->extend('updateEditForm', $form); return $form; - } if ($id == 0) { - $siteConfig = SiteConfig::current_site_config(); - $fields = $siteConfig->getFormFields(); - if(Object::has_extension('SiteConfig',"Translatable")){ - $fields->push(new HiddenField('Locale','', $siteConfig->Locale )); - } - $form = new Form($this, "EditForm", $fields, $siteConfig->getFormActions()); - $form->loadDataFrom($siteConfig); - - $this->extend('updateEditForm', $form); - - return $form; + } if ($id == 0 || $id == 'root') { + $form = $this->RootForm(); } else if($id) { return new Form($this, "EditForm", new FieldSet( new LabelField('PageDoesntExistLabel',_t('CMSMain.PAGENOTEXISTS',"This page doesn't exist"))), new FieldSet()); @@ -496,7 +486,22 @@ JS; } } - + /** + * @return Form + */ + function RootForm() { + $siteConfig = SiteConfig::current_site_config(); + $fields = $siteConfig->getFormFields(); + if(Object::has_extension('SiteConfig',"Translatable")){ + $fields->push(new HiddenField('Locale','', $siteConfig->Locale )); + } + $form = new Form($this, "EditForm", $fields, $siteConfig->getFormActions()); + $form->loadDataFrom($siteConfig); + + $this->extend('updateEditForm', $form); + + return $form; + } //------------------------------------------------------------------------------------------// // Data saving handlers diff --git a/code/SecurityAdmin.php b/code/SecurityAdmin.php index d14dfc06..7482519f 100644 --- a/code/SecurityAdmin.php +++ b/code/SecurityAdmin.php @@ -29,6 +29,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider { 'memberimport', 'GroupImportForm', 'groupimport', + 'RootForm' ); /** @@ -57,82 +58,105 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider { Requirements::javascript(THIRDPARTY_DIR . "/greybox/AmiJS.js"); Requirements::javascript(THIRDPARTY_DIR . "/greybox/greybox.js"); } + + function getEditForm($id = null) { + if(!$id) $id = $this->currentPageID(); - public function getEditForm($id) { - $record = null; + if($id && $id != 'root') { + $record = DataObject::get_by_id($this->stat('tree_class'), $id); + if(!$record) return false; + } + + if($id && is_numeric($id)) { + $fields = $record->getCMSFields(); + + if($fields->hasTabSet()) { + $fields->findOrMakeTab('Root.Import',_t('Group.IMPORTTABTITLE', 'Import')); + $fields->addFieldToTab('Root.Import', + new LiteralField( + 'MemberImportFormIframe', + sprintf( + '', + $this->Link('memberimport') + ) + ) + ); + } - // Root form - if (($id == 'root' || $id == 0)) { - $fields = new FieldSet( - new TabSet( - 'Root', - new Tab('Import', _t('SecurityAdmin.TABIMPORT', 'Import'), - new LiteralField( - 'GroupImportFormIframe', - sprintf( - '', - $this->Link('groupimport') + $actions = new FieldSet( + new FormAction('addmember',_t('SecurityAdmin.ADDMEMBER','Add Member')), + new FormAction('save',_t('SecurityAdmin.SAVE','Save')) + ); + + $form = new Form($this, "EditForm", $fields, $actions); + $form->loadDataFrom($record); + + if(!$record->canEdit()) { + $readonlyFields = $form->Fields()->makeReadonly(); + $form->setFields($readonlyFields); + } + + // Filter permissions + $permissionField = $form->Fields()->dataFieldByName('Permissions'); + if($permissionField) $permissionField->setHiddenPermissions(self::$hidden_permissions); + + $this->extend('updateEditForm', $form); + } else { + $form = $this->RootForm(); + } + + return $form; + } + + /** + * @return FieldSet + */ + function RootForm() { + $memberList = new MemberTableField( + $this, + "Members" + ); + // unset 'inlineadd' permission, we don't want inline addition + $memberList->setPermissions(array('show', 'edit', 'delete', 'add')); + $memberList->setRelationAutoSetting(false); + + $fields = new FieldSet( + new TabSet( + 'Root', + new Tab('Members', singleton('Member')->i18n_plural_name(), + $memberList, + new LiteralField('MembersCautionText', + sprintf('

%s

', + _t( + 'SecurityAdmin.MemberListCaution', + 'Caution: Removing members from this list will remove them from all groups and the database' ) ) ) ), - // necessary for tree node selection in LeftAndMain.EditForm.js - new HiddenField('ID', false, 0) - ); - - $actions = new FieldSet(); - - $form = new Form( - $this, - 'EditForm', - $fields, - $actions - ); - - $this->extend('updateEditForm', $form); - - return $form; - } - - if($id && $id != 'root') { - $record = DataObject::get_by_id($this->stat('tree_class'), $id); - } - - if(!$record) return false; - - $fields = $record->getCMSFields(); - - if($fields->hasTabSet()) { - $fields->findOrMakeTab('Root.Import',_t('Group.IMPORTTABTITLE', 'Import')); - $fields->addFieldToTab('Root.Import', - new LiteralField( - 'MemberImportFormIframe', - sprintf( - '', - $this->Link('memberimport') + new Tab('Import', _t('SecurityAdmin.TABIMPORT', 'Import'), + new LiteralField( + 'GroupImportFormIframe', + sprintf( + '', + $this->Link('groupimport') + ) ) ) - ); - } - + ), + // necessary for tree node selection in LeftAndMain.EditForm.js + new HiddenField('ID', false, 0) + ); $actions = new FieldSet( - new FormAction('addmember',_t('SecurityAdmin.ADDMEMBER','Add Member')), - new FormAction('save',_t('SecurityAdmin.SAVE','Save')) + new FormAction('addmember',_t('SecurityAdmin.ADDMEMBER','Add Member')) ); - $form = new Form($this, "EditForm", $fields, $actions); - $form->loadDataFrom($record); - - if(!$record->canEdit()) { - $readonlyFields = $form->Fields()->makeReadonly(); - $form->setFields($readonlyFields); - } - - // Filter permissions - $permissionField = $form->Fields()->dataFieldByName('Permissions'); - if($permissionField) $permissionField->setHiddenPermissions(self::$hidden_permissions); - - $this->extend('updateEditForm', $form); + $form = new Form( + $this, + 'EditForm', + $fields, + $actions + ); return $form; } diff --git a/tests/SecurityAdminTest.php b/tests/SecurityAdminTest.php index 086c5b22..796502a3 100644 --- a/tests/SecurityAdminTest.php +++ b/tests/SecurityAdminTest.php @@ -10,13 +10,13 @@ class SecurityAdminTest extends FunctionalTest { $this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin')); /* First, open the applicable group */ - $this->get('admin/security/getitem?ID=' . $this->idFromFixture('Group','admin')); + $this->get('admin/security/show/' . $this->idFromFixture('Group','admin')); $this->assertRegExp('/]+id="Form_EditForm_Title"[^>]+value="Administrators"[^>]*>/',$this->content()); /* Then load the export page */ - $this->get('admin/security//EditForm/field/Members/export'); + $this->get('admin/security/EditForm/field/Members/export'); $lines = preg_split('/\n/', $this->content()); - + $this->assertEquals(count($lines), 3, "Export with members has one content row"); $this->assertRegExp('/"","","admin@example.com"/', $lines[1], "Member values are correctly exported"); } @@ -25,11 +25,11 @@ class SecurityAdminTest extends FunctionalTest { $this->session()->inst_set('loggedInAs', $this->idFromFixture('Member', 'admin')); /* First, open the applicable group */ - $this->get('admin/security/getitem?ID=' . $this->idFromFixture('Group','empty')); + $this->get('admin/security/show/' . $this->idFromFixture('Group','empty')); $this->assertRegExp('/]+id="Form_EditForm_Title"[^>]+value="Empty Group"[^>]*>/',$this->content()); /* Then load the export page */ - $this->get('admin/security//EditForm/field/Members/export'); + $this->get('admin/security/EditForm/field/Members/export'); $lines = preg_split('/\n/', $this->content()); $this->assertEquals(count($lines), 2, "Empty export only has header fields and an empty row");