You are here

function private_node_grants in Private 7

Same name and namespace in other branches
  1. 5 private.module \private_node_grants()
  2. 6 private.module \private_node_grants()
  3. 7.2 private.module \private_node_grants()

Implements hook_node_grants().

Tell the node access system what GIDs the user belongs to for each realm. In this example, we are providing two realms: the example realm, which has just one group id (1) and the user is either a member or not depending upon the operation and the access permission set.

We are also setting up a realm for the node author, though, to give it special privileges. That has 1 GID for every UID, and each user is automatically a member of the group where GID == UID.

File

./private.module, line 86
A tremendously simple access control module -- it allows users to mark individual nodes as private; users with 'access private content' perms can read these nodes, while others cannot.

Code

function private_node_grants($account, $op) {

  // First grant a grant to the author for own content.
  $grants['private_author'] = array(
    $account->uid,
  );
  if ($op == 'view' && user_access('access private content', $account)) {
    $grants['private_view'] = array(
      PRIVATE_GRANT_ALL,
    );
  }
  if (($op == 'update' || $op == 'delete') && user_access('edit private content', $account)) {
    $grants['private_edit'] = array(
      PRIVATE_GRANT_ALL,
    );
  }
  return $grants;
}