0

I am trying to block a user from accessing certain content/blocks if they do not have permission to view content of a certain type within a group.

I have the user ID and the group ID, but how do I check the user's permissions for that group? I can't find any documentation.

To start, how would I print all the permissions for a given user and group?

2 Answers 2

0

Assuming that $gid contains the group ID and $uid contains the user ID, you can get the list of the permission names that user has on the group using the following code.

$group = entity_object_load($gid, 'group');
$permissions = $group->userPermissions($uid);

$permissions will contain an array with all the permission names.

0

The Group class has a userHasPermission() method you can use. So something like this:

if ($group->userHasPermission($user->uid, 'some permission')) {
  // do something.
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.