Skip to content

Commit

Permalink
use a consistent default value for sharing.maxAutocompleteResults
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Dec 11, 2020
1 parent 6c04584 commit c8a933e
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 13 deletions.
6 changes: 5 additions & 1 deletion apps/dav/lib/Connector/Sabre/Principal.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use OCA\DAV\Traits\PrincipalProxyTrait;
use OCP\App\IAppManager;
use OCP\AppFramework\QueryException;
use OCP\Constants;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUser;
Expand Down Expand Up @@ -270,7 +271,10 @@ protected function searchUserPrincipals(array $searchProperties, $test = 'allof'
}
}

$searchLimit = $this->config->getSystemValue('sharing.maxAutocompleteResults', null);
$searchLimit = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT);
if($searchLimit <= 0) {
$searchLimit = null;
}
foreach ($searchProperties as $prop => $value) {
switch ($prop) {
case '{http://sabredav.org/ns}email-address':
Expand Down
6 changes: 5 additions & 1 deletion apps/dav/lib/DAV/GroupPrincipalBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

namespace OCA\DAV\DAV;

use OCP\Constants;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
Expand Down Expand Up @@ -212,7 +213,10 @@ public function searchPrincipals($prefixPath, array $searchProperties, $test = '
$restrictGroups = $this->groupManager->getUserGroupIds($user);
}

$searchLimit = $this->config->getSystemValue('sharing.maxAutocompleteResults', null);
$searchLimit = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT);
if($searchLimit <= 0) {
$searchLimit = null;
}
foreach ($searchProperties as $prop => $value) {
switch ($prop) {
case '{DAV:}displayname':
Expand Down
3 changes: 2 additions & 1 deletion apps/files_sharing/lib/Controller/ShareesAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

namespace OCA\Files_Sharing\Controller;

use OCP\Constants;
use function array_slice;
use function array_values;
use Generator;
Expand Down Expand Up @@ -148,7 +149,7 @@ public function search(string $search = '', string $itemType = null, int $page =
}

// never return more than the max. number of results configured in the config.php
$maxResults = (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0);
$maxResults = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT);
if ($maxResults > 0) {
$perPage = min($perPage, $maxResults);
}
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/src/services/ConfigService.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export default class Config {
* @memberof Config
*/
get maxAutocompleteResults() {
return parseInt(OC.config['sharing.maxAutocompleteResults'], 10) || 200
return parseInt(OC.config['sharing.maxAutocompleteResults'], 10) || 25
}

/**
Expand Down
13 changes: 10 additions & 3 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1410,10 +1410,17 @@
'sharing.managerFactory' => '\OC\Share20\ProviderFactory',

/**
* Define max number of results returned by the user search for auto-completion
* Default is unlimited (value set to 0).
* Define max number of results returned by the search for auto-completion of
* users, groups, etc. The value must not be lower than 0 (for unlimited).
*
* If more, different sources are requested (e.g. different user backends; or
* both users and groups), the value is applied per source and might not be
* truncated after collecting the results. I.e. more results can appear than
* configured here.
*
* Default is 25.
*/
'sharing.maxAutocompleteResults' => 0,
'sharing.maxAutocompleteResults' => 25,

/**
* Define the minimum length of the search string before we start auto-completion
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Contacts/ContactsMenu/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace OC\Contacts\ContactsMenu;

use OCP\App\IAppManager;
use OCP\Constants;
use OCP\Contacts\ContactsMenu\IEntry;
use OCP\IConfig;
use OCP\IUser;
Expand Down Expand Up @@ -63,7 +64,7 @@ public function __construct(ContactsStore $store, ActionProviderStore $actionPro
* @return array
*/
public function getEntries(IUser $user, $filter) {
$maxAutocompleteResults = $this->config->getSystemValueInt('sharing.maxAutocompleteResults', 25);
$maxAutocompleteResults = max(0, $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT));
$minSearchStringLength = $this->config->getSystemValueInt('sharing.minSearchStringLength', 0);
$topEntries = [];
if (strlen($filter) >= $minSearchStringLength) {
Expand Down
5 changes: 3 additions & 2 deletions lib/private/Template/JSConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use bantu\IniGetWrapper\IniGetWrapper;
use OC\CapabilitiesManager;
use OCP\App\IAppManager;
use OCP\Constants;
use OCP\Defaults;
use OCP\IConfig;
use OCP\IGroupManager;
Expand Down Expand Up @@ -189,8 +190,8 @@ public function getConfig() {
'enable_avatars' => true, // here for legacy reasons - to not crash existing code that relies on this value
'lost_password_link' => $this->config->getSystemValue('lost_password_link', null),
'modRewriteWorking' => $this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true',
'sharing.maxAutocompleteResults' => (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0),
'sharing.minSearchStringLength' => (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0),
'sharing.maxAutocompleteResults' => max(0, $this->config->getSystemValueInt('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)),
'sharing.minSearchStringLength' => $this->config->getSystemValueInt('sharing.minSearchStringLength', 0),
'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX,
];

Expand Down
6 changes: 6 additions & 0 deletions lib/public/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,10 @@ class Constants {
* longer support windows as server platform.
*/
public const FILENAME_INVALID_CHARS = "\\/";

/**
* @since 21.0.0 – default value for autocomplete/search results limit,
* cf. sharing.maxAutocompleteResults in config.sample.php.
*/
public const SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT = 25;
}
7 changes: 4 additions & 3 deletions tests/lib/Contacts/ContactsMenu/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use OC\Contacts\ContactsMenu\ContactsStore;
use OC\Contacts\ContactsMenu\Manager;
use OCP\App\IAppManager;
use OCP\Constants;
use OCP\Contacts\ContactsMenu\IEntry;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IConfig;
Expand Down Expand Up @@ -82,7 +83,7 @@ public function testGetFilteredEntries() {

$this->config->expects($this->at(0))
->method('getSystemValueInt')
->with('sharing.maxAutocompleteResults', 25)
->with('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)
->willReturn(25);
$this->config->expects($this->at(1))
->method('getSystemValueInt')
Expand Down Expand Up @@ -120,7 +121,7 @@ public function testGetFilteredEntriesLimit() {

$this->config->expects($this->at(0))
->method('getSystemValueInt')
->with('sharing.maxAutocompleteResults', 25)
->with('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)
->willReturn(3);
$this->config->expects($this->at(1))
->method('getSystemValueInt')
Expand Down Expand Up @@ -157,7 +158,7 @@ public function testGetFilteredEntriesMinSearchStringLength() {

$this->config->expects($this->at(0))
->method('getSystemValueInt')
->with('sharing.maxAutocompleteResults', 25)
->with('sharing.maxAutocompleteResults', Constants::SHARING_MAX_AUTOCOMPLETE_RESULTS_DEFAULT)
->willReturn(3);
$this->config->expects($this->at(1))
->method('getSystemValueInt')
Expand Down

0 comments on commit c8a933e

Please sign in to comment.