Enhance administrative user search by including email searches

mattman - January 29, 2007 - 21:42
Project:Drupal
Version:5.x-dev
Component:user.module
Category:feature request
Priority:normal
Assigned:damien_vancouver
Status:closed
Description

Having used drupal for a while now, I've found the user search form quite limiting - from a support standpoint that is. Most of the time, users send email about issues to something like support@example.com and do not include their site user name. However, more often than not, the user's email is the same as within drupal. Addressing issues using /admin/user/search using only the user name as criteria does not get you to the user's record very fast.

Attached is a patch to the user_search function that leverages the 'administer users' access perm.

If there are those who feel this addition to the search result clouds the results, then you could consider an additional permission to extend the search. I figure creating a module for simply extending the search is overkill when email is such a common everyday piece of information. Plus, this does not expose the user search (by users with access via 'access user profiles') to private email information.

AttachmentSizeStatusTest resultOperations
user_search.txt1.39 KBIgnoredNoneNone

#1

damien_vancouver - May 24, 2007 - 17:02
Status:active» needs review

I too agree this functionality is so essential that i cannot believe it is still not in core.

I will explain by outlining my scenario - perhaps it's not obvious how important a feature this is.

One of the drupal sites we manage has over 4000 users and uses organic groups heavily. We also use og2list to create a mailing list gateway to the groups.

Every time a group manager wants to add someone to organic groups, they are totally unable to find their username, because there is no way to look the user up by e-mail. Guessing the user's username is about the best chance they have. Indeed you can't even list the users and see a summary list of their emails in a column (this is perhaps security motivated and maybe a good thing - but you DO need to be able to search on e-mail). For a CMS like Drupal this should be (in my opinion) a clearly labelled and easy to find feature for any user searches. But it is not and it seems to be the main complaint of my user base is that it's impossible to do any system administration without an ability to find users.

Anyway, I was excited to find this patch, as before I was solving this problem with the ldap_adddressbook module, which is not ported to 5.x yet. (besides, that was a kludge, the users are already in drupal, it should be simple to search for them by username or email!)

I tried mattman's patch on Drupal 5.1 and found that it worked, but there was one missing } in the patch that caused a whitescreen when I applied it.

I have attached the fixed patch for 6.x (the filename at the top needed to be edited, and the missing } added right before return $find). I am going to make a separate Drupal issue post for 5.x as I believe this feature is important and should be available (even if in a patch form for now).

Please consider adding this functionality (or an enhanced version of it) to HEAD and/or DRUPAL-5! Thanks!!

AttachmentSizeStatusTest resultOperations
user_search_0.patch1.41 KBIgnoredNoneNone

#2

damien_vancouver - May 24, 2007 - 17:52
Status:needs review» reviewed & tested by the community

OK that last _0 patch still had problems.

I have recreated a proper patch against HEAD.

I have also created backports for DRUPAL-5 and DRUPAL 5.1 release which I will post as seperate issues and follow up with links to.

Here is the new HEAD patch, should be ready to go:

AttachmentSizeStatusTest resultOperations
user_search_by_email-HEAD.patch1.73 KBIgnoredNoneNone

#3

damien_vancouver - May 24, 2007 - 18:01

The Drupal 5.1 release version of this patch can be found here: http://drupal.org/node/146573.

The DRUPAL-5 version against the current Drupal 5 CVS branch can be found here: http://drupal.org/node/146575.

#4

recidive - May 24, 2007 - 18:04

Your patch doesn't conform with Drupal's coding standards, it contains 'tabs' and wrong comments.

#5

recidive - May 24, 2007 - 18:15
Status:reviewed & tested by the community» needs work

Needs work.

#6

damien_vancouver - May 25, 2007 - 06:22
Status:needs work» needs review

Attached is n updated patch with tabs and comments removed. I also fixed the positioning of the else's in if statements. Hopefully it should confirm to the coding standards.

I realized that something should also be displayed in hook_help for admin/user/search if it will allow email searching. I modified the hook_help for admin/user/search so that it will display a slightly modified help text.

In my drupal 6 install, I do not see the user search anywhere - admin/user management just says List,Add and Edit?? Anyway hopefully this patch is closer now, sorry for marking it ready to be committed. Please have another look.

