You are here

function _comment_resource_access in Services 7.3

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

Access check callback for comment controllers.

1 string reference to '_comment_resource_access'
_comment_resource_definition in resources/comment_resource.inc

File

resources/comment_resource.inc, line 384

Code

function _comment_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(
      'comment',
      'data',
    ));
  }
  if ($op == 'create') {
    $comment = (object) $args[0];
  }
  else {
    $comment = comment_load($args[0]);
  }
  if (isset($comment->nid)) {
    $node = node_load($comment->nid);
    if ($op == 'create' && !$node->nid) {
      return services_error(t('Node nid: @nid does not exist.', array(
        '@nid' => $comment->nid,
      )), 406);
    }
  }
  if (user_access('administer comments')) {
    return TRUE;
  }
  switch ($op) {
    case 'view':

      // Check if the user has access to comments
      return user_access('access comments');
    case 'delete':
      return user_access('administer comments');
    case 'edit':
      return comment_access('edit', $comment);
    case 'create':

      // Check if the user may post comments, node has comments enabled
      // and that the user has access to the node.
      return user_access('post comments') && $node->comment == COMMENT_NODE_OPEN;
  }
}