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

Child inherit Parent edit permissions


Go to End


7 Posts   2159 Views

Avatar
Twenty3design

Community Member, 7 Posts

25 February 2009 at 2:34am

Hello,

Is it possible to set all children to automatically use their parents user permissions. I don't want the users to have to set the permissions every time they create a page or news item.

Thanks in advance.
Liam

Avatar
Carbon Crayon

Community Member, 598 Posts

25 February 2009 at 5:05am

Edited: 25/02/2009 5:07am

Hi Liam

In 2.3 there is an option on each page to inherit it's parents settings, which you can set to a default using the Defaults array.

In 2.2x you can do this using the OnBeforeWrite function in the Pages model class like so:

function onBeforeWrite() {
      //If the page already exists in the database, don't take parent permissions
      if (!$this->exists()) {
         if($parent = $this->Parent()) {
            if($parent->Viewers) $this->Viewers = $parent->Viewers;
            if($parent->Editors) $this->Editors = $parent->Editors;
            if($parent->ViewersGroup) $this->ViewersGroup = $parent->ViewersGroup;
            if($parent->EditorsGroup) $this->EditorsGroup = $parent->EditorsGroup;
         }
      }

      parent::onBeforeWrite();
   } 

Avatar
Twenty3design

Community Member, 7 Posts

25 February 2009 at 5:14am

Ahh, I'm using 2.2.3.
That's why I couldn't find the option!

Thanks for the code for 2.2x.
As always a great reply, thanks Aram.

Avatar
Carbon Crayon

Community Member, 598 Posts

25 February 2009 at 5:16am

Your welcome :)

Avatar
headless_pnub

Community Member, 17 Posts

25 February 2009 at 12:31pm

Do you need to call this function somehow or should it just run? I can't seem to get it to work.
Sorry for my noobness.

Avatar
Carbon Crayon

Community Member, 598 Posts

25 February 2009 at 12:37pm

Edited: 25/02/2009 12:37pm

The function gets run automatically before the page is saved/written.

if you want it to retake the permisions each time you save it then remove the first if() statement so that it will do it for existing pages, otherwise this will only work when creating a new page.

Avatar
headless_pnub

Community Member, 17 Posts

25 February 2009 at 1:10pm

Of course!

Brilliant, thanks.