mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 09:05:55 +00:00
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:
parent
6537535da2
commit
4ba1ce143a
@ -42,9 +42,9 @@ class GroupSubsites extends DataObjectDecorator {
|
|||||||
*/
|
*/
|
||||||
function alternateTreeTitle() {
|
function alternateTreeTitle() {
|
||||||
if($this->owner->SubsiteID == 0) {
|
if($this->owner->SubsiteID == 0) {
|
||||||
return $this->owner->Title;
|
return $this->owner->Title . ' <i>(global group)</i>';
|
||||||
} else {
|
} 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;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
@ -433,6 +433,9 @@ JS;
|
|||||||
* Return the subsites that the current user can access.
|
* Return the subsites that the current user can access.
|
||||||
* Look for one of the given permission codes on the site.
|
* 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.
|
* @param $permCode array|string Either a single permission code or an array of permission codes.
|
||||||
*/
|
*/
|
||||||
function accessible_sites($permCode) {
|
function accessible_sites($permCode) {
|
||||||
@ -443,11 +446,13 @@ JS;
|
|||||||
|
|
||||||
if(!$member) return new DataObjectSet();
|
if(!$member) return new DataObjectSet();
|
||||||
|
|
||||||
|
$templateClassList = "'" . implode("', '", ClassInfo::subclassesFor("Subsite_Template")) . "'";
|
||||||
|
|
||||||
$subsites = DataObject::get(
|
$subsites = DataObject::get(
|
||||||
'Subsite',
|
'Subsite',
|
||||||
"`Group_Members`.`MemberID` = $member->ID
|
"`Group_Members`.`MemberID` = $member->ID
|
||||||
AND `Permission`.`Code` IN ($SQL_codes, 'ADMIN')
|
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` ON (`SubsiteID`=`Subsite`.`ID` OR `SubsiteID` = 0)
|
||||||
LEFT JOIN `Group_Members` ON `Group_Members`.`GroupID`=`Group`.`ID`
|
LEFT JOIN `Group_Members` ON `Group_Members`.`GroupID`=`Group`.`ID`
|
||||||
@ -514,7 +519,7 @@ class Subsite_Template extends Subsite {
|
|||||||
self::changeSubsite($this->ID);
|
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
|
* 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
|
* issues with having to check whether or not the new parents have been added to the site tree
|
||||||
* when a page, etc, is duplicated
|
* when a page, etc, is duplicated
|
||||||
@ -536,6 +541,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);
|
self::changeSubsite($oldSubsiteID);
|
||||||
|
|
||||||
return $intranet;
|
return $intranet;
|
||||||
|
@ -92,6 +92,26 @@ class SubsiteAdminTest extends SapphireTest {
|
|||||||
$cont->popCurrent();
|
$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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
x
Reference in New Issue
Block a user