You are here

function _administerusersbyrole_can_cancel_user in Administer Users by Role 7

2 calls to _administerusersbyrole_can_cancel_user()
administerusersbyrole_form_user_multiple_cancel_confirm_alter in ./administerusersbyrole.module
Implements hook_form_FORM_ID_alter().
administerusersbyrole_handler_field_user_link_cancel::render_link in views/administerusersbyrole_handler_field_user_link_cancel.inc
1 string reference to '_administerusersbyrole_can_cancel_user'
administerusersbyrole_menu_alter in ./administerusersbyrole.module
Implements hook_menu_alter().

File

./administerusersbyrole.module, line 87
Provides fine-grained permissions for creating, editing, and deleting users.

Code

function _administerusersbyrole_can_cancel_user($account) {
  if ($account->uid == 1) {
    return FALSE;
  }

  // We mave been passed a mock account object. If so, load the user to ensure
  // that we have roles to check against.
  if (!isset($account->roles)) {
    $account = user_load($account->uid);
  }
  if ($account->roles === array(
    DRUPAL_AUTHENTICATED_RID => 'authenticated user',
  )) {
    if (!user_access('cancel 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, 'cancel', TRUE))) {
      return TRUE;
    }
    if (!user_access(_administerusersbyrole_build_perm_string($role, 'cancel', FALSE))) {
      $allow = FALSE;
    }
  }
  return $allow;
}