You are here

function _user_resource_access in Services 6.3

Same name and namespace in other branches
  1. 7.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 This file will define the resources for dealing with the user object

File

resources/user_resource.inc, line 468
This file will define the resources for dealing with the user object

Code

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

  // Adds backwards compatability with regression fixed in #1083242
  $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],
      )), 406);
    }
  }
  global $user;
  switch ($op) {
    case 'view':
      return user_view_access($account);
    case 'update':
      return $user->uid == $account->uid || user_access('administer users');
    case 'create':
      return user_access('administer users');
    case 'register':

      //Verify user is not logged in, and verify that visitors can create accounts.
      if (!$user->uid && variable_get('user_register', 1) != 0) {
        return TRUE;
      }
      else {
        return FALSE;
      }
    case 'delete':
      return user_access('administer users');
  }
}