_node_resource_access

  1. services
    1. 7.3
    2. 7 node_resource.module
    3. 6.2 node_resource.module
    4. 6.3
Versions
6.2 – 7 _node_resource_access($op = 'view', $args = array())

Determine whether the current user can access a node resource.

Parameters

$op One of view, update, create, delete per node_access().

$args Resource arguments passed through from the original request.

Return value

bool

See also

node_access()

Code

resources/node_resource.inc, line 423

<?php
function _node_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], 'node');
  }

  // Make sure we have an object or this all fails, some servers can
  // mess up the types.
  if (is_array($args[0])) {
    $args[0] = (object) $args[0];
  }
  elseif (!is_array($args[0]) && !is_object($args[0])) { //This is to determine if it is just a string happens on node/%NID
    $args[0] = (object) array('nid' => $args[0]);
  }

  if ($op != 'create' && !empty($args)) {
    $node = node_load($args[0]->nid);
  }
  elseif ($op == 'create') {
    if (isset($args[0]->type)) {
      $node = $args[0]->type;
      return node_access($op, $node);
    }
    else {
      return services_error(t('Node type is required'), 406);
    }
  }
  if (isset($node->nid) && $node->nid) {
    return node_access($op, $node);
  }
  else {
    return services_error(t('Node @nid could not be found', array('@nid' => $args[0]->nid)), 404);
  }
}
?>