Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reduce search providers per config value "unified_search_providers_allowed" #46

Merged
merged 5 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion IONOS
Submodule IONOS updated from a09839 to b4bf18
9 changes: 9 additions & 0 deletions core/src/components/UnifiedSearch/UnifiedSearchModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
</NcActionButton>
</NcActions>
<SearchableList :label-text="t('core', 'Search people')"
v-if="peopleSearchEnabled"
:search-list="userContacts"
:empty-content-text="t('core', 'Not found')"
data-cy-unified-search-filter="people"
Expand Down Expand Up @@ -225,6 +226,14 @@ export default defineComponent({
type: Boolean,
default: false,
},

/**
* Show people search filter
*/
peopleSearchEnabled: {
type: Boolean,
default: false,
}
},

emits: ['update:open', 'update:query'],
Expand Down
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
Loading