Permalink
Browse files

ENHANCEMENT Redirecting to cms preview in ContentController if user i…

…s logged in
  • Loading branch information...
1 parent 1ad4bd6 commit 75ce4413480ab79315c5cb8938042780b379f11c @chillu chillu committed May 19, 2011
@@ -120,6 +120,12 @@ public function init() {
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 @@ public function testCanViewStage() {
$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,14 +54,17 @@ function testAccessingStageWithBlankStage() {
// 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');
$response = $this->get($page->URLSegment . '?stage=Live');
$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 @@ function testRestrictedViewInheritance() {
$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);
}

0 comments on commit 75ce441

Please sign in to comment.