Merge branch '2.0' into 2.1

This commit is contained in:
Robbie Averill 2019-06-25 15:43:59 +12:00
commit 9655371276
3 changed files with 27 additions and 9 deletions

View File

@ -17,13 +17,13 @@ env:
matrix: matrix:
include: include:
- php: 5.6 - 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 - 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 - 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 - 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 - php: 7.2
env: DB=MYSQL INSTALLER_VERSION=4.x-dev BEHAT_TEST=1 env: DB=MYSQL INSTALLER_VERSION=4.x-dev BEHAT_TEST=1
@ -39,7 +39,7 @@ before_script:
# Install composer # Install composer
- composer validate - composer validate
- composer require silverstripe/installer:"$INSTALLER_VERSION" silverstripe/recipe-testing:^1 --no-update - 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 - composer install --prefer-source --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
# Behat bootstrapping # Behat bootstrapping

View File

@ -215,11 +215,16 @@ class LeftAndMainSubsites extends LeftAndMainExtension
/** /**
* Check if the current controller is accessible for this user on this subsite. * 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. // Admin can access everything, no point in checking.
$member = Security::getCurrentUser();
if ($member if ($member
&& (Permission::checkMember($member, 'ADMIN') // 'Full administrative rights' && (Permission::checkMember($member, 'ADMIN') // 'Full administrative rights'
|| Permission::checkMember($member, 'CMS_ACCESS_LeftAndMain') // 'Access to all CMS sections' || 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, * Prevent accessing disallowed resources. This happens after onBeforeInit has executed,
* so all redirections should've already taken place. * 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);
} }
/** /**

View File

@ -9,6 +9,7 @@ use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\Subsites\Extensions\LeftAndMainSubsites;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\State\SubsiteState; use SilverStripe\Subsites\State\SubsiteState;
@ -100,4 +101,14 @@ class LeftAndMainSubsitesTest extends FunctionalTest
$this->assertTrue($l->shouldChangeSubsite(CMSPageEditController::class, 1, 5)); $this->assertTrue($l->shouldChangeSubsite(CMSPageEditController::class, 1, 5));
$this->assertFalse($l->shouldChangeSubsite(CMSPageEditController::class, 1, 1)); $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));
}
} }