You are here

function _administerusersbyrole_can_edit_user in Administer Users by Role 5

Same name and namespace in other branches
  1. 6 administerusersbyrole.module \_administerusersbyrole_can_edit_user()
  2. 7 administerusersbyrole.module \_administerusersbyrole_can_edit_user()
2 calls to _administerusersbyrole_can_edit_user()
administerusersbyrole_menu in ./administerusersbyrole.module
administerusersbyrole_user in ./administerusersbyrole.module

File

./administerusersbyrole.module, line 56
Allows users with 'administer users' permission and a role (specified in 'Access control') to edit/delete other users with a specified role. If the user being edited has multiple roles, the user doing the editing must have…

Code

function _administerusersbyrole_can_edit_user($account) {
  global $user;
  if ($account->uid == $user->uid) {
    return TRUE;
  }

  // allow only uid1 to edit uid1
  if ($account->uid == 1) {
    return FALSE;
  }
  foreach ($account->roles as $rid => $role) {
    if ($rid === DRUPAL_AUTHENTICATED_RID) {
      continue;
    }
    if (!user_access('edit users with role ' . $role)) {
      return FALSE;
    }
  }
  return TRUE;
}