You are here

function og_access_node_access_records in Organic groups 5.8

Same name and namespace in other branches
  1. 5 og_access.module \og_access_node_access_records()
  2. 5.3 og_access.module \og_access_node_access_records()
  3. 5.7 og_access.module \og_access_node_access_records()
  4. 6.2 modules/og_access/og_access.module \og_access_node_access_records()
  5. 6 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

./og_access.module, line 200

Code

function og_access_node_access_records($node) {

  // don't write records if the node type is omitted or node is a group
  if (og_is_omitted_type($node->type)) {
    return;
  }
  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' => 1,
    );

    // If the group is not marked private, let everyone view the group homepage.
    if (!$node->og_private) {
      $grants[] = array(
        'realm' => 'og_public',
        'gid' => 0,
        'grant_view' => 1,
        'grant_update' => 0,
        'grant_delete' => 0,
      );
    }
    else {
      $grants[] = array(
        'realm' => 'og_subscriber',
        'gid' => $node->nid,
        'grant_view' => 1,
        'grant_update' => 0,
        'grant_delete' => 0,
      );
    }
  }
  elseif (is_array($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,
      );
    }
    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,
      );

      // 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,
      );
    }
  }
  return $grants;
}