1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Module\Client\Delete\Service; |
4
|
|
|
|
5
|
|
|
use App\Application\Data\UserNetworkSessionData; |
6
|
|
|
use App\Module\Authorization\Repository\AuthorizationUserRoleFinderRepository; |
|
|
|
|
7
|
|
|
use Psr\Log\LoggerInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Check if the authenticated user is permitted to do actions. |
11
|
|
|
* Roles: newcomer < advisor < managing_advisor < administrator. |
12
|
|
|
*/ |
13
|
|
|
final class ClientDeleteAuthorizationChecker |
14
|
|
|
{ |
15
|
|
|
private ?int $loggedInUserId = null; |
16
|
|
|
|
17
|
34 |
|
public function __construct( |
18
|
|
|
private readonly AuthorizationUserRoleFinderRepository $authorizationUserRoleFinderRepository, |
19
|
|
|
private readonly UserNetworkSessionData $userNetworkSessionData, |
20
|
|
|
private readonly LoggerInterface $logger, |
21
|
|
|
) { |
22
|
34 |
|
$this->loggedInUserId = $this->userNetworkSessionData->userId; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Check if the authenticated user is allowed to delete client. |
27
|
|
|
* |
28
|
|
|
* @param int|null $ownerId |
29
|
|
|
* @param bool $log log if forbidden (expected false when function is called for privilege setting) |
30
|
|
|
* |
31
|
|
|
* @return bool |
32
|
|
|
*/ |
33
|
21 |
|
public function isGrantedToDelete(?int $ownerId, bool $log = true): bool |
|
|
|
|
34
|
|
|
{ |
35
|
21 |
|
if ($this->loggedInUserId === null) { |
36
|
|
|
$this->logger->error('loggedInUserId not set while isGrantedToDelete authorization check'); |
37
|
|
|
|
38
|
|
|
return false; |
39
|
|
|
} |
40
|
21 |
|
$authenticatedUserRoleHierarchy = $this->authorizationUserRoleFinderRepository->getRoleHierarchyByUserId( |
41
|
21 |
|
$this->loggedInUserId |
42
|
21 |
|
); |
43
|
|
|
// Returns array with role name as key and hierarchy as value ['role_name' => hierarchy_int] |
44
|
|
|
// * Lower hierarchy number means higher privileged role |
45
|
21 |
|
$userRoleHierarchies = $this->authorizationUserRoleFinderRepository->getUserRolesHierarchies(); |
46
|
|
|
|
47
|
|
|
// Only managing_advisor and higher are allowed to delete client so user has to at least have this role |
48
|
21 |
|
if ($authenticatedUserRoleHierarchy <= $userRoleHierarchies['managing_advisor']) { |
49
|
8 |
|
return true; |
50
|
|
|
} |
51
|
|
|
|
52
|
13 |
|
if ($log === true) { |
53
|
3 |
|
$this->logger->notice( |
54
|
3 |
|
'User ' . $this->loggedInUserId . ' tried to delete client but isn\'t allowed.' |
55
|
3 |
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
13 |
|
return false; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
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