I am about to hide some fields instead of just deny the request when a user doesn't have access to a node.

What I am doing now is trying to postpone the permission check process to theme hooks. I created a module with hook_node_access to return NODE_ACCESS_ALLOW for all views. However, I cannot check the permission later in other place like template.php or modules.

I used

 module_invoke('nodeaccess', 'node_access', $node, $op, $account);

but this only return NULL. How can I use this permission checking mechanism programmatically? Thank you!

Comments

leetom’s picture

Here is what I am doing now:

use _nodeaccess_get_grants($node); to get the grants array, then compare this with users' roles. If there is grant, then label the node by adding a new attribute. Then return NODE_ACCESS_ALLOW and check the new attribute in theme files.

This solved my question, although not so graceful.

function userview_node_access($node, $op, $account){
    if($op == 'view'){
         $node_grants = _nodeaccess_get_grants($node);

        $have = _check_access($node_grants['rid'], $account->roles); // check if any role have access.

        $node->haveAccess = $have;
        return NODE_ACCESS_ALLOW;
    }

}
alison’s picture

Status: Active » Closed (won't fix)

(issue queue housekeeping)

Thank you for reporting and sharing back! I'm going to close, but anyone who's interested should feel free to re-open or open something new with other ideas for handling this info.