AttachmentSizeStatusTest resultOperations
user_search_by_email-HEAD_1.patch2.63 KBIgnoredNoneNone

#7

damien_vancouver - May 25, 2007 - 06:30

Oops, I just realized I took out the only girl's name in the list.. here it is again using webmaster@brenda.com in the email example.

AttachmentSizeStatusTest resultOperations
user_search_by_email-HEAD_2.patch2.63 KBIgnoredNoneNone

#8

damien_vancouver - May 25, 2007 - 14:10

I got my search to show up (didn't have search module enabled). The patch works great for me, and the proper instructions show up for me as administrator.

#9

moshe weitzman - June 22, 2007 - 16:17

code looks good and this is definately useful functionality.

#10

dww - June 22, 2007 - 19:04
Category:task» feature request
Status:needs review» needs work

I haven't tested it, but visually the latest patch mostly looks good. My only objection is the webmaster@brenda.com part. It would be evil if Drupal core printed an example email address pointing to a potentially real domain (and webmaster). So, please change that to: brenda@example.com.

Otherwise, this would be nice. +1.

Thanks,
-Derek

#11

damien_vancouver - June 22, 2007 - 21:34
Status:needs work» needs review

OK, I have updated it as suggested in #10 - the e-mail example is now: "brenda@example.com"

The attached is against current HEAD user.module v1.802.

D.

AttachmentSizeStatusTest resultOperations
user_search_by_email-HEAD_3.patch2.72 KBIgnoredNoneNone

#12

damien_vancouver - June 22, 2007 - 21:41

Found and fixed an extra space before the displayed e-mail address in a search result.

It was reading: username ( user@example.com)
Should be reading: username (user@example.com)

AttachmentSizeStatusTest resultOperations
user_search_by_email-HEAD_4.patch2.72 KBIgnoredNoneNone

#13

dww - June 22, 2007 - 22:02
Status:needs review» reviewed & tested by the community

Re-rolled to fix 2 minor problems:
1) The spacing was wrong, so results were showing up like this: test( test@example.com)

2) We like patches rolled relative from the root of core, not all the way down inside an individual module's directory.

However, this is so minor, I'm just going to RTBC it, even thought it's my own patch. ;)

Thanks,
-Derek

AttachmentSizeStatusTest resultOperations
user_search_by_email-HEAD_4_0.patch2.83 KBIgnoredNoneNone

#14

dww - June 22, 2007 - 22:05
Status:reviewed & tested by the community» needs work

tee hee, whoops. didn't notice your followup, but thanks for catching your own bug. ;)

however, now that i look at it, i notice a minor code-style problem: we don't put a space between the . and a string literal when cat'ing strings.

#15

dww - June 22, 2007 - 22:06
Status:needs work» reviewed & tested by the community

like so.

AttachmentSizeStatusTest resultOperations
user_search_by_email-HEAD_5.patch2.83 KBIgnoredNoneNone

#16

damien_vancouver - June 22, 2007 - 23:46

OK thanks, I see.

So now what, can I commit it now that it's RTBC?

thanks,

D.

#17

Frando - June 23, 2007 - 00:03

No, you can't commit anything to Drupal core yourself ;)
Only very few people have the privileges to commit patches to Drupal core (for the current development for Drupal 6 it's just three). See also http://drupal.org/node/10261
Now that the issue is marked "Ready to be commited", one of them will hopefully pick this one up soon and commit it.

#18

damien_vancouver - June 23, 2007 - 05:48

ah OK - but it is done then! Great!!

Thanks everyone for your help on this! :)

D.

#19

dww - June 23, 2007 - 06:43

but it is done then!

Ha, not yet. ;) It's only done once one of the core committers actually commits it to CVS and marks the issue "fixed". However, sometimes even when people like me think it's RTBC, a core committer will see it and decide it needs work for some reason we didn't think of... So, don't start celebrating just yet. ;)

#20

Gábor Hojtsy - June 23, 2007 - 11:09
Status:reviewed & tested by the community» needs work

The multiple if ($admin) uses and only very small part of code inbetween makes this hard to read IMHO. I would do an if (user_access('administer users')) {} else {} wrap around the code. There is only a while(){} to repeat in them anyway. Otherwise this looks simple and acceptable to me.

