diff --git a/src/Extensions/LeftAndMainSubsites.php b/src/Extensions/LeftAndMainSubsites.php index 760623f5..ccebef68 100644 --- a/src/Extensions/LeftAndMainSubsites.php +++ b/src/Extensions/LeftAndMainSubsites.php @@ -215,11 +215,16 @@ public function shouldChangeSubsite($adminClass, $recordSubsiteID, $currentSubsi /** * Check if the current controller is accessible for this user on this subsite. + * + * @param Member $member */ - public function canAccess() + public function canAccess(Member $member = null) { + if (!$member) { + $member = Security::getCurrentUser(); + } + // Admin can access everything, no point in checking. - $member = Security::getCurrentUser(); if ($member && (Permission::checkMember($member, 'ADMIN') // 'Full administrative rights' || Permission::checkMember($member, 'CMS_ACCESS_LeftAndMain') // 'Access to all CMS sections' @@ -236,10 +241,12 @@ public function canAccess() /** * Prevent accessing disallowed resources. This happens after onBeforeInit has executed, * so all redirections should've already taken place. + * + * @param Member $member */ - public function alternateAccessCheck() + public function alternateAccessCheck(Member $member = null) { - return $this->owner->canAccess(); + return $this->owner->canAccess($member); } /** diff --git a/tests/php/LeftAndMainSubsitesTest.php b/tests/php/LeftAndMainSubsitesTest.php index 09df18f7..ea60db5a 100644 --- a/tests/php/LeftAndMainSubsitesTest.php +++ b/tests/php/LeftAndMainSubsitesTest.php @@ -9,6 +9,7 @@ use SilverStripe\Core\Config\Config; use SilverStripe\Dev\FunctionalTest; use SilverStripe\Security\Member; +use SilverStripe\Subsites\Extensions\LeftAndMainSubsites; use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\State\SubsiteState; @@ -100,4 +101,14 @@ public function testShouldChangeSubsite() $this->assertTrue($l->shouldChangeSubsite(CMSPageEditController::class, 1, 5)); $this->assertFalse($l->shouldChangeSubsite(CMSPageEditController::class, 1, 1)); } + + public function testCanAccessWithPassedMember() + { + $memberID = $this->logInWithPermission('ADMIN'); + $member = Member::get()->byID($memberID); + + /** @var LeftAndMain&LeftAndMainSubsites $leftAndMain */ + $leftAndMain = new LeftAndMain(); + $this->assertTrue($leftAndMain->canAccess($member)); + } }