Skip to content

Commit

Permalink
[FEATURE] Add authentication check for lead detail view
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Feb 27, 2024
1 parent c0029f1 commit b2e07c8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Classes/Controller/LeadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use In2code\Lux\Domain\Repository\CompanyRepository;
use In2code\Lux\Domain\Repository\VisitorRepository;
use In2code\Lux\Domain\Service\CompanyConfigurationService;
use In2code\Lux\Exception\AuthenticationException;
use In2code\Lux\Utility\BackendUtility;
use In2code\Lux\Utility\LocalizationUtility;
use In2code\Lux\Utility\ObjectUtility;
Expand Down Expand Up @@ -101,8 +102,16 @@ public function listAction(FilterDto $filter, string $export = ''): ResponseInte
return $this->defaultRendering();
}

/**
* @param Visitor $visitor
* @return ResponseInterface
* @throws AuthenticationException
*/
public function detailAction(Visitor $visitor): ResponseInterface
{
if ($visitor->canBeRead() === false) {
throw new AuthenticationException('Not allowed to view this visitor', 1709071863);
}
$filter = ObjectUtility::getFilterDtoFromStartAndEnd($visitor->getDateOfPagevisitFirst(), new DateTime())
->setVisitor($visitor);
$this->view->assignMultiple([
Expand Down
17 changes: 17 additions & 0 deletions Classes/Domain/Model/Visitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
use In2code\Lux\Domain\Service\Image\VisitorImageService;
use In2code\Lux\Domain\Service\Provider\Telecommunication;
use In2code\Lux\Domain\Service\ScoringService;
use In2code\Lux\Domain\Service\SiteService;
use In2code\Lux\Exception\ConfigurationException;
use In2code\Lux\Utility\BackendUtility;
use In2code\Lux\Utility\LocalizationUtility;
use In2code\Lux\Utility\ObjectUtility;
use In2code\Lux\Utility\StringUtility;
Expand Down Expand Up @@ -1125,6 +1127,21 @@ public function getLongitude(): string
return $lng;
}

/**
* Check if this visitor can be viewed by current editor
*
* @return bool
*/
public function canBeRead(): bool
{
if (BackendUtility::isAdministrator()) {
return true;
}
$sites = GeneralUtility::makeInstance(SiteService::class)->getAllowedSites();
return GeneralUtility::makeInstance(VisitorRepository::class)
->canVisitorBeReadBySites($this, array_keys($sites));
}

/**
* Sort all categoryscorings by scoring desc
*
Expand Down
11 changes: 11 additions & 0 deletions Classes/Domain/Repository/VisitorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,17 @@ public function findByCompany(Company $company, int $limit = 200): array
return $visitors;
}

public function canVisitorBeReadBySites(Visitor $visitor, array $sites): bool
{
$sql = 'select v.uid from ' . Visitor::TABLE_NAME . ' v'
. ' left join ' . Pagevisit::TABLE_NAME . ' pv on v.uid = pv.visitor'
. ' where v.deleted=0 and v.blacklisted=0 and v.uid=' . $visitor->getUid()
. ' and pv.site in ("' . implode('","', $sites) . '")'
. ' limit 1';
$connection = DatabaseUtility::getConnectionForTable(Visitor::TABLE_NAME);
return (int)$connection->executeQuery($sql)->fetchOne() > 0;
}

/**
* @param int $visitorIdentifier
* @param int $frontenduserIdentifier
Expand Down
10 changes: 10 additions & 0 deletions Classes/Exception/AuthenticationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);
namespace In2code\Lux\Exception;

use Exception;

class AuthenticationException extends Exception
{
}

0 comments on commit b2e07c8

Please sign in to comment.