]> source.dussan.org Git - nextcloud-server.git/commitdiff
feat(search): reduce search providers via core app config unified_search.providers_al... artonge/local/IONOS/feat/config_unified_search_providers_allowed 48841/head 49246/head
authorMisha M.-Kupriyanov <kupriyanov@strato.de>
Mon, 9 Sep 2024 13:50:27 +0000 (15:50 +0200)
committerMisha M.-Kupriyanov <kupriyanov@strato.de>
Wed, 13 Nov 2024 10:15:24 +0000 (11:15 +0100)
reduce search providers by setting core config value to unified_search.providers_allowed = [ 'files', 'setting' ]

./occ config:app:set --value '["files","settings"]' --type array core unified_search.providers_allowed

Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
lib/private/Search/SearchComposer.php

index 71fd003717c0183fcea11728db815f25533150ba..77d7ca62311c23fab1fd275ae74742c236975e80 100644 (file)
@@ -11,6 +11,7 @@ namespace OC\Search;
 use InvalidArgumentException;
 use OC\AppFramework\Bootstrap\Coordinator;
 use OC\Core\ResponseDefinitions;
+use OCP\IAppConfig;
 use OCP\IURLGenerator;
 use OCP\IUser;
 use OCP\Search\FilterDefinition;
@@ -24,7 +25,10 @@ use Psr\Container\ContainerExceptionInterface;
 use Psr\Container\ContainerInterface;
 use Psr\Log\LoggerInterface;
 use RuntimeException;
+use function array_filter;
 use function array_map;
+use function array_values;
+use function in_array;
 
 /**
  * Queries individual \OCP\Search\IProvider implementations and composes a
@@ -62,6 +66,7 @@ class SearchComposer {
                private ContainerInterface $container,
                private IURLGenerator $urlGenerator,
                private LoggerInterface $logger,
+               private IAppConfig $appConfig,
        ) {
                $this->commonFilters = [
                        IFilter::BUILTIN_TERM => new FilterDefinition(IFilter::BUILTIN_TERM, FilterDefinition::TYPE_STRING),
@@ -113,6 +118,8 @@ class SearchComposer {
                        }
                }
 
+               $this->providers = $this->filterProviders($this->providers);
+
                $this->loadFilters();
        }
 
@@ -202,6 +209,23 @@ class SearchComposer {
                return $providers;
        }
 
+       /**
+        * Filter providers based on 'unified_search.providers_allowed' core app config array
+        * @param array $providers
+        * @return array
+        */
+       private function filterProviders(array $providers): array {
+               $allowedProviders = $this->appConfig->getValueArray('core', 'unified_search.providers_allowed');
+
+               if (empty($allowedProviders)) {
+                       return $providers;
+               }
+
+               return array_values(array_filter($providers, function ($p) use ($allowedProviders) {
+                       return in_array($p['id'], $allowedProviders);
+               }));
+       }
+
        private function fetchIcon(string $appId, string $providerId): string {
                $icons = [
                        [$providerId, $providerId . '.svg'],