Jump to content

Getting user permissions to use as selector value in $page->find()


felic
 Share

Recommended Posts

Hi,

probably a stupid simply task but this is my debut dealing with user/roles/permissions stuff within the frontend.

Scenario:

I have some (frontend) users tied to applied user roles (with appropriate permissions). These users have limited access (by those user roles/permissions) to the frontend views (provided by a custom frontend login form).

Now there is a simple message list with several message items. Every page for single items comprises a field with a checkbox group (build as pages, s. https://processwire.com/talk/topic/313-checkbox-group-for-field/) which enables to assign any combination of user roles to a single item.

Setting values by hand within the frontend template works smart:

// Notice: "wpi1" e.g is the name of one checkbox page
// Find every page (checkbox) with given properties
$res = $pages->find("parent=/tools/partners/, name=wpi1"); // or "name="wpi1|wpi2|..."

// Notice: Spares other selectors for this example
$items = $pages->find("partner_membership=$res");

// Iterate and show the list(items)
foreach($items as $item) {
...
}

But of course i'd rather set these values from the properties of the logged in user. And this is where i stalled.

if($user->isLoggedin()) {

1a.
// collect user roles for this user?
$current_user_roles = $user->roles;

or

1.b
// getting $user permissions directly?
$current_user_permissions = $permissions->find("user=$user");

}
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...