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
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
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
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();
}
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.
Your welcome :)
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.
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.
Of course!
Brilliant, thanks.