diff --git a/config/config.sample.php b/config/config.sample.php index c8ee3c301aec3..b3fe801f29104 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -2534,6 +2534,15 @@ */ 'unified_search.enabled' => false, +/** + * List of search providers that are allowed to be used in the unified search + * + * Defaults to ``[]`` (all providers allowed) + * + * For example: Set to ['files', 'settings'] to only allow file and settings search. + */ +'unified_search_providers_allowed' => [], + /** * Enable features that are do respect accessibility standards yet. * diff --git a/core/src/components/UnifiedSearch/UnifiedSearchModal.vue b/core/src/components/UnifiedSearch/UnifiedSearchModal.vue index ef0883c5b25dc..3b5406149f9da 100644 --- a/core/src/components/UnifiedSearch/UnifiedSearchModal.vue +++ b/core/src/components/UnifiedSearch/UnifiedSearchModal.vue @@ -325,6 +325,7 @@ export default defineComponent({ subscribe('nextcloud:unified-search:add-filter', this.handlePluginFilter) getProviders().then((providers) => { this.providers = providers + unifiedSearchLogger.debug(`getProviders`, { providers: this.providers }) this.externalFilters.forEach(filter => { this.providers.push(filter) }) diff --git a/lib/private/Search/SearchComposer.php b/lib/private/Search/SearchComposer.php index d23662f7055ff..dc18bcdf2a6d8 100644 --- a/lib/private/Search/SearchComposer.php +++ b/lib/private/Search/SearchComposer.php @@ -10,6 +10,7 @@ use InvalidArgumentException; use OC\AppFramework\Bootstrap\Coordinator; +use OCP\IConfig; use OCP\IURLGenerator; use OCP\IUser; use OCP\Search\FilterDefinition; @@ -23,7 +24,10 @@ 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 @@ -60,6 +64,7 @@ public function __construct( private ContainerInterface $container, private IURLGenerator $urlGenerator, private LoggerInterface $logger, + private IConfig $config, ) { $this->commonFilters = [ IFilter::BUILTIN_TERM => new FilterDefinition(IFilter::BUILTIN_TERM, FilterDefinition::TYPE_STRING), @@ -197,7 +202,24 @@ function (array $providerData) use ($route, $routeParameters) { return $provider1['order'] <=> $provider2['order']; }); - return $providers; + return $this->reduceProviders($providers); + } + + /** + * reduce providers based on 'unified_search_providers_allowed' config array + * @param array $providers + * @return array + */ + private function reduceProviders(array $providers): array { + $allowedProviders = $this->config->getSystemValue('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 {