mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 09:05:55 +00:00
BUGFIX: admin user can now access subsite zero (main site) without the LeftAndMain access check reverting them back to a previous subsite (includes test for this edge-case).
This commit is contained in:
parent
55214b3e24
commit
a7935bc3e3
@ -123,10 +123,18 @@ class LeftAndMainSubsites extends Extension {
|
||||
}
|
||||
}
|
||||
|
||||
// Switch to a subsite that this user can actually access.
|
||||
$member = Member::currentUser();
|
||||
if ($member && $member->isAdmin()) return true; //admin can access all subsites
|
||||
|
||||
// Switch to a subsite that this user can actually access.
|
||||
$sites = Subsite::accessible_sites("CMS_ACCESS_{$this->owner->class}")->toDropdownMap();
|
||||
if($sites && !isset($sites[Subsite::currentSubsiteID()])) {
|
||||
//SS_Backtrace::backtrace();
|
||||
Debug::Show(Subsite::currentSubsiteID());
|
||||
|
||||
$siteIDs = array_keys($sites);
|
||||
Debug::Show($siteIDs[0]);
|
||||
Subsite::changeSubsite($siteIDs[0]);
|
||||
return true;
|
||||
}
|
||||
|
30
tests/LeftAndMainSubsitesTest.php
Normal file
30
tests/LeftAndMainSubsitesTest.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
class LeftAndMainSubsitesTest extends FunctionalTest {
|
||||
|
||||
static $fixture_file = 'subsites/tests/SubsiteTest.yml';
|
||||
|
||||
function testAlternateAccessCheck() {
|
||||
$admin = $this->objFromFixture("Member","admin");
|
||||
$this->loginAs($admin);
|
||||
$ids = array();
|
||||
|
||||
$subsite1 = $this->objFromFixture('Subsite', 'domaintest1');
|
||||
$subsite2 = $this->objFromFixture('Subsite', 'domaintest2');
|
||||
$subsite3 = $this->objFromFixture('Subsite', 'domaintest3');
|
||||
|
||||
$ids[] = $subsite1->ID;
|
||||
$ids[] = $subsite2->ID;
|
||||
$ids[] = $subsite3->ID;
|
||||
$ids[] = 0;
|
||||
|
||||
foreach($ids as $id) {
|
||||
Subsite::changeSubsite($id); //switch to main site (subsite ID zero)
|
||||
$left = new LeftAndMain();
|
||||
$this->assertTrue($left->canView(), "Admin user can view subsites LeftAndMain with id = '$id'");
|
||||
$this->assertEquals($id, Subsite::currentSubsiteID(), "The current subsite has not been changed in the process of checking permissions for admin user.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user