I host multi-sites. I would like to keep the super admin (uid=1) to myself, and create some regular admins for each site. Regular admin would have pretty much all the rights with a few exceptions (php filter, module control etc). One important permission is the "administer permissions". If I grant regular admin "administer permissions", then he/she can grant everything to him/her self. This is what I consider an all-or-nothing permission.
I believe a simple scheme that can fundamentally improve the permission control: the system can implement a simple rule such that a user (regular admin) can change (grant or remove) a permission (e.g. “administer filters”) only if he/she has that permission (“administer filters”) in the first place.
Coupled with this patch http://drupal.org/node/39636 (hide uid=1 from other users), this rule effectively creates a permission "chain" or hierarchy that allows "administer permissions" to be granted to regular admin without worrying about the all-or-nothing effect.
I believe some minor changes in user.admin.inc that can make it work. However, the changes disabled all the check boxes. Can some expert take a look, and tell me what I am missing here? I'd also like to here if my idea is in the right direction.
Thanks in advance!
function user_admin_perm($form_state, $rid = NULL) {
...
foreach ($role_names as $rid => $name) {
// Builds arrays for checked boxes for each role
if (strpos($role_permissions[$rid], $perm .',') !== FALSE) {
$status[$rid][] = $perm;
}
// a user can only change this permission if he has this permission in the first place
if (user_access($perm)) {
$disabled[$rid][] = FALSE;
}
else {
$disabled[$rid][] = TRUE;
}
}
}
}
}
// Have to build checkboxes here after checkbox arrays are built
foreach ($role_names as $rid => $name) {
//disable the checkbox if current user doesn't have this permission
$form['checkboxes'][$rid] = array('#disabled'=>$disabled[$rid], '#type' => 'checkboxes', '#options' => $options, '#default_value' => isset($status[$rid]) ? $status[$rid] : array());
$form['role_names'][$rid] = array('#value' => $name, '#tree' => TRUE);
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Save permissions'));
This is only for presenting the form, on the form submit, similar checks can put in place to enforce the rule.
Comments
Comment #1
newbuntu commentedI found my problem. The actual solution is quite simple. It's in theme_user_admin_perm()
I believe this is a simple change with fundamental impact on drupal permission control.
I know there can be more elaborate improvement with this idea. For example, this scheme does allow a user to shoot himself on his foot, because he can remove a permission from himself. Then he won't be able to get it back for himself.
I would like to recommend this as core feature change.
Comment #2
gaele commentedHi newbuntu,
Features like this either should go into a contributed module, or into the development version of Drupal. If you want other people to take a look at your code please supply a patch for Drupal 7.
Comment #3
sun.core commentedComment #4
jhedstromFeature -> 8.1.
There are a variety of ways to do this in contrib, marking postponed for now.
Comment #7
dpiThis sounds nightmarish
Issue summary has not considered how to determine what roles you are allowed to modify.
This kind of complexity belongs in contrib.