|
11 | 11 | use InvalidArgumentException; |
12 | 12 | use OC\AppFramework\Bootstrap\Coordinator; |
13 | 13 | use OC\Core\ResponseDefinitions; |
| 14 | +use OCP\IAppConfig; |
14 | 15 | use OCP\IURLGenerator; |
15 | 16 | use OCP\IUser; |
16 | 17 | use OCP\Search\FilterDefinition; |
|
24 | 25 | use Psr\Container\ContainerInterface; |
25 | 26 | use Psr\Log\LoggerInterface; |
26 | 27 | use RuntimeException; |
| 28 | +use function array_filter; |
27 | 29 | use function array_map; |
| 30 | +use function array_values; |
| 31 | +use function in_array; |
28 | 32 |
|
29 | 33 | /** |
30 | 34 | * Queries individual \OCP\Search\IProvider implementations and composes a |
@@ -62,6 +66,7 @@ public function __construct( |
62 | 66 | private ContainerInterface $container, |
63 | 67 | private IURLGenerator $urlGenerator, |
64 | 68 | private LoggerInterface $logger, |
| 69 | + private IAppConfig $appConfig, |
65 | 70 | ) { |
66 | 71 | $this->commonFilters = [ |
67 | 72 | IFilter::BUILTIN_TERM => new FilterDefinition(IFilter::BUILTIN_TERM, FilterDefinition::TYPE_STRING), |
@@ -113,6 +118,8 @@ private function loadLazyProviders(?string $targetProviderId = null): void { |
113 | 118 | } |
114 | 119 | } |
115 | 120 |
|
| 121 | + $this->providers = $this->filterProviders($this->providers); |
| 122 | + |
116 | 123 | $this->loadFilters(); |
117 | 124 | } |
118 | 125 |
|
@@ -202,6 +209,23 @@ function (array $providerData) use ($route, $routeParameters) { |
202 | 209 | return $providers; |
203 | 210 | } |
204 | 211 |
|
| 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 | + |
205 | 229 | private function fetchIcon(string $appId, string $providerId): string { |
206 | 230 | $icons = [ |
207 | 231 | [$providerId, $providerId . '.svg'], |
|
0 commit comments