Total Complexity | 7 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class SecurityHelper |
||
13 | { |
||
14 | public function __construct( |
||
18 | } |
||
19 | |||
20 | public function isOperationAllowed(string $resourceName, string $operationName): bool |
||
21 | { |
||
22 | $user = $this->getUser(); |
||
23 | $resource = $this->registry->get($resourceName); |
||
24 | |||
25 | if (!$resource->hasOperation($operationName)) { |
||
26 | return false; |
||
27 | } |
||
28 | $operation = $resource->getOperation($operationName); |
||
29 | |||
30 | foreach ($operation->getPermissions() ?? [] as $permission) { |
||
31 | if (!$this->security->isGranted($permission, $user)) { |
||
32 | return false; |
||
33 | } |
||
34 | } |
||
35 | |||
36 | return true; |
||
37 | } |
||
38 | |||
39 | public function getUser(): UserInterface |
||
48 | } |
||
49 | } |
||
50 |