You are here

function _user_resource_access in Services 7.3

Same name and namespace in other branches
  1. 6.3 resources/user_resource.inc \_user_resource_access()

Access check callback for user resource.

1 string reference to '_user_resource_access'
_user_resource_definition in resources/user_resource.inc

File

resources/user_resource.inc, line 909

Code

function _user_resource_access($op = 'view', $args = array()) {

  // Adds backwards compatability with regression fixed in #1083242
  if (isset($args[0])) {
    $args[0] = _services_access_value($args[0], array(
      'account',
      'data',
    ));
  }

  // Check if the user exists if appropriate.
  if ($op != 'create' && $op != 'register') {
    $account = user_load($args[0]);
    if (!$account) {
      return services_error(t('There is no user with ID @uid.', array(
        '@uid' => $args[0],
      )), 404);
    }
  }
  global $user;
  switch ($op) {
    case 'view':
      return user_view_access($account);
    case 'update':
      return $user->uid == $account->uid || user_access('administer users');
    case 'create':
    case 'register':
      if (!$user->uid && variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL) != USER_REGISTER_ADMINISTRATORS_ONLY) {
        return TRUE;
      }
      else {
        return user_access('administer users');
      }
    case 'password_reset':
      return TRUE;
    case 'delete':
    case 'cancel':
    case 'resend_welcome_email':
      return user_access('administer users');
  }
}