Skip to content

Commit

Permalink
IONOS(search): reduce search providers via core config unified_search…
Browse files Browse the repository at this point in the history
….providers_allowed

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 <[email protected]>
  • Loading branch information
printminion-co committed Oct 28, 2024
1 parent 9b2c05c commit 65b102f
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions 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\IAppConfig;
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 @@ -59,7 +63,8 @@ public function __construct(
private Coordinator $bootstrapCoordinator,
private ContainerInterface $container,
private IURLGenerator $urlGenerator,
private LoggerInterface $logger
private LoggerInterface $logger,
private IAppConfig $appConfig,
) {
$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' core app config array
* @param array $providers
* @return array
*/
private function reduceProviders(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 {
Expand Down

0 comments on commit 65b102f

Please sign in to comment.