Paid affiliate advertisement

BOUNTY: custom views filter (Current user OR ADMIN)

asak - October 19, 2009 - 16:26

Hi,

Quick $50 for a views2 filter development, which could be added to a users view and provide the following functionality:
Filter to the current user OR if current user has "admin users" permission, display all site users.

The purpose:
We use a CCK User Reference field, and need the website users to ONLY be able to select their own account, so we pass the field through views with a filter of "Current User".
Problem is, we need an admin to be able to select ANY site user while adding/updating such nodes, and since we're using the "Current user" it's not possible for the admin to select some other user.

Similar to the "Published or admin" filter for nodes, which provides somewhat similar functionality, we need this for users and not nodes. This filter should use the standard "administer users" permission to check if the current user qualifies as admin, and if so - provide a list of all available users. If not - filter the list to only one option - the current user.

It's a mix of the "Current user" filter and the functionality of "Published or admin" ... ;)

This development will be contributed back and if the views maintainers find it useful we'd be happy if it was added to core views.module

Anyone...?

Questions/solutions/anything - feel free to contact me.
Thanks!

*_*

beautifulmind - October 19, 2009 - 16:52

Hello
You can use http://drupal.org/project/viewsphpfilter, or if its something else, let me do it.

Regards.

_

WorldFallz - October 19, 2009 - 17:20

should be doable with the 'user: current' and 'user: roles' or 'user: name' filters and the http://drupal.org/project/views_or module.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

Thank you WorldFallz, but I

asak - October 19, 2009 - 21:45

Thank you WorldFallz and beautifulmind, but I don't get it... i think what i need is a views_IF.module: GOT IT!

using viewsphpfilter.module, together with the patch from #574742: Filter for user?, and the following code:

global $user;
if (!in_array('admin', $user->roles)) { return $user->uid; }

Could you give me a hint as to how to use views_OR.module for the IF i need...?
Just had to get rid of the if... ;)

Thank you both very much!

Glad my module worked for

gnassar - October 28, 2009 - 06:48

Glad my module worked for you.

Just to note: I pointed out in that issue that the patch would not be accepted, and that the proper way to do that was to simply include the UID list you wanted in your node-filtering SQL statement as a part of your WHERE clause -- one line, tops, added to one's original PHP snippet. UID filtering as a separate concept from node filtering is unnecessary, since you're just going to use the UID list to determine the set of nodes you want to display in the end anyway.

Or to put it another way, instead of using that patch, you could've just added one more line to your PHP. :)

Nevermind

nvahalik - November 23, 2009 - 23:03

Forgot about the admin part.

 
 

Drupal is a registered trademark of Dries Buytaert.