You are here

function og_access_node_access_records in Organic groups 6

Same name and namespace in other branches
  1. 5.8 og_access.module \og_access_node_access_records()
  2. 5 og_access.module \og_access_node_access_records()
  3. 5.3 og_access.module \og_access_node_access_records()
  4. 5.7 og_access.module \og_access_node_access_records()
  5. 6.2 modules/og_access/og_access.module \og_access_node_access_records()
  6. 7.2 og_access/og_access.module \og_access_node_access_records()
  7. 7 og_access/og_access.module \og_access_node_access_records()

Implementation of hook_node_access_records.

File

modules/og_access/og_access.module, line 239

Code

function og_access_node_access_records($node) {
  if (og_is_group_type($node->type)) {

    // This grant allows group admins to manage their group.
    $grants[] = array(
      'realm' => 'og_admin',
      'gid' => $node->nid,
      'grant_view' => 1,
      'grant_update' => 1,
      'grant_delete' => 0,
      'priority' => 0,
    );
    if (!$node->og_private) {

      // If the group is not private, let everyone view the group homepage.
      $grants[] = array(
        'realm' => 'og_public',
        'gid' => 0,
        'grant_view' => 1,
        'grant_update' => 0,
        'grant_delete' => 0,
        'priority' => 0,
      );
    }
    else {

      // If the group private, let subscribers view the group homepage.
      $grants[] = array(
        'realm' => 'og_subscriber',
        'gid' => $node->nid,
        'grant_view' => 1,
        'grant_update' => 0,
        'grant_delete' => 0,
        'priority' => 0,
      );
    }
  }
  elseif (!empty($node->og_groups)) {

    // Applies to non group nodes.
    if ($node->og_public) {
      $grants[] = array(
        'realm' => 'og_public',
        'gid' => 0,
        'grant_view' => 1,
        'grant_update' => 0,
        'grant_delete' => 0,
        'priority' => 0,
      );
    }
    foreach ($node->og_groups as $gid) {

      // Group administrators get all operations.
      $grants[] = array(
        'realm' => 'og_admin',
        'gid' => $gid,
        'grant_view' => 1,
        'grant_update' => 1,
        'grant_delete' => 1,
        'priority' => 0,
      );

      // Normal subscribers just get update operation if node type is a wiki type.
      $is_wiki = og_is_wiki_type($node->type);
      $grants[] = array(
        'realm' => 'og_subscriber',
        'gid' => $gid,
        'grant_view' => 1,
        'grant_update' => $is_wiki,
        'grant_delete' => 0,
        'priority' => 0,
      );
    }
  }
  if (!empty($grants)) {

    // Allow other modules to change the grants.
    drupal_alter('og_access_grants', $grants, $node);
    return $grants;
  }
  return NULL;
}