1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Module\Client\Read\Service; |
4
|
|
|
|
5
|
|
|
use App\Application\Data\UserNetworkSessionData; |
6
|
|
|
use App\Module\Authorization\Repository\AuthorizationUserRoleFinderRepository; |
|
|
|
|
7
|
|
|
use App\Module\User\Enum\UserRole; |
8
|
|
|
use Psr\Log\LoggerInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Check if the authenticated user is permitted to do actions. |
12
|
|
|
* Roles: newcomer < advisor < managing_advisor < administrator. |
13
|
|
|
*/ |
14
|
|
|
final class ClientReadAuthorizationChecker |
15
|
|
|
{ |
16
|
|
|
private ?int $loggedInUserId = null; |
17
|
|
|
|
18
|
32 |
|
public function __construct( |
19
|
|
|
private readonly AuthorizationUserRoleFinderRepository $authorizationUserRoleFinderRepository, |
20
|
|
|
private readonly UserNetworkSessionData $userNetworkSessionData, |
21
|
|
|
private readonly LoggerInterface $logger, |
22
|
|
|
) { |
23
|
32 |
|
$this->loggedInUserId = $this->userNetworkSessionData->userId; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Check if the authenticated user is allowed to read client. |
28
|
|
|
* |
29
|
|
|
* @param int|null $ownerId |
30
|
|
|
* @param string|\DateTimeImmutable|null $deletedAt |
31
|
|
|
* @param bool $log log if forbidden (expected false when function is called for privilege setting) |
32
|
|
|
* |
33
|
|
|
* @return bool |
34
|
|
|
*/ |
35
|
22 |
|
public function isGrantedToRead( |
36
|
|
|
?int $ownerId, |
|
|
|
|
37
|
|
|
string|\DateTimeImmutable|null $deletedAt = null, |
38
|
|
|
bool $log = true, |
39
|
|
|
): bool { |
40
|
22 |
|
if ($this->loggedInUserId !== null) { |
41
|
22 |
|
$authenticatedUserRoleHierarchy = $this->authorizationUserRoleFinderRepository->getRoleHierarchyByUserId( |
42
|
22 |
|
$this->loggedInUserId |
43
|
22 |
|
); |
44
|
|
|
// Returns array with role name as key and hierarchy as value ['role_name' => hierarchy_int] |
45
|
|
|
// * Lower hierarchy number means higher privileged role |
46
|
22 |
|
$userRoleHierarchies = $this->authorizationUserRoleFinderRepository->getUserRolesHierarchies(); |
47
|
|
|
|
48
|
|
|
// Newcomer are allowed to see all clients regardless of owner if not deleted |
49
|
22 |
|
if ($authenticatedUserRoleHierarchy <= $userRoleHierarchies[UserRole::NEWCOMER->value] |
50
|
22 |
|
&& $deletedAt === null |
51
|
|
|
) { |
52
|
19 |
|
return true; |
53
|
|
|
} |
54
|
|
|
// Managing advisors can see all clients including deleted ones |
55
|
5 |
|
if ($authenticatedUserRoleHierarchy <= $userRoleHierarchies[UserRole::MANAGING_ADVISOR->value]) { |
56
|
3 |
|
return true; |
57
|
|
|
} |
58
|
|
|
} |
59
|
2 |
|
if ($log === true) { |
60
|
2 |
|
$this->logger->notice( |
61
|
2 |
|
'User ' . $this->loggedInUserId . ' tried to read client but isn\'t allowed.' |
62
|
2 |
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
2 |
|
return false; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths