Merge pull request #2363 from open-sausages/pulls/4/CanOrganiseSitetree-clean-up

MINOR Clean up CMSMain::CanOrganiseSitetree
This commit is contained in:
Robbie Averill 2019-01-11 12:37:09 +01:00 committed by GitHub
commit 097d221150
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 2 deletions

View File

@ -756,7 +756,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
if (!SecurityToken::inst()->checkRequest($request)) { if (!SecurityToken::inst()->checkRequest($request)) {
return $this->httpError(400); return $this->httpError(400);
} }
if (!Permission::check('SITETREE_REORGANISE') && !Permission::check('ADMIN')) { if (!$this->CanOrganiseSitetree()) {
return $this->httpError( return $this->httpError(
403, 403,
_t( _t(
@ -862,11 +862,16 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
->setBody(json_encode($statusUpdates)); ->setBody(json_encode($statusUpdates));
} }
/**
* Whether the current member has the permission to reorganise SiteTree objects.
* @return bool
*/
public function CanOrganiseSitetree() public function CanOrganiseSitetree()
{ {
return !Permission::check('SITETREE_REORGANISE') && !Permission::check('ADMIN') ? false : true; return Permission::check('SITETREE_REORGANISE');
} }
/** /**
* @return boolean * @return boolean
*/ */

View File

@ -660,4 +660,22 @@ class CMSMainTest extends FunctionalTest
$searchSchema $searchSchema
); );
} }
public function testCanOrganiseSitetree()
{
$cms = CMSMain::create();
$this->assertFalse($cms->CanOrganiseSitetree());
$this->logInWithPermission('CMS_ACCESS_CMSMain');
$this->assertFalse($cms->CanOrganiseSitetree());
$this->logOut();
$this->logInWithPermission('SITETREE_REORGANISE');
$this->assertTrue($cms->CanOrganiseSitetree());
$this->logOut();
$this->logInWithPermission('ADMIN');
$this->assertTrue($cms->CanOrganiseSitetree());
}
} }