Filter a view based on current user's roles? Using Drupal 7, Views 3 and the Node Reference module, I'm using a view to populate a node reference field on a custom content type. (So it's a view of "Reference" display type.)

I want to filter this view to show (and allow users to select) only:


published content (OK)
content of a certain type (OK)
only nodes created by the current user (OK)
OR if the current user is admin or some other role, bypass the previous filter (3) and show all nodes (but still respect filters 1 and 2) (not OK)


Filters 1 and 2 are always mandatory; then either filter 3 OR 4 must also be mandatory. I know I can rearrange filters into filter groups to make this work. The problem is that I cannot find a way to build filter 4.

For filter 3, I had to bring in a Relationship of type "Content: Author", which made a lot of new filters appear, including the "User: Current" that I used for filter 3 (node author == current user).

For filter 4, I need to filter based on the role of the current user (not author), and I cannot find how to do that.

In the filters list there's a new "User: Roles" filter available, but it only refers to the "Content: Author" relationship, so it only checks the node author's roles. That's not what I need: I need to check the current user's roles.

I'm guessing I have to add a new Relationship to bring in the current user data (something like "User: current"), and then filter on that data, but I cannot find that in the Add Relationship screen.

Any idea how to do that?
Following @Jimajamma's suggestion, here's what I used. I adapted his code slightly for Drupal 7 and to allow for other roles than Administrators full access to the results.

In the View, add a contextual filter on Author: Uid, and use the following settings:

WHEN THE FILTER VALUE IS NOT AVAILABLE:


Provide default value  
Type: PHP Code


Use the following code:

global $user;

if (
    in_array('administrator', $user-&gt;roles) || 
    in_array('editor', $user-&gt;roles)
)
{return -1;}
else
{return $user-&gt;uid;}


WHEN THE FILTER VALUE IS AVAILABLE OR A DEFAULT IS PROVIDED


Specify validation criteria
Validator: PHP Code


Use the following code:

if ($argument == -1) 
{return FALSE;}
else
{return TRUE;}



Action to take if filter value does not validate: Display all results for the specified field (this is what will give admins access to all results)


And that's it!

Notes:

Compared to my initial settings, the relationship (Content: Author) isn't needed anymore; neither is the "Author" filter (which was brought in by the relationship anyway).

Apparently, for Drupal 6 the condition in the first PHP snippet should rather be if (in_array('super user', array_values($user-&gt;roles))).