You are here

function oa_core_node_access in Open Atrium Core 7.2

Implements hook_node_access().

Add proper 'create' access checks that OG doesn't handle

File

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

Code

function oa_core_node_access($node, $op, $account) {
  $type = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);
  if ($op == 'create' && ($type == OA_SPACE_TYPE || og_is_group_content_type('node', $type))) {

    // In og.module, og_node_access doesn't handle 'create' because
    // it doesn't have a Group context.
    // Well, in OA2 we *have* a Group context most of the time.
    // Can't call oa_core_get_space_context() however since
    // og_context_determine_context() will cause an infinite loop
    if (defined('OG_SESSION_CONTEXT_ID') && isset($_SESSION[OG_SESSION_CONTEXT_ID])) {
      $space_id = $_SESSION[OG_SESSION_CONTEXT_ID];

      // so let's use that to test 'create' access
      if ($space_id) {
        $return = og_user_access('node', $space_id, "{$op} {$type} content", $account);
        if ($return) {
          return NODE_ACCESS_ALLOW;
        }
      }
      if ($type != OA_SPACE_TYPE) {
        return NODE_ACCESS_DENY;
      }
    }
  }
  return NODE_ACCESS_IGNORE;
}