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

How to prevent user from creating top level pages?


Go to End


9 Posts   4866 Views

Avatar
Victor

Community Member, 128 Posts

8 December 2009 at 9:32am

What permissions should be granted to user to enable logging in and edit specific pages but to prevent him/her from creation of the top level pages?

It looks like Access to SiteContent allows creation of top level pages

Thank you

Victor

Avatar
CodeGuerrilla

Community Member, 105 Posts

14 January 2010 at 7:21pm

Don't think SilverStripe does this out of the box, you could do something with onBeforeWrite to check the members Group before allowing the write to the database.

Avatar
bummzack

Community Member, 904 Posts

14 January 2010 at 8:16pm

I think you should write a custom canCreate method for your Page Class. There you would check Page-Level and Usergroup and grant/deny accordingly.

Avatar
bummzack

Community Member, 904 Posts

14 January 2010 at 8:33pm

Sorry, disregard my previous post. The canCreate approach isn't going to work, unless you figure out a way to determine which Page is currently selected in the SiteTree (I would be interested to know this as well).
A thing that's going to work is overriding the canPublish method. This won't prevent the user from creating Pages, but you can make sure that he can never publish them at top level.

Avatar
timwjohn

Community Member, 98 Posts

4 March 2010 at 10:35pm

Would the onBeforeWrite method work to prevent users creating pages at all? I would rather limited users not be able to do this in the CMS rather than having a bunch of unwanted drafts they can never publish.

Please let me know. Thanks!

Avatar
matthewwhyte

Community Member, 1 Post

11 March 2010 at 9:34am

I'm having the same issue. Did anyone find a solution?

Avatar
timwjohn

Community Member, 98 Posts

11 March 2010 at 11:10pm

Well this is one solution I found, though I'm not proud of it and I'm sure there are better ways that I'm yet to discover.

With this method, you set up the root pages you need first, then once created add this line to your Page class:

static $can_be_root = false;

This then locks out the possibilty of creating any more pages in root. The only issue is that this is global i.e. for all users including admin.

To create more pages, you'd have to set it to true and probably need to do a /dev/build.

I'm gonna stick with this option for now, but am definitely open to a more flexible approach.

Avatar
Victor

Community Member, 128 Posts

12 March 2010 at 12:48am

Looking at 2.4 beta 1 with CMS workflow I see

Who can create pages in the root of the site?

with 2 radio buttons

* Anyone who can log-in to the CMS
* Only these people (choose from list)

So we decided just to wait until 2.4 release before extending list of people with access

Victor

Go to Top