Skip to content

Commit

Permalink
feat(search): reduce search providers via config unified_search_provi…
Browse files Browse the repository at this point in the history
…ders_allowed

reduce search providers by setting config value to unified_search_providers_allowed = [ 'files', 'setting' ]

./occ config:system:set unified_search_providers_allowed 0 --value files
./occ config:system:set unified_search_providers_allowed 1 --value settings

Signed-off-by: Misha M.-Kupriyanov <kupriyanov@strato.de>
  • Loading branch information
printminion-co committed Oct 22, 2024
1 parent 8e4ac51 commit 8939114
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
9 changes: 9 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
1 change: 1 addition & 0 deletions core/src/components/UnifiedSearch/UnifiedSearchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Check failure on line 328 in core/src/components/UnifiedSearch/UnifiedSearchModal.vue

View workflow job for this annotation

GitHub Actions / NPM lint

Strings must use singlequote
this.externalFilters.forEach(filter => {
this.providers.push(filter)
})
Expand Down
24 changes: 23 additions & 1 deletion lib/private/Search/SearchComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use InvalidArgumentException;
use OC\AppFramework\Bootstrap\Coordinator;
use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Search\FilterDefinition;
Expand All @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8939114

Please sign in to comment.