You are here

function hosting_node_grants in Hosting 5

Implementation of 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

client/hosting_client.access.inc, line 150
Control client node access

Code

function hosting_node_grants($account, $op) {
  $account->client_id = hosting_get_client_from_user($account->uid);
  $types = array_merge(hosting_feature_node_types(), array(
    'site',
    'task',
    'package',
    'client',
  ));
  foreach ($types as $type) {
    if (user_access("{$op} {$type}")) {

      // TODO: restrict access to certain op-type based on the user relationship to this client - see content of $client_relations
      $grants['hosting ' . $type] = array_keys($account->client_id);
    }
  }
  return $grants;
}