Skip to content
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
35 changes: 8 additions & 27 deletions apps/settings/lib/Search/UserSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright Copyright (c) 2023 Stephan Orbaugh <[email protected]>
*
* @author Stephan Orbaugh <[email protected]>
*
* @author Benjamin Gaussorgues <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
Expand All @@ -33,45 +33,26 @@
use OCP\Search\SearchResult;

class UserSearch implements IProvider {


/** @var IL10N */
protected $l;

public function __construct(
IL10N $l) {
$this->l = $l;
private IL10N $l,
) {
}

/**
* @inheritDoc
*/
public function getId(): string {
return 'users';
}

/**
* @inheritDoc
*/
public function getName(): string {
return $this->l->t('Users');
}

/**
* @inheritDoc
*/
public function getOrder(string $route, array $routeParameters): int {
return 300;
public function getOrder(string $route, array $routeParameters): ?int {
return $route === 'settings.Users.usersList'
? 300
: null;
}

/**
* @inheritDoc
*/
public function search(IUser $user, ISearchQuery $query): SearchResult {

return SearchResult::complete(
$this->l->t('Users'),
[]
);
return SearchResult::complete($this->l->t('Users'), []);
}
}
7 changes: 6 additions & 1 deletion lib/private/Search/SearchComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ public function getProviders(string $route, array $routeParameters): array {
function (array $providerData) use ($route, $routeParameters) {
$appId = $providerData['appId'];
$provider = $providerData['provider'];
$order = $provider->getOrder($route, $routeParameters);
if ($order === null) {
return;
}
$triggers = [$provider->getId()];
if ($provider instanceof IFilteringProvider) {
$triggers += $provider->getAlternateIds();
Expand All @@ -197,14 +201,15 @@ function (array $providerData) use ($route, $routeParameters) {
'appId' => $appId,
'name' => $provider->getName(),
'icon' => $this->fetchIcon($appId, $provider->getId()),
'order' => $provider->getOrder($route, $routeParameters),
'order' => $order,
'triggers' => $triggers,
'filters' => $this->getFiltersType($filters, $provider->getId()),
'inAppSearch' => $provider instanceof IInAppSearch,
];
},
$this->providers,
);
$providers = array_filter($providers);

// Sort providers by order and strip associative keys
usort($providers, function ($provider1, $provider2) {
Expand Down
6 changes: 4 additions & 2 deletions lib/public/Search/IProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ public function getName(): string;
/**
* Get the search provider order
* The lower the int, the higher it will be sorted (0 will be before 10)
* If null, the search provider will be hidden in the UI and the API not called
*
* @param string $route the route the user is currently at, e.g. files.view.index
* @param array $routeParameters the parameters of the route the user is currently at, e.g. [fileId = 982, dir = "/"]
*
* @return int
* @return int|null
*
* @since 20.0.0
* @since 28.0.0 Can return null
*/
public function getOrder(string $route, array $routeParameters): int;
public function getOrder(string $route, array $routeParameters): ?int;

/**
* Find matching search entries in an app
Expand Down