mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-09-30 05:09:15 +02:00
Merge pull request #249 from open-sausages/pulls/fix-xhr-canaccess
BUG Prevent SubsiteXHRController failing if there are no subsites available
This commit is contained in:
commit
f7bab259b7
@ -22,13 +22,15 @@ class SubsiteXHRController extends LeftAndMain
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Similar as above, but for the LeftAndMainSubsites - allow access if user allowed into the CMS at all.
|
* Allow access if user allowed into the CMS at all.
|
||||||
*/
|
*/
|
||||||
public function canAccess()
|
public function canAccess()
|
||||||
{
|
{
|
||||||
if (Subsite::all_accessible_sites()->count()>0) {
|
// Allow if any cms access is available
|
||||||
return true;
|
return Permission::check(array(
|
||||||
}
|
'CMS_ACCESS', // Supported by 3.1.14 and up
|
||||||
|
'CMS_ACCESS_LeftAndMain'
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getResponseNegotiator()
|
public function getResponseNegotiator()
|
||||||
|
44
tests/SubsiteXHRControllerTest.php
Normal file
44
tests/SubsiteXHRControllerTest.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: dmooyman
|
||||||
|
* Date: 27/05/16
|
||||||
|
* Time: 3:10 PM
|
||||||
|
*/
|
||||||
|
class SubsiteXHRControllerTest extends FunctionalTest
|
||||||
|
{
|
||||||
|
protected static $fixture_file = 'SubsiteTest.yml';
|
||||||
|
|
||||||
|
public function testCanView() {
|
||||||
|
// Test unauthenticated access
|
||||||
|
Session::clear('MemberID');
|
||||||
|
$result = $this->get('SubsiteXHRController', null, array(
|
||||||
|
'X-Pjax' => 'SubsiteList',
|
||||||
|
'X-Requested-With' => 'XMLHttpRequest'
|
||||||
|
));
|
||||||
|
$this->assertEquals(403, $result->getStatusCode());
|
||||||
|
|
||||||
|
// Login with NO permissions
|
||||||
|
$this->logInWithPermission('NOT_CMS_PERMISSION');
|
||||||
|
$result = $this->get('SubsiteXHRController', null, array(
|
||||||
|
'X-Pjax' => 'SubsiteList',
|
||||||
|
'X-Requested-With' => 'XMLHttpRequest'
|
||||||
|
));
|
||||||
|
$this->assertEquals(403, $result->getStatusCode());
|
||||||
|
|
||||||
|
// Test cms user
|
||||||
|
$this->logInWithPermission('CMS_ACCESS_CMSMain');
|
||||||
|
$result = $this->get('SubsiteXHRController', null, array(
|
||||||
|
'X-Pjax' => 'SubsiteList',
|
||||||
|
'X-Requested-With' => 'XMLHttpRequest'
|
||||||
|
));
|
||||||
|
$this->assertEquals(200, $result->getStatusCode());
|
||||||
|
$this->assertEquals('text/json', $result->getHeader('Content-Type'));
|
||||||
|
$body = $result->getBody();
|
||||||
|
$this->assertContains('Main site', $body);
|
||||||
|
$this->assertContains('Test 1', $body);
|
||||||
|
$this->assertContains('Test 2', $body);
|
||||||
|
$this->assertContains('Test 3', $body);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user