Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Controller fails to redirect when viewed on stage(canViewStage: permissionFailure )


Go to End


2 Posts   1201 Views

Avatar
Praveen

Community Member, 49 Posts

17 April 2015 at 4:27pm

Edited: 19/05/2015 6:35pm

I have observed the problem when using redirect rules
Here is the redirect rules. It opens the page on live .(http://example.com/mypage/profile/)
On stage redirected to login page http://example.com/mypage/profile/?stage=Stage

Director::addRules(100, array(
    'mypage/profile//$Action/$ID' => 'ProfilePage_Controller',
    'mypage/profile//' => 'ProfilePage_Controller',
    'myprofile' => 'ProfilePage_Controller',
));

I traced the code where it gets Permission Failure

if(!$this->dataRecord->canViewStage(Versioned::current_archived_date() ? 'Stage' : Versioned::current_stage())) {
Line:122 cms/code/controllers/ContentController.php

Do I need to set permission to view on Stage?

Thanks
B L Praveen

Avatar
torleif2

Community Member, 6 Posts

29 June 2015 at 11:02am

Edited: 29/06/2015 11:04am

There's a few ways to get around this.

One is to add a ?stage=live to URL. Ugly but it will work.

Another is to bypass the ContentController init() function, this is handy if you have functions in your Page_Controller you want to leverage:

	/**
	 * Bypass the staging permission check
	 */
	public function init() {
		Controller::init();
	}

The last way, which I prefer (as outlined here: http://www.silverstripe.org/community/forums/general-questions/reply/66997) is to extend the Controller, instead of ContentController:

class Whatever_Controller extends Controller {

Edit: if you want to add a permission check, you can by putting this in the controller function (or in the init):

		if (!Permission::checkMember(Member::currentUser(), "CMS_ACCESS_whatever")) {
			header("HTTP/1.0 403 Forbidden");
			die('You do not have permission to use the live chat module');
		}