0

Our client frequently need to grant arbitrary permissions to arbitrary users. It's very boring and fault-prone for our client to create new roles, assign users to roles and then set role permissions.
The module user permissions can grant permissions directly to a user, but the grantee must have the powerful permission "administer permissions", which is not what I want.

1

Use the user permissions module. Contrary to your objections to using this module, it is not the grantee who needs the "administer permissions", but the grantor

-1

Create role:

if (!user_role_load_by_name('new_role')) {
  $role = new stdClass();
  $role->name = 'new_role';
  user_role_save($role);
}

Add Permissions:

$new_role = user_role_load_by_name('new_role');
$values[] = array(
  'rid' => $new_role->rid,
  'permission' => 'create article content',
  'module' => 'modulename'
);
$query = db_insert('role_permission')->fields(
  array(
    'rid',
    'permission',
    'module'
  ));
foreach ($values as $record) {
  $query->values($record);
}
$query->execute();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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