From 4fdf2e24e328c714b571d47b5dfb5b64fc5c185b Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 24 Jun 2019 10:19:58 +1200 Subject: [PATCH 1/2] FIX LeftAndMainSubsites::canAccess() now accepts a Member argument and falls back to the session member --- src/Extensions/LeftAndMainSubsites.php | 15 +++++++++++---- tests/php/LeftAndMainSubsitesTest.php | 11 +++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Extensions/LeftAndMainSubsites.php b/src/Extensions/LeftAndMainSubsites.php index 760623f..ccebef6 100644 --- a/src/Extensions/LeftAndMainSubsites.php +++ b/src/Extensions/LeftAndMainSubsites.php @@ -215,11 +215,16 @@ class LeftAndMainSubsites extends LeftAndMainExtension /** * 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 @@ class LeftAndMainSubsites extends LeftAndMainExtension /** * 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 09df18f..ea60db5 100644 --- a/tests/php/LeftAndMainSubsitesTest.php +++ b/tests/php/LeftAndMainSubsitesTest.php @@ -9,6 +9,7 @@ use SilverStripe\CMS\Controllers\CMSPageEditController; 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 @@ class LeftAndMainSubsitesTest extends FunctionalTest $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)); + } } From 67d10ec0cb514c687c54d9c24194f5e45de7f65f Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 25 Jun 2019 15:43:50 +1200 Subject: [PATCH 2/2] Remove SilverStripe 4.0-4.2 from Travis builds --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7c1453e..506555b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,13 +17,13 @@ env: matrix: include: - php: 5.6 - env: DB=MYSQL INSTALLER_VERSION=4.0.x-dev PHPCS_TEST=1 PHPUNIT_TEST=1 + env: DB=MYSQL INSTALLER_VERSION=4.3.x-dev PHPCS_TEST=1 PHPUNIT_TEST=1 - php: 7.0 - env: DB=PGSQL INSTALLER_VERSION=4.1.x-dev PHPUNIT_TEST=1 + env: DB=PGSQL INSTALLER_VERSION=4.3.x-dev PHPUNIT_TEST=1 - php: 7.1 - env: DB=MYSQL INSTALLER_VERSION=4.1.x-dev BEHAT_TEST=1 + env: DB=MYSQL INSTALLER_VERSION=4.3.x-dev BEHAT_TEST=1 - php: 7.2 - env: DB=MYSQL INSTALLER_VERSION=4.2.x-dev PHPUNIT_COVERAGE_TEST=1 + env: DB=MYSQL INSTALLER_VERSION=4.3.x-dev PHPUNIT_COVERAGE_TEST=1 - php: 7.2 env: DB=MYSQL INSTALLER_VERSION=4.x-dev BEHAT_TEST=1 @@ -39,7 +39,7 @@ before_script: # Install composer - composer validate - composer require silverstripe/installer:"$INSTALLER_VERSION" silverstripe/recipe-testing:^1 --no-update - - if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.0.x-dev; fi + - if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.1.x-dev; fi - composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile # Behat bootstrapping