You are here

function userprotect_user_cancel_access in User protect 7

Access callback for user cancel pages.

This replaces the logic from user.module.

Parameters

object $account: An object representing the user to be cancelled.

1 string reference to 'userprotect_user_cancel_access'
userprotect_menu_alter in ./userprotect.module
Implements hook_menu_alter().

File

./userprotect.module, line 417
Main module file for the userprotect module.

Code

function userprotect_user_cancel_access($account) {

  // Perform core's access check.
  if (($GLOBALS['user']->uid == $account->uid && user_access('cancel account') || user_access('administer users')) && $account->uid > 0) {

    // At this point, we only need the userprotect-specific validation if:
    // 1. The current user and the edited user are not the same.
    // 2. The current user is a user administrator.
    if ($GLOBALS['user']->uid != $account->uid && user_access('administer users')) {

      // Check to see if the user's roles are protecting cancellation, or the
      // user account itself is protected.
      if (!userprotect_check_bypass('up_cancel') && userprotect_get_user_protection($account, 'up_cancel')) {

        // If so, and we're at /user/X/cancel, set a message.
        if (arg(0) == 'user' && is_numeric(arg(1)) && arg(2) == 'cancel') {
          drupal_set_message(t('%user is currently being protected from cancellation.', array(
            '%user' => $account->name,
          )), 'error', FALSE);
        }
        return FALSE;
      }
      else {
        return TRUE;
      }
    }
    else {
      return TRUE;
    }
  }
  else {
    return FALSE;
  }
}