From 02e8021126f9ac677e7aa1734943409713350683 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 21 Feb 2024 10:32:03 +0100 Subject: [PATCH] fix(search): Hide search providers when not allowed to use Talk Signed-off-by: Joas Schilling --- lib/Search/ConversationSearch.php | 11 ++++++++++- lib/Search/CurrentMessageSearch.php | 5 +++++ lib/Search/MessageSearch.php | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/Search/ConversationSearch.php b/lib/Search/ConversationSearch.php index 775c5861e0a..7a1f8b0dd6a 100644 --- a/lib/Search/ConversationSearch.php +++ b/lib/Search/ConversationSearch.php @@ -26,12 +26,14 @@ namespace OCA\Talk\Search; use OCA\Talk\AppInfo\Application; +use OCA\Talk\Config; use OCA\Talk\Manager; use OCA\Talk\Room; use OCA\Talk\Service\AvatarService; use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; +use OCP\IUserSession; use OCP\Search\IProvider; use OCP\Search\ISearchQuery; use OCP\Search\SearchResult; @@ -44,6 +46,8 @@ public function __construct( protected Manager $manager, protected IURLGenerator $url, protected IL10N $l, + protected Config $talkConfig, + protected IUserSession $userSession, ) { } @@ -64,7 +68,12 @@ public function getName(): string { /** * @inheritDoc */ - public function getOrder(string $route, array $routeParameters): int { + public function getOrder(string $route, array $routeParameters): ?int { + $currentUser = $this->userSession->getUser(); + if ($currentUser && $this->talkConfig->isDisabledForUser($currentUser)) { + return null; + } + if (str_starts_with($route, Application::APP_ID . '.')) { // Active app, prefer Talk results return -1; diff --git a/lib/Search/CurrentMessageSearch.php b/lib/Search/CurrentMessageSearch.php index 2cffdeb45ca..c833bec8aa6 100644 --- a/lib/Search/CurrentMessageSearch.php +++ b/lib/Search/CurrentMessageSearch.php @@ -48,6 +48,11 @@ public function getName(): string { * @inheritDoc */ public function getOrder(string $route, array $routeParameters): ?int { + $currentUser = $this->userSession->getUser(); + if ($currentUser && $this->talkConfig->isDisabledForUser($currentUser)) { + return null; + } + if ($route === 'spreed.Page.showCall') { // In conversation, prefer this search results return -3; diff --git a/lib/Search/MessageSearch.php b/lib/Search/MessageSearch.php index 1714a625028..3697cd782ef 100644 --- a/lib/Search/MessageSearch.php +++ b/lib/Search/MessageSearch.php @@ -26,6 +26,7 @@ use OCA\Talk\AppInfo\Application; use OCA\Talk\Chat\ChatManager; use OCA\Talk\Chat\MessageParser; +use OCA\Talk\Config; use OCA\Talk\Exceptions\ParticipantNotFoundException; use OCA\Talk\Exceptions\RoomNotFoundException; use OCA\Talk\Exceptions\UnauthorizedException; @@ -39,6 +40,7 @@ use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUser; +use OCP\IUserSession; use OCP\Search\FilterDefinition; use OCP\Search\IFilter; use OCP\Search\IFilteringProvider; @@ -61,6 +63,8 @@ public function __construct( protected ITimeFactory $timeFactory, protected IURLGenerator $url, protected IL10N $l, + protected Config $talkConfig, + protected IUserSession $userSession, ) { } @@ -82,6 +86,11 @@ public function getName(): string { * @inheritDoc */ public function getOrder(string $route, array $routeParameters): ?int { + $currentUser = $this->userSession->getUser(); + if ($currentUser && $this->talkConfig->isDisabledForUser($currentUser)) { + return null; + } + if (str_starts_with($route, Application::APP_ID . '.')) { // Active app, prefer Talk results return -2;