Skip to content

Commit d660b08

Browse files
authored
Merge pull request #48841 from IONOS-Productivity/feat/config_unified_search_providers_allowed
feat: reduce search providers per config value "unified_search_providers_allowed"
2 parents dea6bd7 + 8e57004 commit d660b08

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/private/Search/SearchComposer.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use InvalidArgumentException;
1212
use OC\AppFramework\Bootstrap\Coordinator;
1313
use OC\Core\ResponseDefinitions;
14+
use OCP\IAppConfig;
1415
use OCP\IURLGenerator;
1516
use OCP\IUser;
1617
use OCP\Search\FilterDefinition;
@@ -24,7 +25,10 @@
2425
use Psr\Container\ContainerInterface;
2526
use Psr\Log\LoggerInterface;
2627
use RuntimeException;
28+
use function array_filter;
2729
use function array_map;
30+
use function array_values;
31+
use function in_array;
2832

2933
/**
3034
* Queries individual \OCP\Search\IProvider implementations and composes a
@@ -62,6 +66,7 @@ public function __construct(
6266
private ContainerInterface $container,
6367
private IURLGenerator $urlGenerator,
6468
private LoggerInterface $logger,
69+
private IAppConfig $appConfig,
6570
) {
6671
$this->commonFilters = [
6772
IFilter::BUILTIN_TERM => new FilterDefinition(IFilter::BUILTIN_TERM, FilterDefinition::TYPE_STRING),
@@ -113,6 +118,8 @@ private function loadLazyProviders(?string $targetProviderId = null): void {
113118
}
114119
}
115120

121+
$this->providers = $this->filterProviders($this->providers);
122+
116123
$this->loadFilters();
117124
}
118125

@@ -202,6 +209,23 @@ function (array $providerData) use ($route, $routeParameters) {
202209
return $providers;
203210
}
204211

212+
/**
213+
* Filter providers based on 'unified_search.providers_allowed' core app config array
214+
* @param array $providers
215+
* @return array
216+
*/
217+
private function filterProviders(array $providers): array {
218+
$allowedProviders = $this->appConfig->getValueArray('core', 'unified_search.providers_allowed');
219+
220+
if (empty($allowedProviders)) {
221+
return $providers;
222+
}
223+
224+
return array_values(array_filter($providers, function ($p) use ($allowedProviders) {
225+
return in_array($p['id'], $allowedProviders);
226+
}));
227+
}
228+
205229
private function fetchIcon(string $appId, string $providerId): string {
206230
$icons = [
207231
[$providerId, $providerId . '.svg'],

0 commit comments

Comments
 (0)