You are here

function oa_core_node_access_records in Open Atrium Core 7.2

Implements hook_node_access_records().

File

includes/oa_core.access.inc, line 140
Code for Access Control functions for OpenAtrium spaces

Code

function oa_core_node_access_records($node) {
  $grants = array();
  $sids = array();
  if ($node->status == 0) {

    // Grant author access to unpublished content.
    if ($node->uid) {
      $grants[] = array(
        'realm' => OA_UNPUBLISHED_REALM,
        'gid' => $node->uid,
        'grant_view' => 1,
        'grant_update' => 0,
        'grant_delete' => 0,
        'priority' => 0,
      );
    }
    return $grants;
  }
  elseif ($node->type == OA_SECTION_TYPE) {
    if (!oa_core_section_is_public($node)) {
      $sids[] = $node->nid;
    }
  }
  elseif (!empty($node->{OA_SECTION_FIELD})) {
    foreach ($node->{OA_SECTION_FIELD}[LANGUAGE_NONE] as $entity_ref) {
      $section = node_load($entity_ref['target_id']);
      if (!oa_core_section_is_public($section)) {
        $sids[] = $entity_ref['target_id'];
      }
    }
  }
  if (empty($sids)) {
    return array();
  }
  foreach ($sids as $sid) {
    $grants[] = array(
      'realm' => OA_ACCESS_REALM,
      'gid' => $sid,
      'grant_view' => 1,
      'grant_update' => 0,
      'grant_delete' => 0,
      // Priority 1 means lesser grants for this node will be ignored.
      'priority' => 1,
    );
  }
  return !empty($grants) ? $grants : array();
}