diff --git a/code/Subsite.php b/code/Subsite.php index c42cc6f..88bed05 100644 --- a/code/Subsite.php +++ b/code/Subsite.php @@ -408,7 +408,7 @@ JS; * @param $includeMainSite If true, the main site will be included if appropriate. * @param $mainSiteTitle The label to give to the main site */ - function accessible_sites($permCode, $includeMainSite = false, $mainSiteTitle = "Main site", $member = null) { + function accessible_sites($permCode, $includeMainSite = true, $mainSiteTitle = "Main site", $member = null) { // Rationalise member arguments if(!$member) $member = Member::currentUser(); if(!$member) return new DataObjectSet(); diff --git a/tests/SubsiteAdminFunctionalTest.php b/tests/SubsiteAdminFunctionalTest.php new file mode 100644 index 0000000..1568f51 --- /dev/null +++ b/tests/SubsiteAdminFunctionalTest.php @@ -0,0 +1,43 @@ +objFromFixture('Member', 'admin'); + Session::set("loggedInAs", $member->ID); + + $this->get('admin/changesubsite?SubsiteID=0&ajax=1'); + $this->get('admin'); + $this->assertEquals(Subsite::currentSubsiteID(), '0', 'Can access main site'); + + $mainSubsite = $this->objFromFixture('Subsite_Template', 'main'); + $this->get("admin/changesubsite?SubsiteID={$mainSubsite->ID}&ajax=1"); + $this->get('admin'); + $this->assertEquals(Subsite::currentSubsiteID(), $mainSubsite->ID, 'Can access the subsite'); + } + + /** + * User which has AccessAllSubsites set to 1 should be able to access all subsites and main site, + * even though he does not have the ADMIN permission. + */ + function testEditorCanAccessAllSubsites() { + $member = $this->objFromFixture('Member', 'editor'); + Session::set("loggedInAs", $member->ID); + + $this->get('admin/changesubsite?SubsiteID=0&ajax=1'); + $this->get('admin'); + $this->assertEquals(Subsite::currentSubsiteID(), '0', 'Can access main site'); + + $mainSubsite = $this->objFromFixture('Subsite_Template', 'main'); + $this->get("admin/changesubsite?SubsiteID={$mainSubsite->ID}&ajax=1"); + $this->get('admin'); + $this->assertEquals(Subsite::currentSubsiteID(), $mainSubsite->ID, 'Can access the subsite'); + } +} diff --git a/tests/SubsiteAdminTest.php b/tests/SubsiteAdminTest.php index 2988540..b2f344e 100644 --- a/tests/SubsiteAdminTest.php +++ b/tests/SubsiteAdminTest.php @@ -112,4 +112,4 @@ class SubsiteAdminTest extends SapphireTest { } -?> \ No newline at end of file +?> diff --git a/tests/SubsiteTest.yml b/tests/SubsiteTest.yml index a82ef75..6caed8c 100644 --- a/tests/SubsiteTest.yml +++ b/tests/SubsiteTest.yml @@ -39,6 +39,9 @@ SubsiteDomain: IsPrimary: 1 SiteTree: + mainSubsitePage: + Title: MainSubsitePage + SubsiteID: 0 home: Title: Home SubsiteID: =>Subsite_Template.main @@ -77,6 +80,10 @@ Group: Title: Admin Code: admin AccessAllSubsites: 1 + editor: + Title: Editor + Code: editor + AccessAllSubsites: 1 subsite1_group: Title: subsite1_group Code: subsite1_group @@ -91,6 +98,15 @@ Permission: admin: Code: ADMIN GroupID: =>Group.admin + editor1: + Code: CMS_ACCESS_CMSMain + GroupID: =>Group.editor + editor2: + Code: SITETREE_VIEW_ALL + GroupID: =>Group.editor + editor3: + Code: VIEW_DRAFT_CONTENT + GroupID: =>Group.editor accesscmsmain1: Code: CMS_ACCESS_CMSMain GroupID: =>Group.subsite1_group @@ -111,9 +127,15 @@ Member: Email: admin@test.com Password: rangi Groups: =>Group.admin + editor: + FirstName: Editor + Surname: User + Email: editor@test.com + Password: rangi + Groups: =>Group.editor subsite1member: Email: subsite1member@test.com Groups: =>Group.subsite1_group subsite2member: Email: subsite2member@test.com - Groups: =>Group.subsite2_group \ No newline at end of file + Groups: =>Group.subsite2_group