Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow admins to search for users by display name or email, per #1749 #2660

Closed
wants to merge 7 commits into from
Closed

Allow admins to search for users by display name or email, per #1749 #2660

wants to merge 7 commits into from

Conversation

justin-sleep
Copy link
Member

@justin-sleep justin-sleep commented Dec 13, 2016

Should resolve #1749. Tested with my 4 users. @hregnier, could you test this with your 30k users?

Signed-off-by: justin-sleep justin@quarterfull.com

@mention-bot
Copy link

@justin-sleep, thanks for your PR! By analyzing the history of the files in this pull request, we identified @LukasReschke, @schiessle and @MorrisJobke to be potential reviewers.

@justin-sleep
Copy link
Member Author

Not sure why it's failing some tests on drone after I implemented the null array check. Seems to be git cloning errors unrelated to my changes.

@hregnier
Copy link

@justin-sleep thanks for your PR! It works on my 30k+ users, no lags or whatever.
By the way, as the comments says, partial strings for mail (and maybe display name?) would be great.
Thanks again!

@justin-sleep
Copy link
Member Author

@hregnier no problem! Partial strings for display name should actually already work, I've just tested it on my own server. I'll see if I can figure out something for email, though.

@hregnier
Copy link

@justin-sleep About display name, I didn't express myself well : For exemple I have a user who's DisplayName is "Doe John". I can't find him by typing "John Doe". But maybe that is a bug for the searchDisplayName function and needed another issue report?

@justin-sleep
Copy link
Member Author

justin-sleep commented Dec 14, 2016

Hmm, I see what you mean; that would certainly add more versatility to the search. Off the top of my head, a potential solution would be to split the display name into an array of strings ("sub-patterns") using space as a delimiter, than calling searchDisplayName on each sub-pattern. I'll take a look at it.

@justin-sleep
Copy link
Member Author

@hregnier the latest commit I pushed should allow the more flexible display name matching you described.

@codecov-io
Copy link

codecov-io commented Dec 14, 2016

Codecov Report

Merging #2660 into master will increase coverage by -24.05%.

@@             Coverage Diff             @@
##           master    #2660       +/-   ##
===========================================
- Coverage   57.23%   33.18%   -24.05%     
===========================================
  Files        1146     1197       +51     
  Lines       65733    69522     +3789     
  Branches        0     1253     +1253     
===========================================
- Hits        37620    23070    -14550     
- Misses      28113    46452    +18339
Impacted Files Coverage Δ
settings/Controller/UsersController.php 0% <ø> (-64.78%)
apps/files_trashbin/lib/AppInfo/Application.php 0% <ø> (-100%)
lib/private/DB/SQLiteSessionInit.php 0% <ø> (-100%)
apps/user_ldap/appinfo/routes.php 0% <ø> (-100%)
...rivate/Authentication/Token/DefaultTokenMapper.php 0% <ø> (-100%)
apps/files_sharing/lib/AppInfo/Application.php 0% <ø> (-100%)
apps/dav/lib/Connector/Sabre/Server.php 0% <ø> (-100%)
lib/private/Files/Cache/MoveFromCacheTrait.php 0% <ø> (-100%)
lib/private/Files/Mount/LocalHomeMountProvider.php 0% <ø> (-100%)
apps/dav/lib/CalDAV/PublicCalendarRoot.php 0% <ø> (-100%)
... and 640 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e1b8064...885cefa. Read the comment docs.

Signed-off-by: justin-sleep <justin@quarterfull.com>
Signed-off-by: justin-sleep <justin@quarterfull.com>
Signed-off-by: justin-sleep <justin@quarterfull.com>
@rullzer rullzer added this to the Nextcloud 12.0 milestone Dec 16, 2016
@rullzer rullzer added 3. to review Waiting for reviews enhancement labels Dec 16, 2016
//if the pattern to search for isn't potentially complex, just call searchDisplayName with it
if (count($subPatterns) == 1)
$arrays[1] = $this->userManager->searchDisplayName($pattern, $limit, $offset);
else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always use brackets for if blocks.

Signed-off-by: justin-sleep <justin@quarterfull.com>
$batch = $this->userManager->search($pattern, $limit, $offset);


$batch = array();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation for this whole block seems to be wrong. Could you please check that you use tabs to indent? Thanks

