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

Configurable minimum characters before autocomplete user searches #30798

Merged
merged 1 commit into from
Apr 3, 2018

Conversation

VicDeo
Copy link
Member

@VicDeo VicDeo commented Mar 15, 2018

Description

allow limit user/group search by a certain number of characters

Related Issue

#30313

Motivation and Context

For large user lists searching for the first two characters can be very slow to return.

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@VicDeo
Copy link
Member Author

VicDeo commented Mar 15, 2018

@PVince81 according to your spec from #30313 (comment)

Backend code UserManager and GroupManager refuse to work if the search pattern given to any find* and search* methods is shorter than the minimum. This saves us for modifying backend for any other endpoints.

I don't see a better place to block a search pattern length. As for decorators: it's possible to extend User|Group manager with LimitedUserManager | LimitedGroupManager class, overload the methods in question and make OC::$server to return LimitedUserManager instead of UserManager. But it looks too nerdy to me 👓

@VicDeo VicDeo added this to the development milestone Mar 15, 2018
@VicDeo VicDeo self-assigned this Mar 15, 2018
@PVince81
Copy link
Contributor

But adding isSearchable on the IUserManager interface also feels wrong, especially considering that it's not really a capability with that name but a utility function.

@DeepDiver1975 @butonic @jvillafanez any other fancy ideas ?

@VicDeo
Copy link
Member Author

VicDeo commented Mar 20, 2018

@PVince81 I have a fancy idea: non-static method inside \OCP\Util that makes DI possible.

@PVince81
Copy link
Contributor

@VicDeo sounds good. You can even invent new utility services in the server container that suit our purposes.

@jvillafanez
Copy link
Member

Maybe it's a good time to think about error handling in the user / group manager... returning an empty result just because you don't want to search with less than 4 chars feels bad because any user could think that there isn't any user, not that you're refusing to search with such little information.
Throwing an exception would be better, but it will likely need a lot of changes.

The problem is that the user / group manager doesn't specify any exception that could be thrown, so I don't expect any error handling to be in place, not even the default "catch all" exception handling with the "something went wrong" message.

For the specific check, it depends on how we want this to progress. If there are no plans to add similar functionality, adding the functions in the same class is fine if we consider it as implementation detail (and make those functions private). On the other hand, if we want to make restrictions based on the user type (maybe we want to allow the admin to do a less restrictive search), or any other, we'll likely need to move the functions to an specialized class.

@codecov
Copy link

codecov bot commented Mar 27, 2018

Codecov Report

Merging #30798 into master will increase coverage by <.01%.
The diff coverage is 88%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #30798      +/-   ##
============================================
+ Coverage      62.3%    62.3%   +<.01%     
+ Complexity    18396    18241     -155     
============================================
  Files          1141     1142       +1     
  Lines         68155    68177      +22     
  Branches       1232     1232              
============================================
+ Hits          42461    42481      +20     
- Misses        25333    25335       +2     
  Partials        361      361
Flag Coverage Δ Complexity Δ
#javascript 52.04% <ø> (ø) 0 <ø> (ø) ⬇️
#phpunit 63.48% <88%> (ø) 18241 <9> (-155) ⬇️
Impacted Files Coverage Δ Complexity Δ
core/js/sharedialogview.js 76.41% <ø> (ø) 0 <0> (ø) ⬇️
lib/private/Group/Manager.php 90% <100%> (+0.11%) 77 <1> (+1) ⬆️
lib/public/Util/UserSearch.php 100% <100%> (ø) 4 <4> (?)
lib/private/Server.php 84.98% <100%> (+0.09%) 254 <0> (ø) ⬇️
apps/files_sharing/lib/Capabilities.php 100% <100%> (ø) 6 <1> (ø) ⬇️
lib/private/User/Manager.php 80.95% <70%> (-0.61%) 56 <3> (+3)

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 744f742...7666497. Read the comment docs.

@VicDeo VicDeo force-pushed the fix-30313 branch 2 times, most recently from f3530c9 to 4c4332f Compare March 27, 2018 19:13
@PVince81
Copy link
Contributor

returning an empty result just because you don't want to search with less than 4 chars feels bad because any user could think that there isn't any user, not that you're refusing to search with such little information

The other alternative is finding all the current HTTP API endpoints that we have and add the limit there. This includes the sharing autocomplete, custom groups and potentially others (gallery app old share dialog)

/**
* This class provides functions to search users
*
* @since 10.1.0
Copy link
Contributor

Choose a reason for hiding this comment

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

make that 10.0.8

Copy link
Contributor

@PVince81 PVince81 left a comment

Choose a reason for hiding this comment

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

Fair enough, it looks like it's the best compromise 👍

see comment

@VicDeo VicDeo force-pushed the fix-30313 branch 5 times, most recently from 7990475 to bd606d0 Compare March 29, 2018 17:15
@VicDeo VicDeo changed the title [WIP] Configurable minimum characters before autocomplete user searches Configurable minimum characters before autocomplete user searches Mar 29, 2018
@VicDeo VicDeo force-pushed the fix-30313 branch 2 times, most recently from b28153d to 7bb43f1 Compare March 29, 2018 20:00
@VicDeo
Copy link
Member Author

VicDeo commented Apr 2, 2018

Comment addressed.
Fixed tests, rebased, squashed.

@PVince81 PVince81 merged commit b6be432 into master Apr 3, 2018
@PVince81 PVince81 deleted the fix-30313 branch April 3, 2018 07:22
@PVince81
Copy link
Contributor

PVince81 commented Apr 3, 2018

@VicDeo please backport

* @return mixed
*/
public function getSearchMinLength() {
return $this->config->getSystemValue('user.search_min_length', 4);
Copy link
Contributor

Choose a reason for hiding this comment

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

@pmaier1 note: now the minimum search length will be 4 by default, we'll add this to the release notes.
If an admin wants less or 0 they must change it manually.

Copy link
Member Author

@VicDeo VicDeo Apr 3, 2018

Choose a reason for hiding this comment

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

@PVince81 we decided allow zero length for backward compatibility reasons. /But I think this is a subject to remove and shouldn't be advertised/

@PVince81
Copy link
Contributor

PVince81 commented Apr 3, 2018

follow up for missed test failure: #30992

@PVince81
Copy link
Contributor

PVince81 commented Apr 3, 2018

@VicDeo can you backport with both PRs ?

@VicDeo
Copy link
Member Author

VicDeo commented Apr 3, 2018

@PVince81 Sure. Do you mean 'both PRs as single PR'?

@VicDeo
Copy link
Member Author

VicDeo commented Apr 3, 2018

Stable10: #30994

@lock
Copy link

lock bot commented Jul 31, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants