3

I would like my view to not display nodes to which the current user does not have access to.

I have implemented hook_permission "access nodes of type mytype"

I have also implemented hook_node_access this way:

function mymodule_node_access( $node, $op, $account)
{

   if ($op == 'create')
    {
     $type = $node;                                                                                                                            
    }

   else
   {

    switch($node->type)
    {
      case "mytype":
        if ( !user_access("access nodes of type mytype") )
         {return NODE_ACCESS_DENY;}
        break;
    }

   }

 return NODE_ACCESS_IGNORE;
}

I set up the view to displays only nodes of type "mytype". When a user who does not have the permission "access nodes of type mytype" clicks on a link in the rows of the view, he gets the page "access denied" which is what I want. But I also want the view to not display the nodes of type "mytype" if a user does not have the permission to "access nodes of type mytype".

How do I implement that?

Thanks,

Baba

0
1

The correct answer is actually here.

It seems that a better way to control node access is through hook_node_access_records and hook_node_grants as described here http://drupal.org/node/1260948. This works with views properly.

0

Take a look at Node access example, you can manage to make it work with Node access module.

The modules provide roles and user specific security permissions for menus, menu items, nodes, and security integration into the administration and help systems.

1
  • I did actually look at the node access example and the code I posted above is as much as I could take from it because Node access example does not seem to use views to display nodes. Therefore I haven't found a way to do the same thing with a view.
    – Baba
    Aug 14 '13 at 20:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.