PWaddict Posted November 7, 2018 Share Posted November 7, 2018 Here is what I want to do: if ($page->my_checkbox) { //Remove permission "my-permission" from role "client" //Remove permission "page-add" from template "my-template" from role "client" } else { //Add permission "my-permission" on role "client" //Add permission "page-add" on template "my-template" on role "client" } I would really appreciate your help. Link to comment Share on other sites More sharing options...
Zeka Posted November 7, 2018 Share Posted November 7, 2018 @PWaddict https://processwire.com/api/ref/role/ 1 Link to comment Share on other sites More sharing options...
PWaddict Posted November 7, 2018 Author Share Posted November 7, 2018 Here is the first part for simply removing/adding a permission from specific role: $client = $roles->get('client'); if ($page->my_checkbox) { if ($client->hasPermission('my-permission')) { $client->of(false); $client->removePermission('my-permission'); $client->save(); } } else { if (!$client->hasPermission('my-permission')) { $client->of(false); $client->addPermission('my-permission'); $client->save(); } } @Zeka What I don't understand is how to remove permission "page-add" from template "my-template" from role "client". 1 Link to comment Share on other sites More sharing options...
PWaddict Posted November 7, 2018 Author Share Posted November 7, 2018 I solved it ? $client = $roles->get('client'); $s_template = $templates->get("my-template"); if ($page->my_checkbox) { if ($client->hasPermission('my-permission')) { $client->of(false); $client->removePermission('my-permission'); $client->save(); $s_template->revokePermissionByRole("page-add", $client); $s_template->save(); } } else { if (!$client->hasPermission('my-permission')) { $client->of(false); $client->addPermission('my-permission'); $client->save(); $s_template->addPermissionByRole("page-add", $client); $s_template->save(); } } 2 Link to comment Share on other sites More sharing options...
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