You are here

function ctools_metadata_comment_access in Chaos Tool Suite (ctools) 7

Access callback for the comment entity.

1 string reference to 'ctools_metadata_comment_access'
_ctools_entity_access in includes/entity-access.inc
Core hack to include entity api-esque 'access callback' functions to core entities without needing to rely on entity api. Exception: We don't touch file entity. You must have entity API enabled to view files.

File

includes/entity-access.inc, line 117
Provides various callbacks for the whole core module integration. This is a copy of Entity API's functionality for use when Entity API isn't Enabled, and only works on view functions.

Code

function ctools_metadata_comment_access($op, $entity = NULL, $account = NULL) {

  // When determining access to a comment, if comment has an associated node,
  // the user must be able to view the node in order to access the comment.
  if (isset($entity->nid)) {
    if (!node_access('view', node_load($entity->nid), $account)) {
      return FALSE;
    }
  }

  // Comment administrators are allowed to perform all operations on all
  // comments.
  if (user_access('administer comments', $account)) {
    return TRUE;
  }

  // Unpublished comments can never be accessed by non-admins.
  if (isset($entity->status) && $entity->status == COMMENT_NOT_PUBLISHED) {
    return FALSE;
  }
  if (user_access('access comments', $account) && $op == 'view') {
    return TRUE;
  }
  return FALSE;
}