#21

damien_vancouver - June 23, 2007 - 21:16
Status:needs work» needs review

I made those changes as suggested in #20 and it is much more readable this way.

updated patch against v1.804 attached. Tests OK for me.

D.

AttachmentSizeStatusTest resultOperations
user_search_by_email-HEAD_6.patch2.65 KBIgnoredNoneNone

#22

Gábor Hojtsy - June 23, 2007 - 21:38
Status:needs review» fixed

OK, reviewed the patch even more closely and noticed some issues:

- the $admin variable had no use, it did distract from the understandability of the code
- a comment on why it is only possible to search by email for admins was required
- I noticed that the menu item explicitly said that the page offers search by name only, modified that
- then immediately noticed that the menu item for this page is only ever allowed access, if the user already has "administer users" privileges, so doing the check in the help hook again, and having two help texts is completely pointless, that page will only display for users having the privilege already

After fixed these, the patch seemed to be RTBC, attached for reference :) So comitted.

AttachmentSizeStatusTest resultOperations
user_search_by_email-HEAD_7.patch2.81 KBIgnoredNoneNone

#23

damien_vancouver - June 24, 2007 - 00:13

Thanks for your help Gábor!

#24

Anonymous - July 8, 2007 - 00:15
Status:fixed» closed

#25

damien_vancouver - September 4, 2007 - 05:29

Here is an updated backport of the final patch for Drupal 5.2.

AttachmentSizeStatusTest resultOperations
user_search_by_email-DRUPAL-5-2.patch2.85 KBIgnoredNoneNone

#26

damien_vancouver - November 1, 2007 - 07:53
Version:6.x-dev» 5.3

Here is the backport for DRUPAL-5.3. It shoudl apply cleanly to the 5.3 user.module.

AttachmentSizeStatusTest resultOperations
user_search_by_email_DRUPAL-5.3.patch2.8 KBIgnoredNoneNone

#27

damien_vancouver - November 1, 2007 - 15:53

Whoops, that one had a small bug - here is the correct version for 5.3.

AttachmentSizeStatusTest resultOperations
user_search_by_email_DRUPAL-5.3_0.patch2.81 KBIgnoredNoneNone

#28

damien_vancouver - November 1, 2007 - 15:56

