Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
27 / 27 |
|
100.00% |
17 / 17 |
CRAP | |
100.00% |
1 / 1 |
| PolicyContext | |
100.00% |
27 / 27 |
|
100.00% |
17 / 17 |
18 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fromUserId | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| setUserId | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getUserId | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setGroups | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getGroups | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setCircles | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getCircles | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setActiveGroupScope | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getActiveGroupScope | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setRequestOverrides | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getRequestOverrides | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setStoredRequestOverrides | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getStoredRequestOverrides | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isStoredRequestOverride | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| setActorRole | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getActorRole | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Service\Policy\Model; |
| 10 | |
| 11 | final class PolicyContext { |
| 12 | private ActorRole $actorRole; |
| 13 | private ?string $userId = null; |
| 14 | /** @var list<string> */ |
| 15 | private array $groups = []; |
| 16 | /** @var list<string> */ |
| 17 | private array $circles = []; |
| 18 | private ?ActiveGroupScope $activeGroupScope = null; |
| 19 | /** @var array<string, mixed> */ |
| 20 | private array $requestOverrides = []; |
| 21 | /** @var array<string, mixed> */ |
| 22 | private array $storedRequestOverrides = []; |
| 23 | public function __construct() { |
| 24 | $this->actorRole = ActorRole::regularUser(); |
| 25 | } |
| 26 | |
| 27 | public static function fromUserId(string $userId): self { |
| 28 | $context = new self(); |
| 29 | $context->setUserId($userId); |
| 30 | return $context; |
| 31 | } |
| 32 | |
| 33 | public function setUserId(?string $userId): self { |
| 34 | $this->userId = $userId; |
| 35 | return $this; |
| 36 | } |
| 37 | |
| 38 | public function getUserId(): ?string { |
| 39 | return $this->userId; |
| 40 | } |
| 41 | |
| 42 | /** @param list<string> $groups */ |
| 43 | public function setGroups(array $groups): self { |
| 44 | $this->groups = $groups; |
| 45 | return $this; |
| 46 | } |
| 47 | |
| 48 | /** @return list<string> */ |
| 49 | public function getGroups(): array { |
| 50 | return $this->groups; |
| 51 | } |
| 52 | |
| 53 | /** @param list<string> $circles */ |
| 54 | public function setCircles(array $circles): self { |
| 55 | $this->circles = $circles; |
| 56 | return $this; |
| 57 | } |
| 58 | |
| 59 | /** @return list<string> */ |
| 60 | public function getCircles(): array { |
| 61 | return $this->circles; |
| 62 | } |
| 63 | |
| 64 | public function setActiveGroupScope(?ActiveGroupScope $activeGroupScope): self { |
| 65 | $this->activeGroupScope = $activeGroupScope; |
| 66 | return $this; |
| 67 | } |
| 68 | |
| 69 | public function getActiveGroupScope(): ?ActiveGroupScope { |
| 70 | return $this->activeGroupScope; |
| 71 | } |
| 72 | |
| 73 | /** @param array<string, mixed> $requestOverrides */ |
| 74 | public function setRequestOverrides(array $requestOverrides): self { |
| 75 | $this->requestOverrides = $requestOverrides; |
| 76 | return $this; |
| 77 | } |
| 78 | |
| 79 | /** @return array<string, mixed> */ |
| 80 | public function getRequestOverrides(): array { |
| 81 | return $this->requestOverrides; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Request values a document stored earlier and that are now replayed |
| 86 | * internally, as opposed to the values the current actor submits. |
| 87 | * |
| 88 | * @param array<string, mixed> $storedRequestOverrides |
| 89 | */ |
| 90 | public function setStoredRequestOverrides(array $storedRequestOverrides): self { |
| 91 | $this->storedRequestOverrides = $storedRequestOverrides; |
| 92 | return $this; |
| 93 | } |
| 94 | |
| 95 | /** @return array<string, mixed> */ |
| 96 | public function getStoredRequestOverrides(): array { |
| 97 | return $this->storedRequestOverrides; |
| 98 | } |
| 99 | |
| 100 | public function isStoredRequestOverride(string $policyKey): bool { |
| 101 | return !array_key_exists($policyKey, $this->requestOverrides) |
| 102 | && array_key_exists($policyKey, $this->storedRequestOverrides); |
| 103 | } |
| 104 | |
| 105 | public function setActorRole(ActorRole $role): self { |
| 106 | $this->actorRole = $role; |
| 107 | return $this; |
| 108 | } |
| 109 | |
| 110 | public function getActorRole(): ActorRole { |
| 111 | return $this->actorRole; |
| 112 | } |
| 113 | } |