domain_node_grants

Versions
domain
domain_node_grants($account, $op)

Implement hook_node_grants.

Informs the node access system what permissions the user has. By design all users are in the realm defined by the currently active domain_id.

Code

./domain.module, line 1263

<?php
function domain_node_grants($account, $op) {
  global $_domain;
  $grants = array();

  // Do we need to use complex rules?
  $rules = variable_get('domain_access_rules', FALSE);

  // By design, all users can see content sent to all affiliates,
  // but the $_domain['site_grant'] can be set to FALSE.
  if ($op == 'view') {
    if ($_domain['site_grant']) {
      $grants['domain_site'][] = 0;
      if ($rules) {
        $grants['domain_site']['group'] = 'domain';
      }
    }

    // Grant based on active domain.
    $grants['domain_id'][] = $_domain['domain_id'];
    if ($rules) {
      $grants['domain_id']['group'] = 'domain';
    }
    // In special cases, we grant the ability to view all nodes.  That is,
    // we simply get out of the way of other node_access rules.
    // We do this with the universal 'domain_all' grant.
    if ($op == 'view' && domain_grant_all()) {
      // If no other node access modules are present, return our grant.
      // Otherwise, we just step out of the way.
      if ($rules) {
        return array();
      }
      else {
        return array('domain_all' => array(0));
      }
    }
  }
  else {
    // The $account may not have domain information loaded, so get it.
    $domains = domain_get_user_domains($account);
    $perm = 'delete domain nodes';
    if ($op == 'update') {
      $perm = 'edit domain nodes';
    }
    if (user_access($perm, $account)) {
      if (!empty($domains)) {
        foreach ($domains as $id) {
          if (abs($id) > 0) {
            if ($id > 0) {
              $grants['domain_id'][] = $id;
            }
            else {
              $grants['domain_id'][] = 0;
            }
            // Advanced rules let us access check unpublished nodes for editing.
            if ($rules) {
              $grants['domain_id']['check'] = TRUE;
            }
          }
        }
      }
    }
  }
  // Let Domain Access module extensions act to override the defaults.
  static $_modules;
  if (!isset($_modules)) {
    $_modules = module_implements('domaingrants');
  }
  if (!empty($_modules)) {
    foreach ($_modules as $module) {
      // Cannot use module_invoke_all() since these are passed by reference.
      $function = $module .'_domaingrants';
      $function($grants, $account, $op);
    }
  }
  return $grants;
}
?>

Contact

  • agentrickard [at] gmail [dot] com

Donations

My Amazon.com Wish List