use InvalidArgumentException;
use OC\AppFramework\Bootstrap\Coordinator;
use OC\Core\ResponseDefinitions;
+use OCP\IAppConfig;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\Search\FilterDefinition;
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
private ContainerInterface $container,
private IURLGenerator $urlGenerator,
private LoggerInterface $logger,
+ private IAppConfig $appConfig,
) {
$this->commonFilters = [
IFilter::BUILTIN_TERM => new FilterDefinition(IFilter::BUILTIN_TERM, FilterDefinition::TYPE_STRING),
}
}
+ $this->providers = $this->filterProviders($this->providers);
+
$this->loadFilters();
}
return $providers;
}
+ /**
+ * Filter providers based on 'unified_search.providers_allowed' core app config array
+ * @param array $providers
+ * @return array
+ */
+ private function filterProviders(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 {
$icons = [
[$providerId, $providerId . '.svg'],