diff options
author | Louis <louis@chmn.me> | 2024-11-13 12:24:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-13 12:24:56 +0100 |
commit | d660b0813a8fda5722f868cc08e371d0308b8258 (patch) | |
tree | 0213b21d8acfb971f06dade04d2a86fbe4f39371 | |
parent | dea6bd73620b2a033f59b506b1c5f1466d37dd54 (diff) | |
parent | 8e570041a533dc958d22f4998988abf31e0a58bf (diff) | |
download | nextcloud-server-d660b0813a8fda5722f868cc08e371d0308b8258.tar.gz nextcloud-server-d660b0813a8fda5722f868cc08e371d0308b8258.zip |
Merge pull request #48841 from IONOS-Productivity/feat/config_unified_search_providers_allowed
feat: reduce search providers per config value "unified_search_providers_allowed"
-rw-r--r-- | lib/private/Search/SearchComposer.php | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/private/Search/SearchComposer.php b/lib/private/Search/SearchComposer.php index 71fd003717c..77d7ca62311 100644 --- a/lib/private/Search/SearchComposer.php +++ b/lib/private/Search/SearchComposer.php @@ -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'], |