5

I'm trying to set a view that shows only the nodes that current user or role has access to edit. I've tried with contextual filters and relationships but with no luck. Anyone know how to restrict it?

3 Answers 3

3

Views accessed can be controlled by Views Access configuration, check the screen shots if it helps.

Step 1: Find the Views Access Configuration

enter image description here

Step 2 : Opt the permissions, which suit your needs

enter image description here

Step 3 : Configure the permissions

enter image description here

1
  • 1
    This is pretty much spot on! And also a recommended way instead of using the views_php module.
    – AjitS
    Commented Nov 13, 2013 at 8:22
-1

It can be done with Views PHP, but I don't think it can be done just within normal Views configuration - would be delighted to be contradicted.

If you're OK to use Views PHP the steps are:

  1. Add Content: Nid as a Field in your view and exclude it from display.

  2. Add a Global: PHP filter and include the following snippet:

    return !node_access('update', node_load($row->nid));
    

PHP explanation (for non-seasoned PHPers) - the PHP snippet get the node object by using the node id that is made available by virtue of adding the Content: Nid field. With the first parameter of node_access set as 'update' the function will check whether the the node is editable. You can also check for 'view', 'delete' or 'create' powers. If no third parameter is specified, the function checks the powers of the current user. The function will return true if the user can edit it, but the Global: PHP filter needs a return value of false in order to show the row, so the ! flips the true/false value returned by the function.

-3

In Drupal 7 with Views 3 and Views PHP it can be done in one step. Create a Global PHP Filter and in the Filter code add:

return !node_access('update', node_load($data->nid));
1
  • No offence, but this is a pretty terrible idea all around. Using php.module or anything that leverages it is a bad idea in general, but you're also performing a node_load() on every row/node that the view displays - which is a REALLY expensive way of doing things.
    – Chapabu
    Commented Nov 13, 2013 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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