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.

General Questions

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

Child inherit Parent edit permissions


Reply

7 Posts   1294 Views

Avatar
Twenty3design

25 February 2009 at 2:34am Community Member, 7 Posts

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

25 February 2009 at 5:05am (Last edited: 25 February 2009 5:07am), Community Member, 598 Posts

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

25 February 2009 at 5:14am Community Member, 7 Posts

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

25 February 2009 at 5:16am Community Member, 598 Posts

Your welcome :)

Avatar
headless_pnub

25 February 2009 at 12:31pm Community Member, 17 Posts

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

25 February 2009 at 12:37pm (Last edited: 25 February 2009 12:37pm), Community Member, 598 Posts

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

25 February 2009 at 1:10pm Community Member, 17 Posts

Of course!

Brilliant, thanks.