Skip to content

Commit

Permalink
[TASK] Live search should only show results if the backend user has a…
Browse files Browse the repository at this point in the history
…ccess to the leads module
  • Loading branch information
einpraegsam committed Nov 19, 2024
1 parent 0dabfab commit 990a344
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions Classes/Backend/LiveSearch/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@

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;
use TYPO3\CMS\Backend\Search\LiveSearch\ResultItemAction;
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
Expand All @@ -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()));
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 990a344

Please sign in to comment.