1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Module\User\Read\Service; |
4
|
|
|
|
5
|
|
|
use App\Domain\Exception\DomainRecordNotFoundException; |
6
|
|
|
use App\Module\Authorization\Exception\ForbiddenException; |
7
|
|
|
use App\Module\User\Authorization\Service\UserPrivilegeDeterminer; |
|
|
|
|
8
|
|
|
use App\Module\User\Data\UserResultData; |
9
|
|
|
use App\Module\User\Find\Repository\UserFinderRepository; |
10
|
|
|
use App\Module\User\FindDropdownOptions\Service\AuthorizedUserRoleFilterer; |
|
|
|
|
11
|
|
|
|
12
|
|
|
// Class cannot be readonly as it's mocked (doubled) in tests |
13
|
|
|
readonly class UserReadFinder |
14
|
|
|
{ |
15
|
5 |
|
public function __construct( |
16
|
|
|
private UserFinderRepository $userFinderRepository, |
17
|
|
|
private UserPrivilegeDeterminer $userPrivilegeDeterminer, |
18
|
|
|
private AuthorizedUserRoleFilterer $authorizedUserRoleFilterer, |
19
|
|
|
private UserReadAuthorizationChecker $userReadAuthorizationChecker, |
20
|
|
|
) { |
21
|
5 |
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Find user with authorization check and privilege attributes. |
25
|
|
|
* |
26
|
|
|
* @param int $id |
27
|
|
|
* |
28
|
|
|
* @throws \Exception |
29
|
|
|
* |
30
|
|
|
* @return UserResultData |
31
|
|
|
*/ |
32
|
5 |
|
public function findUserReadResult(int $id): UserResultData |
33
|
|
|
{ |
34
|
5 |
|
if ($this->userReadAuthorizationChecker->isGrantedToRead($id)) { |
35
|
4 |
|
$userRow = $this->userFinderRepository->findUserById($id); |
36
|
4 |
|
if (!empty($userRow)) { |
37
|
3 |
|
$userResultData = new UserResultData($userRow); |
38
|
|
|
// Status privilege |
39
|
3 |
|
$userResultData->statusPrivilege = $this->userPrivilegeDeterminer->getMutationPrivilege( |
40
|
3 |
|
$id, |
41
|
3 |
|
'status', |
42
|
3 |
|
); |
43
|
|
|
// Available user roles for dropdown and privilege |
44
|
3 |
|
$userResultData->availableUserRoles = $this->authorizedUserRoleFilterer->filterAuthorizedUserRoles( |
45
|
3 |
|
$userResultData->userRoleId |
46
|
3 |
|
); |
47
|
3 |
|
$userResultData->userRolePrivilege = $this->userPrivilegeDeterminer->getUserRoleAssignmentPrivilege( |
48
|
3 |
|
$userResultData->availableUserRoles |
49
|
3 |
|
); |
50
|
|
|
|
51
|
|
|
// Personal info privilege like first name, email and so on |
52
|
3 |
|
$userResultData->generalPrivilege = $this->userPrivilegeDeterminer->getMutationPrivilege( |
53
|
3 |
|
$id, |
54
|
3 |
|
'personal_info', |
55
|
3 |
|
); |
56
|
|
|
// Password change without verification of old password |
57
|
3 |
|
$userResultData->passwordWithoutVerificationPrivilege = $this->userPrivilegeDeterminer-> |
58
|
3 |
|
getMutationPrivilege($id, 'password_without_verification'); |
59
|
|
|
|
60
|
3 |
|
return $userResultData; |
61
|
|
|
} |
62
|
|
|
// When user allowed to read, and it doesn't exist indicate that the resource was not found |
63
|
1 |
|
throw new DomainRecordNotFoundException('User not found.'); |
64
|
|
|
} |
65
|
|
|
// Forbidden when not found and user is not allowed to read |
66
|
1 |
|
throw new ForbiddenException('Not allowed to read user.'); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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