Jump to content

Field access control


hansv
 Share

Recommended Posts

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

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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'?

Screen Shot 06-01-19 at 11.22 PM.PNG

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...