Jump to:

22984 Posts in 11765 Topics by 2827 members

General Questions

SilverStripe Forums » General Questions » How to prevent user from creating top level pages?

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

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

Page: 1 2
Go to End
Author Topic: 2290 Views
  • Victor
    Avatar
    Community Member
    128 Posts

    How to prevent user from creating top level pages? Link to this post

    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

  • CodeGuerrilla
    Avatar
    Community Member
    105 Posts

    Re: How to prevent user from creating top level pages? Link to this post

    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.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: How to prevent user from creating top level pages? Link to this post

    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.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: How to prevent user from creating top level pages? Link to this post

    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.

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: How to prevent user from creating top level pages? Link to this post

    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!

  • matthewwhyte
    Avatar
    Community Member
    1 Post

    Re: How to prevent user from creating top level pages? Link to this post

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

  • timwjohn
    Avatar
    Community Member
    98 Posts

    Re: How to prevent user from creating top level pages? Link to this post

    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.

  • Victor
    Avatar
    Community Member
    128 Posts

    Re: How to prevent user from creating top level pages? Link to this post

    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

    2290 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.