You are here

function hosting_client_node_access_records in Hosting 6.2

Same name and namespace in other branches
  1. 5 client/hosting_client.access.inc \hosting_client_node_access_records()
  2. 7.4 client/hosting_client.access.inc \hosting_client_node_access_records()
  3. 7.3 client/hosting_client.access.inc \hosting_client_node_access_records()

Implements hook_node_access_records().

File

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

Code

function hosting_client_node_access_records($node) {
  if (hosting_client_disabling()) {
    return;
  }
  $grants = array();
  $base_grant = array(
    'realm' => 'hosting ' . $node->type,
    'grant_view' => TRUE,
    'grant_update' => TRUE,
    'grant_delete' => FALSE,
    'priority' => 1,
  );

  // tasks inherit from their parent
  if ($node->type == 'task') {
    $node = node_load($node->rid);
    $base_grant['grant_update'] = FALSE;
  }
  switch ($node->type) {
    case 'site':
      $base_grant['gid'] = $node->client;
      break;
    case 'client':
      $base_grant['gid'] = $node->nid;
      break;
    case 'package':
      $base_grant['grant_update'] = FALSE;
      break;
    case 'task':
    case 'server':

      // The rest of the node types are configuration, so only admin should see them.
      $base_grant['gid'] = HOSTING_ADMIN_CLIENT;
      break;
    case 'platform':
      $base_grant['gid'] = HOSTING_ADMIN_CLIENT;
      if (isset($node->clients)) {
        foreach ($node->clients as $cid => $client) {
          if ($cid != HOSTING_ADMIN_CLIENT) {
            $grants[] = array_merge($base_grant, array(
              'gid' => $cid,
              'grant_update' => FALSE,
            ));
          }
        }
      }
      break;
    default:

      //Not hosting node, don't change access.
      return;
  }
  if (isset($base_grant['gid'])) {
    $grants[] = $base_grant;

    // this should _always_ happen.
    if ($base_grant['gid'] != HOSTING_ADMIN_CLIENT) {

      // Also give full access to the administrator user.
      $base_grant['gid'] = HOSTING_ADMIN_CLIENT;
      $grants[] = $base_grant;
    }
    return $grants;
  }
}