mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
ENHANCEMENT Redirecting to cms preview in ContentController if user is logged in
This commit is contained in:
parent
1ad4bd6dfd
commit
75ce441348
@ -120,6 +120,12 @@ class ContentController extends Controller {
|
||||
return Security::permissionFailure($this, sprintf($message, Controller::join_links($link, "?stage=Live")));
|
||||
}
|
||||
}
|
||||
|
||||
// Redirect to admin UI if user is logged in
|
||||
if($this->URLSegment != 'Security' && Permission::check('CMS_ACCESS_CMSMain') && !$this->request->getVar('cms-preview-disabled')) {
|
||||
$cmsController = singleton('CMSPageEditController');
|
||||
return Director::redirect(Controller::join_links($cmsController->Link('show'), $this->dataRecord->ID, '?cms-preview-expanded=1'));
|
||||
}
|
||||
|
||||
// Use theme from the site config
|
||||
if(($config = SiteConfig::current_site_config()) && $config->Theme) {
|
||||
|
@ -16,19 +16,22 @@ class ContentControllerPermissionTest extends FunctionalTest {
|
||||
$page->publish('Stage', 'Live');
|
||||
|
||||
$response = $this->get('/testpage');
|
||||
$this->assertEquals($response->getStatusCode(), 200);
|
||||
$this->assertEquals($response->getStatusCode(), 200, 'Doesnt require login for implicit live stage');
|
||||
|
||||
$response = $this->get('/testpage/?stage=Live');
|
||||
$this->assertEquals($response->getStatusCode(), 200);
|
||||
$this->assertEquals($response->getStatusCode(), 200, 'Doesnt require login for explicit live stage');
|
||||
|
||||
$response = $this->get('/testpage/?stage=Stage');
|
||||
// should redirect to login
|
||||
$this->assertEquals($response->getStatusCode(), 302);
|
||||
$this->assertEquals($response->getStatusCode(), 302, 'Redirects to login page when not logged in for draft stage');
|
||||
$this->assertContains('Security/login', $response->getHeader('Location'));
|
||||
|
||||
$this->logInWithPermission('CMS_ACCESS_CMSMain');
|
||||
|
||||
$response = $this->get('/testpage/?stage=Stage');
|
||||
$this->assertEquals($response->getStatusCode(), 200);
|
||||
$this->assertEquals($response->getStatusCode(), 302, 'Redirects to page view in CMS when logged in for draft stage');
|
||||
$this->assertNotContains('Security/login', $response->getHeader('Location'));
|
||||
$this->assertContains('admin/page/edit/show/' . $page->ID, $response->getHeader('Location'));
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,6 +54,7 @@ class SiteTreePermissionsTest extends FunctionalTest {
|
||||
// should be prompted for a login
|
||||
$response = $this->get($page->URLSegment . '?stage=Stage');
|
||||
$this->assertEquals($response->getStatusCode(), '302');
|
||||
$this->assertContains('Security/login', $response->getHeader('Location'));
|
||||
|
||||
$this->logInWithPermission('ADMIN');
|
||||
|
||||
@ -61,7 +62,9 @@ class SiteTreePermissionsTest extends FunctionalTest {
|
||||
$this->assertEquals($response->getStatusCode(), '404');
|
||||
|
||||
$response = $this->get($page->URLSegment . '?stage=Stage');
|
||||
$this->assertEquals($response->getStatusCode(), '200');
|
||||
$this->assertEquals($response->getStatusCode(), '302');
|
||||
$this->assertNotContains('Security/login', $response->getHeader('Location'));
|
||||
$this->assertContains('admin/page/edit/show/' . $page->ID, $response->getHeader('Location'));
|
||||
|
||||
$response = $this->get($page->URLSegment . '?stage=');
|
||||
$this->assertEquals($response->getStatusCode(), '404');
|
||||
@ -330,9 +333,10 @@ class SiteTreePermissionsTest extends FunctionalTest {
|
||||
$response = $this->get($childPage->RelativeLink());
|
||||
$this->assertEquals(
|
||||
$response->getStatusCode(),
|
||||
200,
|
||||
302,
|
||||
'Authenticated members can view a page marked as "Viewable by these groups" if theyre in the listed groups by inherited permission'
|
||||
);
|
||||
$this->assertContains('admin/page/edit/show/' . $childPage->ID, $response->getHeader('Location'));
|
||||
$this->session()->inst_set('loggedInAs', null);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user