And as requested by lpkb, here is the user.module file for Drupal 5.3 with the patch applied (for people who aren't so good with patching).

Just remove the .txt extension, rename up your old modules/user/user.module to user.module.bak
and put this one in place as modules/user/user.module

AttachmentSizeStatusTest resultOperations
user.module_0.txt112.49 KBIgnoredNoneNone

#29

damien_vancouver - December 6, 2007 - 05:59
Version:5.3» 5.4

Here is the Drupal 5.4 backport of the admin user search by email patch that is comitted to Drupal 6.

I have also attached the patched user.module (for those who don't like patching!)

To use that, rename your old user.module to user.module.drupal54.bak and save and rename the attached user.module_drupal5.4_with_admin_user_search_patch.txt to user.module.

AttachmentSizeStatusTest resultOperations
user_search_by_email_DRUPAL-5.4.patch2.82 KBIgnoredNoneNone
user.module_drupal5.4_with_admin_user_search_patch.txt113.19 KBIgnoredNoneNone

#30

damien_vancouver - December 11, 2007 - 22:16
Version:5.4» 5.5

the Drupal 5.4 patch from #29 will apply to Drupal 5.5 cleanly as well.

OR, use the attached Drupal 5.5 user.module with the patch applied. Just rename your modules/user.module and save this one in its place as user.module.

AttachmentSizeStatusTest resultOperations
user.module_drupal5.5_with_admin_user_search_patch.txt113.19 KBIgnoredNoneNone

#31

damien_vancouver - January 14, 2008 - 20:42
Version:5.5» 5.6

As with Drupal 5.5, the drupal 5.4 patch from #29 will apply to the latest Drupal 5.6 release cleanly.

For those patch-shy, I've attached the patched modules/user/user.module file for Drupal 5.6 to this comment - just rename the attached file to user.module and save it over the existing modules/user/user.module file from Drupal 5.6.

AttachmentSizeStatusTest resultOperations
user.module_drupal5.6_with_admin_user_search_patch_applied.txt113.27 KBIgnoredNoneNone

#32

damien_vancouver - February 4, 2008 - 19:11
Version:5.6» 5.7

attached is the patched modules/user/user.module for Drupal 5.7.

If you'd rather patch, the patch from [#29] / drupal 5.4 still works.

AttachmentSizeStatusTest resultOperations
user.module_drupal5.7_with_admin_user_search_patch_applied.txt113.27 KBIgnoredNoneNone

#33

introfini - April 22, 2008 - 10:52

Hi,

I tested it on 5.7, and is working.

introfini

#34

jpsalter - April 21, 2008 - 19:35

I too can confirm it works w/ 5.7.

Thanks for a great patch.

#35

ericinwisconsin - July 3, 2008 - 13:55

This definitely works with 5.7.

How about incorporating this into the core, guys? Quite frankly, I'm amazed that it's not there already.

#36

Damien Tournoud - July 3, 2008 - 14:35
Version:5.7» 7.x-dev

Yeah, it is in core (both Drupal 6.x and the development version Drupal 7.x). Please reassign to 5.x and to "patch (to be ported)" if you want to submit a port for inclusion in the 5.x branch.

#37

thomasmurphy - July 23, 2008 - 04:00

Will I need a seperate patch for 5.8?

#38

damien_vancouver - July 28, 2008 - 16:40
Version:7.x-dev» 5.x-dev
Assigned to:Anonymous» damien_vancouver
Status:closed» patch (to be ported)

Here is the updated/backported patch for Drupal 5.9, as well as the user module with the patch applied.

HOW TO INSTALL ADMIN USER SEARCH

1. Update your site to Drupal 5.9.
2. Download the user.module_drupal-5.9_with_admin_user_search_applied.txt from this post
3. Rename it to user.module and save it over top of your stock Drupal 5.9 user.module
4. test it by going to your site's admin/user/search page. The prompt should mention an e-mail (brenda@example.com) and you should be able to get matches back searching by email.

@Damien T. - I keep updating and releasing this patch each minor drupal version here, but since it's in core it would be useful to just get it in future releases.

Thus I've marked it as 5.x-dev and patch (to be ported) as you suggested. I've tested this version of the patch on 3 or 4 of my sites, but someone else who also uses it every version needs to confirm it is working as expected and then mark it "Reviewed and Tested by the Community" to get it further along to inclusion in forthcoming maintenance releases.

If that never quite happens, then meet back here next minor version ;)

D.

AttachmentSizeStatusTest resultOperations
user_search_by_email_DRUPAL-5.9.patch2.82 KBIgnoredNoneNone
user.module_drupal-5.9_with_admin_user_search_applied.txt113.36 KBIgnoredNoneNone

#39

moshe weitzman - August 1, 2008 - 15:32

Minor UI gripe ... I was expecting this in Admin => User => User and not on search page.

#40

thomasmurphy - September 2, 2008 - 03:39

Hey, is there a 5.10 updated user.module on its way? Thanks for all the others.

#41

damien_vancouver - September 16, 2008 - 18:50

The old 5.9 patch works for Drupal 5.10, but here is an updated patch and user.module. Follow the installation instructions from #38.

AttachmentSizeStatusTest resultOperations
user_search_by_email_DRUPAL-5.10.patch2.82 KBIgnoredNoneNone
user.module_drupal-5.10_with_admin_user_search_applied.txt113.36 KBIgnoredNoneNone

#42

thomasmurphy - September 16, 2008 - 23:43

thanks

#43

damien_vancouver - October 13, 2008 - 21:31

Drupal 5.11 patch and updated user.module for admin/user/search by e-mail address are attached.
See http://drupal.org/node/113983#comment-939950 (#38 on this thread) for install instructions.

AttachmentSizeStatusTest resultOperations
user.module.drupal-5.11_with_admin_user_search_applied.txt114.3 KBIgnoredNoneNone
user_search_by_email_DRUPAL-5.11.patch2.82 KBIgnoredNoneNone

#44

lpkb - October 16, 2008 - 15:39

Thanks for continuing to update these while we wait for it to be included... I appreciate it!

#45

Pasqualle - October 17, 2008 - 15:49

I don't think it will be ever included in D5, simply because new features are not added to stable versions..

#46

damien_vancouver - October 17, 2008 - 16:02

@Pasqualle, yeah that's the situation as I understand it - this patch made it into HEAD in time for inclusion into drupal 6 I think.

I will keep on making new versions and posting them here as new minors of D5 come out, at least until I stop using it Drupal 5 everywhere (and with some coaxing by email, probably even after that).

What is the correct status for this situation? Fixed? By Design?

#47

Pasqualle - October 17, 2008 - 17:12

rolling :)

