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?
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:
Content: Nidas a Field in your view and exclude it from display.
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.
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));