You are here

function _administerusersbyrole_can_edit_user in Administer Users by Role 6

Same name and namespace in other branches
  1. 5 administerusersbyrole.module \_administerusersbyrole_can_edit_user()
  2. 7 administerusersbyrole.module \_administerusersbyrole_can_edit_user()
2 calls to _administerusersbyrole_can_edit_user()
administerusersbyrole_init in ./administerusersbyrole.module
Implements hook_init().
administerusersbyrole_user in ./administerusersbyrole.module
Implements hook_user().

File

./administerusersbyrole.module, line 67
Non-displayable characters.

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;
  }
  if ($account->roles === array(
    DRUPAL_AUTHENTICATED_RID => 'authenticated user',
  )) {
    if (!user_access('edit users with no custom roles')) {
      return FALSE;
    }
  }
  $allow = TRUE;
  foreach ($account->roles as $rid => $role) {
    if ($rid === DRUPAL_AUTHENTICATED_RID) {
      continue;
    }
    if (user_access(_administerusersbyrole_build_perm_string($role, 'edit', TRUE))) {
      return TRUE;
    }
    if (!user_access(_administerusersbyrole_build_perm_string($role, 'edit', FALSE))) {
      $allow = FALSE;
    }
  }
  return $allow;
}