I don't think we have a good status for this case..

#48

damien_vancouver - October 22, 2008 - 20:42

Here is the Drupal 5.12 patch file and pre-patched user.module.

See http://drupal.org/node/113983#comment-939950 (#38 on this thread) for the install instructions.

AttachmentSizeStatusTest resultOperations
user.module_drupal-5.12_with_admin_user_search_applied.txt114.3 KBIgnoredNoneNone
user_search_by_email_DRUPAL-5.12.patch2.82 KBIgnoredNoneNone

#49

damien_vancouver - January 6, 2009 - 18:23

here is the Drupal 5.14 patch for administrative user search by email address.

a pre-patched modules/user/user.module attached as well.

AttachmentSizeStatusTest resultOperations
user.module_drupal-5.14_with_admin_user_search_applied.txt114.3 KBIgnoredNoneNone
user_search_by_email_DRUPAL-5.14.patch2.82 KBIgnoredNoneNone

#50

alexandreracine - January 8, 2009 - 18:19

#51

damien_vancouver - January 8, 2009 - 19:08

This admin user search patch is already in Drupal 6 and 7 (committed in #22 above),
see further explanation here: http://drupal.org/node/299784#comment-1189706.

#52

damien_vancouver - January 21, 2009 - 02:39

Patch and user.module for Drupal 5.15.

See http://drupal.org/node/113983#comment-939950 for install instructions.

AttachmentSizeStatusTest resultOperations
user_search_by_email_DRUPAL-5.15.patch2.82 KBIgnoredNoneNone
user.module_drupal-5.15_with_admin_user_search_applied.txt114.3 KBIgnoredNoneNone

#53

dww - January 21, 2009 - 18:02
Status:patch (to be ported)» closed

@damien_vancouver: Can you please find another place to keep posting these backport patches? You keep bumping this issue for those of us unlucky enough to have commented previously. ;) Thanks.

#54

lpkb - January 26, 2009 - 20:05

If you start posting elsewhere please let me know where. We plan to upgrade to d6 within a few months but until then these are greatly appreciated. Thanks again.

#55

damien_vancouver - January 27, 2009 - 02:32

Next version I will make a new thread and post it here... till then let's try and keep this issue quiet :) I am stuck on 5t though so I will keep posting these for the forseeable future, just in another spot.

If anyone has any suggestions as to where the best spot would be (that wouldn't involve it bumping lots of people) please let me know. I've never found a suitable "backports for 5" issues collection but there definitely should be one (stuff like this and the performance backports undertaken by the infrastructure team when drupal.org was really sucking last year... sadly these were never organized in one spot).

Maybe there should be a groups.drupal.org group for this? I dunno, but anyway if anyone has any ideas please private message me through the contact form rather than post on the issue.

Sorry to everyone we keep bothering! :D

#56

Pasqualle - January 27, 2009 - 03:19

summary:
1. The patch can't be committed because the new feature won't be included in the stable version.
2. As I see it is not possible to create a new module with the same functionality.
3. If the patch is useful for people then it should be available.
4. We encourage all developers and users to make Drupal better.

I believe you have all the rights to use the d.o infrastructure for the patch, and I think the issue queue is a good place for it. Just create a new issue with a clear description that the patch will not be committed. Provide a link between the new issue and old issue, so people could find it. Set the status to "patch (to be ported)", and you can even add a new tag, something like "Backported feature", so you can create a collection of issues with that one tag.

I do not use the patch as I don't have a D5 site, but I would like to say thanks for your contribution Damien.

#57

chris.cohen - March 17, 2009 - 14:17

Thank you very much for all the effort on this patch. It worked fine for me on Drupal 5.10 and it is very useful.

 
 

Drupal is a registered trademark of Dries Buytaert.