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.
Add a comment
|
2 Answers
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
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();