hansv Posted June 1, 2019 Posted June 1, 2019 Hi I have a question about Access control In my template, I have a field 'relations' (= a page field) with e.g. board of directors, members, ... The board of directors may view a page, the members not. How can I manage in permissions / roles that only the board of directors can view the page? thx in advance
elabx Posted June 1, 2019 Posted June 1, 2019 I think, if you mean the actual pages selected, you have to check for the template permissions of the selectable pages. Field access will show/hide the actual field for different roles.
hansv Posted June 1, 2019 Author Posted June 1, 2019 I think, my question was not really clearly. In my template 'x', I have a field 'Relatie' (see screenshot). The field 'Relatie' is a Page reference field. Page 'y' may only be viewable by 'Raad van bestuur'. How can I make a permission / role for the value 'Raad van bestuur' of the field 'Relatie'?
elabx Posted June 3, 2019 Posted June 3, 2019 Ok, then again if I understand correctly you want to set permissions on a page using a Page Referece field (to select a role), being "y" the page being edited? Probably last think I don't understand is if you want to block the edit page or the frontend page (rendered with the template) If the case is blocking the edit page for a certain role, you could hook into the Page::editable() (haven't tested this code): wire()->addHookAfter('Page::editable', function($event) { if(!$event->return) return; // already determined user has no access if(wire('user')->isSuperuser()) return; // superuser always allowed $page = $event->object; if($page->template == "y_page_template") if($page->relatie->has($this->user->roles)){ $event->return = true; } else{ $event->return = false; } } }); Here I am assuming Relatie field actually selects roles in ProcessWire, since those are pages too. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now