You are here

function _comment_resource_access in Services 6.3

Same name and namespace in other branches
  1. 7.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 Will define the comments resource for dealing with node comments

File

resources/comment_resource.inc, line 375
Will define the comments resource for dealing with node comments

Code

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

  // Add backwards compatability with regression fixed in #1083242
  $args = _services_access_value($args, array(
    'comment',
    'data',
  ));
  if ($op == 'view' && !isset($args[0])) {
    return user_access('access comments');
  }
  if ($op == 'create') {
    $comment = (object) $args[0];
  }
  else {
    $comment = _comment_load($args[0]);
  }

  // If the submitted comment does not contain a nid, then return an error.
  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
      // and that the node has comments enabled.
      return $comment->status == COMMENT_PUBLISHED && user_access('access comments');
    case 'edit':
    case 'delete':

      // Check if the user may edit the comment, and has access to the input format
      return comment_access('edit', $comment);
    case 'create':

      // Check if the user may post comments, and has access to the used format and
      // check if the node has comments enabled, and that the user has access to the node
      return user_access('post comments');
  }
}