From eeb3b2792a3e4caf44748aa54d7e96acef173240 Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi Date: Mon, 17 Jul 2023 16:20:21 +0545 Subject: [PATCH] Enable links preview even when the global search is not enabled Signed-off-by: Swikriti Tripathi --- .../WorkPackageReferenceProvider.php | 14 -------------- lib/Search/OpenProjectSearchProvider.php | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/lib/Reference/WorkPackageReferenceProvider.php b/lib/Reference/WorkPackageReferenceProvider.php index eb4348091..b3e26e56d 100644 --- a/lib/Reference/WorkPackageReferenceProvider.php +++ b/lib/Reference/WorkPackageReferenceProvider.php @@ -80,20 +80,6 @@ public function getIconUrl(): string { * @inheritDoc */ public function getSupportedSearchProviderIds(): array { - if ($this->userId !== null) { - $ids = []; - // take the fallback value from the defaults - $searchEnabled = $this->config->getUserValue( - $this->userId, - Application::APP_ID, - 'search_enabled', - $this->config->getAppValue(Application::APP_ID, 'default_enable_unified_search', '0') - ); - if ($searchEnabled) { - $ids[] = 'openproject-search'; - } - return $ids; - } return ['openproject-search']; } diff --git a/lib/Search/OpenProjectSearchProvider.php b/lib/Search/OpenProjectSearchProvider.php index da6a529b5..e6a85957b 100644 --- a/lib/Search/OpenProjectSearchProvider.php +++ b/lib/Search/OpenProjectSearchProvider.php @@ -111,14 +111,23 @@ public function search(IUser $user, ISearchQuery $query): SearchResult { $openprojectUrl = OpenProjectAPIService::sanitizeUrl($this->config->getAppValue(Application::APP_ID, 'openproject_instance_url')); $accessToken = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'token'); - $searchEnabled = $this->config->getUserValue( - $user->getUID(), - Application::APP_ID, 'search_enabled', - $this->config->getAppValue(Application::APP_ID, 'default_enable_unified_search', '0')) === '1'; - if ($accessToken === '' || !$searchEnabled) { + if ($accessToken === '') { return SearchResult::paginated($this->getName(), [], 0); } + $routeFrom = $query->getRoute(); + $requestedFromSmartPicker = $routeFrom === '' || $routeFrom === 'smart-picker'; + + if (!$requestedFromSmartPicker) { + $searchEnabled = $this->config->getUserValue( + $user->getUID(), + Application::APP_ID, 'search_enabled', + $this->config->getAppValue(Application::APP_ID, 'default_enable_unified_search', '0')) === '1'; + if (!$searchEnabled) { + return SearchResult::paginated($this->getName(), [], 0); + } + } + $searchResults = $this->service->searchWorkPackage($user->getUID(), $term, null, false); $searchResults = array_slice($searchResults, $offset, $limit);