BUGFIX: Fixed bug where you couldn't edit templates that had no subdomain.

ENHANCEMENT: Mark global groups in the subsite list, rather than subsite groups.
ENHANCEMENT: When creating a subsite from a template, copy the groups as well as the pages, but leave the groups empty.
This commit is contained in:
Sam Minnee 2009-02-24 22:09:15 +00:00
parent 6537535da2
commit 4ba1ce143a
3 changed files with 70 additions and 4 deletions

View File

@ -42,9 +42,9 @@ class GroupSubsites extends DataObjectDecorator {
*/
function alternateTreeTitle() {
if($this->owner->SubsiteID == 0) {
return $this->owner->Title;
return $this->owner->Title . ' <i>(global group)</i>';
} else {
return $this->owner->Title . ' <i>(' . $this->owner->Subsite()->Title . ')</i>';
return $this->owner->Title; // . ' <i>(' . $this->owner->Subsite()->Title . ')</i>';
}
}
@ -84,6 +84,38 @@ class GroupSubsites extends DataObjectDecorator {
return $access;
}
/**
* Create a duplicate of this group and save it to another subsite.
* The group and permissions will be duplicated, but not the members.
* @param $subsiteID int|Subsite The Subsite to copy to, or its ID
*/
public function duplicateToSubsite($subsiteID = null) {
if(is_object($subsiteID)) {
$subsite = $subsiteID;
$subsiteID = $subsite->ID;
} else {
$subsite = DataObject::get_by_id('Subsite', $subsiteID);
}
$group = $this->owner->duplicate(false);
$subsiteID = ($subsiteID ? $subsiteID : Subsite::currentSubsiteID());
$group->SubsiteID = $subsiteID;
$group->write();
// Duplicate permissions
$permissions = $this->owner->Permissions();
foreach($permissions as $permission) {
$newPerm = $permission->duplicate(false);
$newPerm->GroupID = $group->ID;
$newPerm->write();
}
return $group;
}
}
?>

View File

@ -433,6 +433,9 @@ JS;
* Return the subsites that the current user can access.
* Look for one of the given permission codes on the site.
*
* Sites will only be included if they have a Title and a Subdomain.
* Templates will only be included if they have a Title.
*
* @param $permCode array|string Either a single permission code or an array of permission codes.
*/
function accessible_sites($permCode) {
@ -442,12 +445,14 @@ JS;
else $SQL_codes = "'" . Convert::raw2sql($permCode) . "'";
if(!$member) return new DataObjectSet();
$templateClassList = "'" . implode("', '", ClassInfo::subclassesFor("Subsite_Template")) . "'";
$subsites = DataObject::get(
'Subsite',
"`Group_Members`.`MemberID` = $member->ID
AND `Permission`.`Code` IN ($SQL_codes, 'ADMIN')
AND Subdomain IS NOT NULL AND `Subsite`.Title != ''",
AND (Subdomain IS NOT NULL OR `Subsite`.ClassName IN ($templateClassList)) AND `Subsite`.Title != ''",
'',
"LEFT JOIN `Group` ON (`SubsiteID`=`Subsite`.`ID` OR `SubsiteID` = 0)
LEFT JOIN `Group_Members` ON `Group_Members`.`GroupID`=`Group`.`ID`
@ -514,7 +519,7 @@ class Subsite_Template extends Subsite {
self::changeSubsite($this->ID);
/*
* Copy data from this template to the given subsite. Does this using an iterative depth-first search.
* Copy site content from this template to the given subsite. Does this using an iterative depth-first search.
* This will make sure that the new parents on the new subsite are correct, and there are no funny
* issues with having to check whether or not the new parents have been added to the site tree
* when a page, etc, is duplicated
@ -535,6 +540,15 @@ class Subsite_Template extends Subsite {
}
}
}
/**
* Copy groups from the template to the given subsites. Each of the groups will be created and left
* empty.
*/
$groups = DataObject::get("Group", "SubsiteID = '$this->ID'");
if($groups) foreach($groups as $group) {
$group->duplicateToSubsite($intranet);
}
self::changeSubsite($oldSubsiteID);

View File

@ -91,6 +91,26 @@ class SubsiteAdminTest extends SapphireTest {
$cont->popCurrent();
}
/**
* Test that the main-site user with ADMIN permissions can access all subsites, regardless
* of whether he is in a subsite-specific group or not.
*/
function testMainsiteAdminCanAccessAllSubsites() {
$member = $this->objFromFixture('Member', 'admin');
$member->logIn();
$cmsMain = new CMSMain();
foreach($cmsMain->Subsites() as $subsite) {
$ids[$subsite->ID] = true;
}
$this->assertArrayHasKey(0, $ids, "Main site accessible");
$this->assertArrayHasKey(1, $ids, "Site with no groups inaccesible");
$this->assertArrayHasKey(2, $ids, "Subsite1 Template inaccessible");
$this->assertArrayHasKey(3, $ids, "Subsite2 Template inaccessible");
}
}