From 990a3443f290b9f0e93db5e46b5f0c669da4f7ca Mon Sep 17 00:00:00 2001 From: Alexander Kellner Date: Tue, 19 Nov 2024 19:23:07 +0100 Subject: [PATCH] [TASK] Live search should only show results if the backend user has access to the leads module --- Classes/Backend/LiveSearch/Visitor.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Classes/Backend/LiveSearch/Visitor.php b/Classes/Backend/LiveSearch/Visitor.php index 6d908086..4f4b08ec 100644 --- a/Classes/Backend/LiveSearch/Visitor.php +++ b/Classes/Backend/LiveSearch/Visitor.php @@ -6,7 +6,9 @@ use In2code\Lux\Domain\Model\Visitor as VisitorModel; use In2code\Lux\Domain\Repository\VisitorRepository; +use In2code\Lux\Utility\BackendUtility; use In2code\Lux\Utility\ObjectUtility; +use TYPO3\CMS\Backend\Module\ModuleProvider; use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException; use TYPO3\CMS\Backend\Routing\UriBuilder; use TYPO3\CMS\Backend\Search\LiveSearch\ResultItem; @@ -14,6 +16,7 @@ use TYPO3\CMS\Backend\Search\LiveSearch\SearchDemand\SearchDemand; use TYPO3\CMS\Backend\Search\LiveSearch\SearchProviderInterface; use TYPO3\CMS\Core\Imaging\IconFactory; +use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException; class Visitor implements SearchProviderInterface @@ -36,6 +39,9 @@ public function __construct( */ public function count(SearchDemand $searchDemand): int { + if ($this->isEnabled() === false) { + return 0; + } return count($this->getResults($searchDemand->getQuery())); } @@ -48,8 +54,10 @@ public function count(SearchDemand $searchDemand): int public function find(SearchDemand $searchDemand): array { $resultItems = []; - foreach ($this->getResults($searchDemand->getQuery()) as $visitor) { - $resultItems[] = $this->getResultItem($visitor); + if ($this->isEnabled()) { + foreach ($this->getResults($searchDemand->getQuery()) as $visitor) { + $resultItems[] = $this->getResultItem($visitor); + } } return $resultItems; } @@ -114,4 +122,17 @@ protected function getResults(string $searchTerm): array } return $this->results; } + + /** + * Check if backend user has access to the leads module + * + * @return bool + */ + protected function isEnabled(): bool + { + /** @var ModuleProvider $moduleProvider */ + $moduleProvider = GeneralUtility::makeInstance(ModuleProvider::class); + return BackendUtility::getBackendUserAuthentication() !== null && + $moduleProvider->accessGranted('lux_LuxLead', BackendUtility::getBackendUserAuthentication()); + } }