-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
@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. |
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. |
@justin-sleep thanks for your PR! It works on my 30k+ users, no lags or whatever. |
@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. |
@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? |
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. |
@hregnier the latest commit I pushed should allow the more flexible display name matching you described. |
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
Signed-off-by: justin-sleep <justin@quarterfull.com>
Signed-off-by: justin-sleep <justin@quarterfull.com>
Signed-off-by: justin-sleep <justin@quarterfull.com>
//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 { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 💤
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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>
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 :) |
@hregnier I'm having trouble replicating what you're describing. This is what I'm doing to try to run into your bug:
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? |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works here 👍
@blizzz Could you give this a try? |
|
||
// TODO: allow partial strings for email matches | ||
$emailSearchResult = $this->userManager->getByEmail($pattern); | ||
$searchResults = array($uidSearchResult, $displayNameSearchResult, $emailSearchResult); |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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>
There was a problem hiding this 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.
@justin-sleep @nickvergessen @blizzz what's the status here? How can we proceed with this? |
@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. |
@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. |
moving to 14 due to freeze. @justin-sleep are you still interested in finishing it? |
The search for displayname is fixed with #7169 |
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