suntrop Posted February 22, 2015 Posted February 22, 2015 Hi all. I have pages (templates) that are only accessible to certain users. Now I need to get all users that have view access to specific pages (they will get email when page updates). I thought of something like this: $template = wire('templates')->get($p->template); $roles = $template->getRoles(); $users = wire('pages')->find('template=user, roles=' . $roles); But it looks like getRoles() doesn't returns the roles for that template. Roles is an empty PageArray. What is wrong or is there another way to get those users?
kongondo Posted February 22, 2015 Posted February 22, 2015 (edited) The following works for me. You first have to enable 'Do you want to manage view and edit access.....' in the Access tab when editing that template. //$t = $page->template;//if on this page $t = $templates->get("skyscraper"); //echo $t->name . '<br>';//confirm we are looking at the right template $tRoles = $t->getRoles(); foreach ($tRoles as $r) { echo $r->name . '<br>'; } getRoles() seem only to work if 'view pages' permission is enabled on that template for a role. Edited February 22, 2015 by kongondo 1
diogo Posted February 22, 2015 Posted February 22, 2015 You could also iterate all users instead: foreach($users as $u) { if ( $u->hasPermission('page-view', $page) ) // send email to $u->email } 2
suntrop Posted February 22, 2015 Author Posted February 22, 2015 Thanks. Problem was, I thought I could get inherited roles as well. Perhaps I forgot access was managed by the parent page/template. diogo's method works fine
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