I am trying to implement a small custom module to handle node access restrictions using hook_node_grants() and node_access_records().

I have a one content type called customer_propinfo that is concerned with access security. This content type has a CCK User Reference field that I want to use as the Grant ID (gid).

If I hard-code the user name into the code it works and access to the node is granted, but when I try to set the gid using $node->field_customer[0]['view'] it will not work. I have spent about 12 hours researching and trying to get this to work.

>
function private_blogs_node_grants($account, $op) {
  
  global $user;
  $account_number = $user->name;
  $grants['private_blogs'] = array($account_number);

  return $grants;
}

function private_blogs_node_access_records($node) {
  
  if ($node->type == 'customer_propinfo') {
    $grants = array();
    $grants[] = array(
      'realm' => 'private_blogs',
       'gid' => $node->field_customer[0]['view'],
       //  'gid' => 777,  *** If we hard-code the username/account number, access if granted as expected
      'grant_view' => TRUE,
      'grant_update' => FALSE,
      'grant_delete' => FALSE,
      'priority' => 0,
    );

    return $grants;
  }
}
<

Comments

3cwebdev’s picture

I got it to work by using

'gid' => $node->field_customer[0]['uid'],

as this gid instead of ....['view']

The Cosmic Gift | Complete Computer Care | Team Hope