MINOR added more documentation around SiteConfig. Also wrote unit tests for permissions inheritance off it. (from r86132)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@89164 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-10-15 21:53:15 +00:00
parent b930149c3a
commit 7dd6d10cde
5 changed files with 96 additions and 6 deletions

View File

@ -37,6 +37,8 @@ class TableListField extends FormField {
protected $fieldList; protected $fieldList;
protected $disableSorting = false;
/** /**
* @var $fieldListCsv array * @var $fieldListCsv array
*/ */
@ -342,6 +344,10 @@ JS
} }
return new DataObjectSet($headings); return new DataObjectSet($headings);
} }
function disableSorting($to = true) {
$this->disableSorting = $to;
}
/** /**
* Determines if a field is "sortable". * Determines if a field is "sortable".
@ -352,7 +358,7 @@ JS
* @return bool * @return bool
*/ */
function isFieldSortable($fieldName) { function isFieldSortable($fieldName) {
if($this->customSourceItems) { if($this->customSourceItems || $this->disableSorting) {
return false; return false;
} }
@ -362,8 +368,14 @@ JS
$query = $this->__cachedQuery = $this->getQuery(); $query = $this->__cachedQuery = $this->getQuery();
} }
$sql = $query->sql(); $sql = $query->sql();
$selects = $query->select;
foreach($selects as $i => $sel) {
if (preg_match('/"(.+?)"\."(.+?)"/', $sel, $matches)) $selects[$i] = $matches[2];
}
$SQL_fieldName = Convert::raw2sql($fieldName); $SQL_fieldName = Convert::raw2sql($fieldName);
return (in_array($SQL_fieldName,$query->select) || stripos($sql,"AS {$SQL_fieldName}")); return (in_array($SQL_fieldName,$selects) || stripos($sql,"AS {$SQL_fieldName}"));
} }
/** /**

View File

@ -101,6 +101,21 @@ class Group extends DataObject {
$fields->removeFieldFromTab('Root', 'IP Addresses'); $fields->removeFieldFromTab('Root', 'IP Addresses');
} }
if(Permission::check('EDIT_PERMISSIONS') && DataObject::get('PermissionRole')) {
$fields->addFieldToTab(_t('SecurityAdmin.ROLES', 'Roles'),
new LiteralField(
"",
"<p>" .
_t('SecurityAdmin.ROLESDESCRIPTION',
"This section allows you to add roles to this group. Roles are logical groupings of permissions, which can be editied in the Roles tab"
) .
"</p>"
)
);
$fields->addFieldToTab(_t('SecurityAdmin.ROLES', 'Roles'), new CheckboxSetField('Roles', 'Roles', DataObject::get('PermissionRole')));
}
$memberList->setController($this); $memberList->setController($this);
$memberList->setPermissions(array('show', 'edit', 'delete', 'export', 'add')); $memberList->setPermissions(array('show', 'edit', 'delete', 'export', 'add'));
$memberList->setParentClass('Group'); $memberList->setParentClass('Group');

View File

@ -16,6 +16,8 @@
$cacheOn = true; $cacheOn = true;
$cacheDebug = false; $cacheDebug = false;
$hostmapLocation = '../subsites/host-map.php'; $hostmapLocation = '../subsites/host-map.php';
date_default_timezone_set('Pacific/Auckland');
if ($cacheOn) { if ($cacheOn) {
if (file_exists($hostmapLocation)) { if (file_exists($hostmapLocation)) {
@ -34,14 +36,14 @@ if ($cacheOn) {
$file = $file ? $file : 'index'; $file = $file ? $file : 'index';
if (file_exists('../cache/'.$cacheDir.$file.'.html')) { if (file_exists('../cache/'.$cacheDir.$file.'.html')) {
header('X-cache: hit at '.date('r')); header('X-cache: hit at '.@date('r'));
echo file_get_contents('../cache/'.$cacheDir.$file.'.html'); echo file_get_contents('../cache/'.$cacheDir.$file.'.html');
} elseif (file_exists('../cache/'.$cacheDir.$file.'.php')) { } elseif (file_exists('../cache/'.$cacheDir.$file.'.php')) {
header('X-cache: hit at '.date('r')); header('X-cache: hit at '.@date('r'));
include_once '../cache/'.$cacheDir.$file.'.php'; include_once '../cache/'.$cacheDir.$file.'.php';
if ($cacheDebug) echo "<h1>File was cached</h1>"; if ($cacheDebug) echo "<h1>File was cached</h1>";
} else { } else {
header('X-cache: miss at '.date('r') . ' on ' . $cacheDir . $file); header('X-cache: miss at '.@date('r') . ' on ' . $cacheDir . $file);
// No cache hit... fallback!!! // No cache hit... fallback!!!
include 'main.php'; include 'main.php';
if ($cacheDebug) echo "<h1>File was !NOT! cached</h1>"; if ($cacheDebug) echo "<h1>File was !NOT! cached</h1>";

View File

@ -263,7 +263,7 @@ class SiteTreePermissionsTest extends FunctionalTest {
// Get the live version of the page // Get the live version of the page
$page = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $pageID"); $page = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $pageID");
// subadmin users // subadmin users
$subadminuser = $this->objFromFixture('Member', 'subadmin'); $subadminuser = $this->objFromFixture('Member', 'subadmin');
$this->assertTrue( $this->assertTrue(
@ -271,6 +271,57 @@ class SiteTreePermissionsTest extends FunctionalTest {
'Authenticated members can edit a page that was deleted from stage and marked as "Editable by logged in users" if they have cms permissions and belong to any of these groups' 'Authenticated members can edit a page that was deleted from stage and marked as "Editable by logged in users" if they have cms permissions and belong to any of these groups'
); );
} }
function testInheritCanViewFromSiteConfig() {
$page = $this->objFromFixture('Page', 'inheritWithNoParent');
$siteconfig = $this->objFromFixture('SiteConfig', 'default');
$editor = $this->objFromFixture('Member', 'editor');
$editorGroup = $this->objFromFixture('Group', 'editorgroup');
$siteconfig->CanViewType = 'Anyone';
$siteconfig->write();
$this->assertTrue($page->canView(FALSE), 'Anyone can view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to LoggedInUsers');
$siteconfig->CanViewType = 'LoggedInUsers';
$siteconfig->write();
$this->assertFalse($page->canView(FALSE), 'Anonymous can\'t view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to LoggedInUsers');
$siteconfig->CanViewType = 'LoggedInUsers';
$siteconfig->write();
$this->assertTrue($page->canView($editor), 'Users can view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to LoggedInUsers');
$siteconfig->CanViewType = 'OnlyTheseUsers';
$siteconfig->ViewerGroups()->add($editorGroup);
$siteconfig->ViewerGroups()->write();
$siteconfig->write();
$this->assertTrue($page->canView($editor), 'Editors can view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to OnlyTheseUsers');
$this->assertFalse($page->canView(FALSE), 'Anonymous can\'t view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to OnlyTheseUsers');
}
function testInheritCanEditFromSiteConfig() {
$page = $this->objFromFixture('Page', 'inheritWithNoParent');
$siteconfig = $this->objFromFixture('SiteConfig', 'default');
$editor = $this->objFromFixture('Member', 'editor');
$user = $this->objFromFixture('Member', 'websiteuser');
$editorGroup = $this->objFromFixture('Group', 'editorgroup');
$siteconfig->CanEditType = 'LoggedInUsers';
$siteconfig->write();
$this->assertFalse($page->canEdit(FALSE), 'Anonymous can\'t edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to LoggedInUsers');
$this->session()->inst_set('loggedInAs', $editor->ID);
$this->assertTrue($page->canEdit(), 'Users can edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to LoggedInUsers');
$siteconfig->CanEditType = 'OnlyTheseUsers';
$siteconfig->EditorGroups()->add($editorGroup);
$siteconfig->EditorGroups()->write();
$siteconfig->write();
$this->assertTrue($page->canEdit($editor), 'Editors can edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to OnlyTheseUsers');
$this->session()->inst_set('loggedInAs', null);
$this->assertFalse($page->canEdit(FALSE), 'Anonymous can\'t edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to OnlyTheseUsers');
$this->session()->inst_set('loggedInAs', $user->ID);
$this->assertFalse($page->canEdit($user), 'Website user can\'t edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to OnlyTheseUsers');
}
} }
?> ?>

View File

@ -1,3 +1,9 @@
SiteConfig:
default:
Title: My test site
Tagline: There is no doubt this is a great test site
CanViewType: Anyone
CanEditType: LoggedInUsers
Permission: Permission:
cmsmain1: cmsmain1:
Code: CMS_ACCESS_CMSMain Code: CMS_ACCESS_CMSMain
@ -50,6 +56,10 @@ Page:
CanEditType: OnlyTheseUsers CanEditType: OnlyTheseUsers
EditorGroups: =>Group.subadmingroup EditorGroups: =>Group.subadmingroup
URLSegment: restrictedEditOnlySubadminGroup URLSegment: restrictedEditOnlySubadminGroup
inheritWithNoParent:
CanEditType: Inherit
CanViewType: Inherit
URLSegment: inheritWithNoParent
parent_restrictedViewOnlySubadminGroup: parent_restrictedViewOnlySubadminGroup:
CanViewType: OnlyTheseUsers CanViewType: OnlyTheseUsers
ViewerGroups: =>Group.subadmingroup ViewerGroups: =>Group.subadmingroup