aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2020-12-12 00:25:10 +0100
committerArthur Schiwon <blizzz@arthur-schiwon.de>2020-12-15 11:53:39 +0100
commitd8ad4ef6b5fc038e8187dc285925cd1a0d7fb5bf (patch)
tree2ecbc4bf0bcd0737f7cf57ecb6bbee22982a1928
parent2b017b704a4a49801bc09774a1a17cfedca9cc7e (diff)
downloadnextcloud-server-d8ad4ef6b5fc038e8187dc285925cd1a0d7fb5bf.tar.gz
nextcloud-server-d8ad4ef6b5fc038e8187dc285925cd1a0d7fb5bf.zip
use a consistent default value for sharing.maxAutocompleteResults
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
-rw-r--r--apps/dav/lib/Connector/Sabre/Principal.php6
-rw-r--r--apps/dav/lib/DAV/GroupPrincipalBackend.php6
-rw-r--r--apps/files_sharing/lib/Controller/ShareesAPIController.php3
-rw-r--r--apps/files_sharing/src/services/ConfigService.js2
-rw-r--r--config/config.sample.php13
-rw-r--r--lib/private/Contacts/ContactsMenu/Manager.php3
-rw-r--r--lib/private/Template/JSConfigHelper.php5
-rw-r--r--lib/public/Constants.php6
-rw-r--r--tests/lib/Contacts/ContactsMenu/ManagerTest.php7
9 files changed, 38 insertions, 13 deletions
diff --git a/apps/dav/lib/Connector/Sabre/Principal.php b/apps/dav/lib/Connector/Sabre/Principal.php
index 12e1d18faa2..bf03569bd5b 100644
--- a/apps/dav/lib/Connector/Sabre/Principal.php
+++ b/apps/dav/lib/Connector/Sabre/Principal.php
@@ -39,6 +39,7 @@ use OCA\DAV\CalDAV\Proxy\ProxyMapper;
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;
@@ -270,7 +271,10 @@ class Principal implements BackendInterface {
}
}
- $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':
diff --git a/apps/dav/lib/DAV/GroupPrincipalBackend.php b/apps/dav/lib/DAV/GroupPrincipalBackend.php
index 747976b6ad3..8b9c5aa9488 100644
--- a/apps/dav/lib/DAV/GroupPrincipalBackend.php
+++ b/apps/dav/lib/DAV/GroupPrincipalBackend.php
@@ -27,6 +27,7 @@
namespace OCA\DAV\DAV;
+use OCP\Constants;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
@@ -212,7 +213,10 @@ class GroupPrincipalBackend implements BackendInterface {
$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':
diff --git a/apps/files_sharing/lib/Controller/ShareesAPIController.php b/apps/files_sharing/lib/Controller/ShareesAPIController.php
index a2b39b40772..70f016d81f2 100644
--- a/apps/files_sharing/lib/Controller/ShareesAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareesAPIController.php
@@ -36,6 +36,7 @@ declare(strict_types=1);
namespace OCA\Files_Sharing\Controller;
+use OCP\Constants;
use function array_slice;
use function array_values;
use Generator;
@@ -148,7 +149,7 @@ class ShareesAPIController extends OCSController {
}
// 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);
}
diff --git a/apps/files_sharing/src/services/ConfigService.js b/apps/files_sharing/src/services/ConfigService.js
index a825bcb7d11..0971bc387a3 100644
--- a/apps/files_sharing/src/services/ConfigService.js
+++ b/apps/files_sharing/src/services/ConfigService.js
@@ -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
}
/**
diff --git a/config/config.sample.php b/config/config.sample.php
index 8adb5bf2168..50bf46353e4 100644
--- a/config/config.sample.php
+++ b/config/config.sample.php
@@ -1410,10 +1410,17 @@ $CONFIG = [
'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
diff --git a/lib/private/Contacts/ContactsMenu/Manager.php b/lib/private/Contacts/ContactsMenu/Manager.php
index 8f772b8e027..d08db5775e5 100644
--- a/lib/private/Contacts/ContactsMenu/Manager.php
+++ b/lib/private/Contacts/ContactsMenu/Manager.php
@@ -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;
@@ -63,7 +64,7 @@ class Manager {
* @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) {
diff --git a/lib/private/Template/JSConfigHelper.php b/lib/private/Template/JSConfigHelper.php
index ebe799bf4f8..83c8d7c0e42 100644
--- a/lib/private/Template/JSConfigHelper.php
+++ b/lib/private/Template/JSConfigHelper.php
@@ -33,6 +33,7 @@ namespace OC\Template;
use bantu\IniGetWrapper\IniGetWrapper;
use OC\CapabilitiesManager;
use OCP\App\IAppManager;
+use OCP\Constants;
use OCP\Defaults;
use OCP\IConfig;
use OCP\IGroupManager;
@@ -189,8 +190,8 @@ class JSConfigHelper {
'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,
];
diff --git a/lib/public/Constants.php b/lib/public/Constants.php
index 2653031a430..64872821582 100644
--- a/lib/public/Constants.php
+++ b/lib/public/Constants.php
@@ -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;
}
diff --git a/tests/lib/Contacts/ContactsMenu/ManagerTest.php b/tests/lib/Contacts/ContactsMenu/ManagerTest.php
index 4cfbd9c7c90..2f5acf61644 100644
--- a/tests/lib/Contacts/ContactsMenu/ManagerTest.php
+++ b/tests/lib/Contacts/ContactsMenu/ManagerTest.php
@@ -28,6 +28,7 @@ use OC\Contacts\ContactsMenu\ActionProviderStore;
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;
@@ -82,7 +83,7 @@ class ManagerTest extends TestCase {
$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')
@@ -120,7 +121,7 @@ class ManagerTest extends TestCase {
$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')
@@ -157,7 +158,7 @@ class ManagerTest extends TestCase {
$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')