if (count($subPatterns) == 1) {
$arrays[1] = $this->userManager->searchDisplayName($pattern, $limit, $offset);
}
else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use } else { on a single line. Sorry for this nitpicking



$batch = array();
$arrays = array();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use such generic names.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I had been meaning to change this one. Coding late at night means limited creativity 💤

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙂

$arrays = array();

//split display name into individual words for flexible matching
$arrays[0] = $this->userManager->search($pattern, $limit, $offset);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use searchResult or something more descriptive.


//if the pattern to search for isn't potentially complex, just call searchDisplayName with it
if (count($subPatterns) == 1) {
$arrays[1] = $this->userManager->searchDisplayName($pattern, $limit, $offset);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use displaynameSearchResult or something more descriptive here instead of $array[1]

}

// TODO: allow partial strings for email matches
$arrays[2] = $this->userManager->getByEmail($pattern);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use emailSearchResult or something more descriptive here


// TODO: allow partial strings for email matches
$arrays[2] = $this->userManager->getByEmail($pattern);
foreach ($arrays as $arr) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either build here the array of arrays or simply call array_merge three times. It's more crucial to have readable code instead of clever or smart code.

Signed-off-by: justin-sleep <justin@quarterfull.com>
Signed-off-by: justin-sleep <justin@quarterfull.com>
@hregnier
Copy link

thanks @justin-sleep it seems to works! Some bug appear (If i search "John " only one john on the dozens appear, but typing another letter or trim the space refresh the search) but it's not so disturbing compare to the improvement :)

@justin-sleep
Copy link
Member Author

@hregnier I'm having trouble replicating what you're describing. This is what I'm doing to try to run into your bug:

  • Create multiple users named John (e.g. display name is John Doe, John Goodman, etc.) with random usernames
  • Type "John " into the search bar

But for me, this returns a list that contains every user whose display name contains John. Could you clarify the properties of the users that aren't getting returned?

@hregnier
Copy link

That's a problem. I can't get you clearer information because i can't find any pattern of the bug.

Another example : I have a user who username is "Dupont Jean". I can't find him when I search "dupont jean" but find him with "jean dupont" ! But I do not have the same problem with every user...

I understand you can't reproduce the bug. I can't show you a real set of users, although it should be usefull.

Copy link
Member

@MorrisJobke MorrisJobke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works here 👍

@MorrisJobke
Copy link
Member

@blizzz Could you give this a try?

cc @nickvergessen @rullzer @schiessle @icewind1991


// TODO: allow partial strings for email matches
$emailSearchResult = $this->userManager->getByEmail($pattern);
$searchResults = array($uidSearchResult, $displayNameSearchResult, $emailSearchResult);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They all are arrays only, so you can simply do:

$batch = array_merge($uidSearchResult, $displayNameSearchResult, $emailSearchResult);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Signed-off-by: justin-sleep <justin@quarterfull.com>
Copy link
Member

@blizzz blizzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I like this approach. Basically it forces this search behavior over all user backends. Especially in case of LDAP it would fire 2 searches (plus the local email lookup, unnecessarily) for "Joann Doe" while the LDAP backend supports this all already, in just one go. I'd prefer to have this implemented on the specific backend.

@ChristophWurst
Copy link
Member

@justin-sleep @nickvergessen @blizzz what's the status here? How can we proceed with this?

@justin-sleep
Copy link
Member Author

@ChristophWurst I haven't proceeded with the changes @blizzz requested. I haven't looked into the codebase enough to know where the individual backends are located to implement the changes there rather than in UsersController, so if someone could point me to the backends I could give it a look.

@blizzz
Copy link
Member

blizzz commented Mar 8, 2017

@justin-sleep starting point for local backend: https://github.com/nextcloud/server/blob/master/lib/private/User/Database.php

LDAP backend allows this already, so it does not need to be touched.

I have no overview about other backends.

@MorrisJobke MorrisJobke added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Mar 8, 2017
@MorrisJobke MorrisJobke removed this from the Nextcloud 12.0 milestone May 9, 2017
@rullzer rullzer added this to the Nextcloud 13 milestone May 23, 2017
@blizzz
Copy link
Member

blizzz commented Nov 13, 2017

moving to 14 due to freeze. @justin-sleep are you still interested in finishing it?

@MorrisJobke
Copy link
Member

The search for displayname is fixed with #7169

@MorrisJobke MorrisJobke self-assigned this Nov 14, 2017
@MorrisJobke
Copy link
Member

There is only the search by email missing. And as it needs to be done in a similar place like #7169 I will close this and have opened a issue for this remaining thing in #7175.

@MorrisJobke MorrisJobke removed this from the Nextcloud 14 milestone Nov 14, 2017
@MorrisJobke MorrisJobke removed their assignment Nov 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User search in admin/groupadmin panel only on uid
9 participants