mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
Merged from branches/0.1
This commit is contained in:
parent
6037ec56e5
commit
b646a104f1
@ -13,6 +13,7 @@ Object::add_extension('LeftAndMain', 'LeftAndMainSubsites');
|
||||
Object::add_extension('LeftAndMain', 'ControllerSubsites');
|
||||
|
||||
Object::add_extension('Group', 'GroupSubsites');
|
||||
Object::add_extension('Member', 'MemberSubsites');
|
||||
Object::add_extension('File', 'FileSubsites');
|
||||
|
||||
// Backwards compatibility with SilverStripe 2.2
|
||||
|
@ -34,9 +34,9 @@ class FileSubsites extends DataObjectDecorator {
|
||||
if($sites)$fields->addFieldToTab('Root.Details', new DropdownField("SubsiteID", "Subsite", $sites->toDropdownMap('ID', 'Title', "(Public)")));
|
||||
}
|
||||
|
||||
if($this->owner->SubsiteID == 0&&!Permission::check('EDIT_PERMISSIONS')){
|
||||
if($this->owner->SubsiteID == 0 && !Permission::check('EDIT_PERMISSIONS') && !Permission::check('SUBSITE_ASSETS_EDIT')){
|
||||
$fields->removeFieldFromTab("Root", "Upload");
|
||||
$fields->transform(new ReadonlyTransformation());
|
||||
$fields = $fields->transform(new ReadonlyTransformation());
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,6 +64,11 @@ class FileSubsites extends DataObjectDecorator {
|
||||
if(!$this->owner->ID && !$this->owner->SubsiteID) $this->owner->SubsiteID = Subsite::currentSubsiteID();
|
||||
}
|
||||
|
||||
function onAfterUpload() {
|
||||
$this->owner->SubsiteID = Subsite::currentSubsiteID();
|
||||
$this->owner->write();
|
||||
}
|
||||
|
||||
function alternateCanEdit() {
|
||||
// Check the CMS_ACCESS_SecurityAdmin privileges on the subsite that owns this group
|
||||
$subsiteID = Session::get('SubsiteID');
|
||||
|
@ -18,20 +18,35 @@ class GroupSubsites extends DataObjectDecorator {
|
||||
}
|
||||
|
||||
function updateCMSFields(&$fields) {
|
||||
|
||||
if( $this->owner->SubsiteID == 0 || $this->owner->canEdit() ){
|
||||
$subsites = DataObject::get('Subsite');
|
||||
if ( $subsites && $subsites->exists() ) {
|
||||
$oldSubsiteID = Session::get('SubsiteID');
|
||||
foreach( $subsites as $subsite ) {
|
||||
Subsite::changeSubsite($subsite->ID);
|
||||
if ( !Permission::check('CL_Admin') ) { $subsites->remove( $subsite ) ; }
|
||||
}
|
||||
Subsite::changeSubsite($oldSubsiteID);
|
||||
|
||||
$tab = $fields->findOrMakeTab(
|
||||
'Root.Subsites',
|
||||
_t('GroupSubsites.SECURITYTABTITLE', 'Subsites')
|
||||
);
|
||||
$tab->push(new DropdownField(
|
||||
|
||||
$dropdown = new DropdownField(
|
||||
'SubsiteID',
|
||||
_t('GroupSubsites.SECURITYACCESS', 'Limit CMS access to subsites', PR_MEDIUM, 'Dropdown listing existing subsites which this group has access to'),
|
||||
($subsites) ? $subsites->toDropDownMap() : null,
|
||||
$subsites->toDropDownMap(),
|
||||
null,
|
||||
null,
|
||||
''
|
||||
));
|
||||
);
|
||||
if ( $subsites->Count() == 1 ) $dropdown = $dropdown->transform(new ReadonlyTransformation()) ;
|
||||
|
||||
$tab->push($dropdown) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,14 +93,13 @@ class GroupSubsites extends DataObjectDecorator {
|
||||
// Check the CMS_ACCESS_SecurityAdmin privileges on the subsite that owns this group
|
||||
$oldSubsiteID = Session::get('SubsiteID');
|
||||
|
||||
Session::set('SubsiteID', $this->owner->SubsiteID);
|
||||
Subsite::changeSubsite($this->owner->SubsiteID) ;
|
||||
$access = Permission::check('CMS_ACCESS_SecurityAdmin');
|
||||
Session::set('SubsiteID', $oldSubsiteID);
|
||||
Subsite::changeSubsite($oldSubsiteID) ;
|
||||
|
||||
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.
|
||||
|
@ -78,6 +78,9 @@ class LeftAndMainSubsites extends Extension {
|
||||
$mainSiteTitle = "Main site";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$mainSiteTitle = "Main site";
|
||||
break;
|
||||
}
|
||||
|
||||
if($mainSiteTitle && Subsite::hasMainSitePermission(Member::currentUser(), array('CMS_ACCESS_' . $this->owner->class, 'ADMIN')))
|
||||
|
20
code/MemberSubsites.php
Normal file
20
code/MemberSubsites.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* Extension for the Group object to add subsites support
|
||||
*
|
||||
* @package subsites
|
||||
*/
|
||||
class MemberSubsites extends DataObjectDecorator {
|
||||
|
||||
/* Only allow adding to groups we can edit */
|
||||
public function saveGroups( $groups ) {
|
||||
$groups = explode( ',', $groups ) ;
|
||||
$filtered = array() ;
|
||||
foreach( $groups as $groupID ) {
|
||||
$group = DataObject::get_by_id('Group', $groupID) ;
|
||||
if ( $group && $group->canEdit() ) $filtered[] = $groupID ;
|
||||
}
|
||||
$this->owner->Groups()->setByIDList( $filtered ) ;
|
||||
}
|
||||
|
||||
}
|
@ -282,6 +282,10 @@ JS;
|
||||
else $subsiteID = $subsite;
|
||||
|
||||
Session::set('SubsiteID', $subsiteID);
|
||||
|
||||
// And clear caches
|
||||
self::$cached_subsite = NULL ;
|
||||
Permission::flush_permission_cache() ;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -491,6 +495,7 @@ JS;
|
||||
return array(
|
||||
'SUBSITE_EDIT' => 'Edit Sub-site Details',
|
||||
'SUBSITE_ACCESS_ALL' => 'Access all subsites',
|
||||
'SUBSITE_ASSETS_EDIT' => 'Edit Sub-site Assets Admin'
|
||||
);
|
||||
}
|
||||
|
||||
@ -540,7 +545,7 @@ class Subsite_Template extends Subsite {
|
||||
while(count($stack) > 0) {
|
||||
list($sourceParentID, $destParentID) = array_pop($stack);
|
||||
|
||||
$children = Versioned::get_by_stage('Page', 'Live', "`ParentID`=$sourceParentID", '');
|
||||
$children = Versioned::get_by_stage('SiteTree', 'Live', "`ParentID`=$sourceParentID", '');
|
||||
|
||||
if($children) {
|
||||
foreach($children as $child) {
|
||||
|
@ -79,7 +79,7 @@ class SubsiteAdmin extends GenericDataAdmin {
|
||||
'subsite' => 'New site',
|
||||
'template' => 'New template',
|
||||
)),
|
||||
new DropdownField('TemplateID', 'Use template:', $templateArray)//,
|
||||
new DropdownField('TemplateID', 'Copy structure from:', $templateArray)//,
|
||||
/*new TextField('AdminName', 'Admin name:'),
|
||||
new EmailField('AdminEmail', 'Admin email:')*/
|
||||
),
|
||||
|
@ -1,9 +1,9 @@
|
||||
<div id="LeftPane">
|
||||
<h2>Create Intranet</h2>
|
||||
<h2>Create Sub-site</h2>
|
||||
<div id="AddIntranetForm_holder" style="overflow:auto">
|
||||
$AddSubsiteForm
|
||||
</div>
|
||||
<h2>Search for Intranets</h2>
|
||||
<h2>Search for Sub-sites</h2>
|
||||
<div id="Search_holder" style="overflow: auto;">
|
||||
<div id="SearchForm_holder" style="overflow:auto">
|
||||
$SearchForm
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?
|
||||
<?php
|
||||
|
||||
class SubsiteAdminTest extends SapphireTest {
|
||||
static $fixture_file = 'subsites/tests/SubsiteTest.yml';
|
||||
@ -99,7 +99,7 @@ class SubsiteAdminTest extends SapphireTest {
|
||||
*/
|
||||
function testMainsiteAdminCanAccessAllSubsites() {
|
||||
$member = $this->objFromFixture('Member', 'admin');
|
||||
$member->logIn();
|
||||
Session::set("loggedInAs", $member->ID);
|
||||
|
||||
$cmsMain = new CMSMain();
|
||||
foreach($cmsMain->Subsites() as $subsite) {
|
||||
|
@ -43,7 +43,7 @@ class SubsiteTest extends SapphireTest {
|
||||
$this->assertEquals($siteHome->MasterPageID, $tmplHome->ID);
|
||||
|
||||
// Check linking of child pages
|
||||
$tmplStaff = $this->objFromFixture('Page','staff');
|
||||
$tmplStaff = $this->objFromFixture('SiteTree','staff');
|
||||
$siteStaff = DataObject::get_one('SiteTree', "URLSegment = '" . Convert::raw2sql($tmplStaff->URLSegment) . "'");
|
||||
$this->assertEquals($siteStaff->MasterPageID, $tmplStaff->ID);
|
||||
|
||||
@ -77,33 +77,37 @@ class SubsiteTest extends SapphireTest {
|
||||
$admin = $this->objFromFixture('Member', 'admin');
|
||||
$subsite1member = $this->objFromFixture('Member', 'subsite1member');
|
||||
$subsite2member = $this->objFromFixture('Member', 'subsite2member');
|
||||
$mainpage = $this->objFromFixture('Page', 'home');
|
||||
$subsite1page = $this->objFromFixture('Page', 'subsite1_home');
|
||||
$subsite2page = $this->objFromFixture('Page', 'subsite2_home');
|
||||
$mainpage = $this->objFromFixture('SiteTree', 'home');
|
||||
$subsite1page = $this->objFromFixture('SiteTree', 'subsite1_home');
|
||||
$subsite2page = $this->objFromFixture('SiteTree', 'subsite2_home');
|
||||
$subsite1 = $this->objFromFixture('Subsite_Template', 'subsite1');
|
||||
$subsite2 = $this->objFromFixture('Subsite_Template', 'subsite2');
|
||||
|
||||
Session::set("loggedInAs", $admin->ID);
|
||||
$this->assertTrue(
|
||||
$subsite1page->canEdit($admin),
|
||||
(bool)$subsite1page->canEdit(),
|
||||
'Administrators can edit all subsites'
|
||||
);
|
||||
|
||||
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
|
||||
Subsite::changeSubsite($subsite1);
|
||||
|
||||
Session::set("loggedInAs", $subsite1member->ID);
|
||||
$this->assertTrue(
|
||||
$subsite1page->canEdit($subsite1member),
|
||||
(bool)$subsite1page->canEdit(),
|
||||
'Members can edit pages on a subsite if they are in a group belonging to this subsite'
|
||||
);
|
||||
|
||||
Session::set("loggedInAs", $subsite2member->ID);
|
||||
$this->assertFalse(
|
||||
$subsite1page->canEdit($subsite2member),
|
||||
(bool)$subsite1page->canEdit(),
|
||||
'Members cant edit pages on a subsite if they are not in a group belonging to this subsite'
|
||||
);
|
||||
|
||||
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
|
||||
Subsite::changeSubsite($subsite2);
|
||||
$this->assertFalse(
|
||||
$mainpage->canEdit($subsite2member),
|
||||
$mainpage->canEdit(),
|
||||
'Members cant edit pages on the main site if they are not in a group allowing this'
|
||||
);
|
||||
|
||||
|
@ -8,7 +8,7 @@ Subsite_Template:
|
||||
subsite2:
|
||||
Title: Subsite2 Template
|
||||
Subdomain: subsite2
|
||||
Page:
|
||||
SiteTree:
|
||||
home:
|
||||
Title: Home
|
||||
SubsiteID: =>Subsite_Template.main
|
||||
@ -17,7 +17,7 @@ Page:
|
||||
SubsiteID: =>Subsite_Template.main
|
||||
staff:
|
||||
Title: Staff
|
||||
ParentID: =>Page.about
|
||||
ParentID: =>SiteTree.about
|
||||
SubsiteID: =>Subsite_Template.main
|
||||
contact:
|
||||
Title: Contact Us
|
||||
@ -34,28 +34,28 @@ Page:
|
||||
subsite2_contactus:
|
||||
Title: Contact Us (Subsite 2)
|
||||
SubsiteID: =>Subsite_Template.subsite2
|
||||
Permission:
|
||||
admin:
|
||||
Code: ADMIN
|
||||
accesscmsmain1:
|
||||
Code: CMS_ACCESS_CMSMain
|
||||
accesscmsmain2:
|
||||
Code: CMS_ACCESS_CMSMain
|
||||
Group:
|
||||
admin:
|
||||
Title: Admin
|
||||
Code: admin
|
||||
Permissions: =>Permission.admin
|
||||
subsite1_group:
|
||||
Title: subsite1_group
|
||||
Code: subsite1_group
|
||||
Subsite: =>Subsite_Template.subsite1
|
||||
Permissions: =>Permission.accesscmsmain1
|
||||
SubsiteID: =>Subsite_Template.subsite1
|
||||
subsite2_group:
|
||||
Title: subsite2_group
|
||||
Code: subsite2_group
|
||||
Subsite: =>Subsite_Template.subsite2
|
||||
Permissions: =>Permission.accesscmsmain2
|
||||
SubsiteID: =>Subsite_Template.subsite2
|
||||
Permission:
|
||||
admin:
|
||||
Code: ADMIN
|
||||
GroupID: =>Group.admin
|
||||
accesscmsmain1:
|
||||
Code: CMS_ACCESS_CMSMain
|
||||
GroupID: =>Group.subsite1_group
|
||||
accesscmsmain2:
|
||||
Code: CMS_ACCESS_CMSMain
|
||||
GroupID: =>Group.subsite2_group
|
||||
Member:
|
||||
admin:
|
||||
FirstName: Admin
|
||||
|
Loading…
Reference in New Issue
Block a user