Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| ObserverProfilePolicyService | |
100.00% |
17 / 17 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isEnabled | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
| isLivePolicyEnabledForFile | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| isLivePolicyEnabled | |
100.00% |
3 / 3 |
|
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\Provider\ObserverProfile; |
| 10 | |
| 11 | use OCA\Libresign\Db\File as FileEntity; |
| 12 | use OCA\Libresign\Service\Policy\PolicyService; |
| 13 | |
| 14 | final class ObserverProfilePolicyService { |
| 15 | public function __construct( |
| 16 | private PolicyService $policyService, |
| 17 | ) { |
| 18 | } |
| 19 | |
| 20 | public function isEnabled(?FileEntity $file = null): bool { |
| 21 | if ($file instanceof FileEntity) { |
| 22 | $snapshotValue = ObserverProfilePolicyValue::getSnapshotEffectiveValue($file); |
| 23 | if ($snapshotValue === true) { |
| 24 | return true; |
| 25 | } |
| 26 | if ($snapshotValue === false) { |
| 27 | return $this->isLivePolicyEnabledForFile($file); |
| 28 | } |
| 29 | |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | return $this->isLivePolicyEnabled(); |
| 34 | } |
| 35 | |
| 36 | private function isLivePolicyEnabledForFile(FileEntity $file): bool { |
| 37 | return ObserverProfilePolicyValue::normalize( |
| 38 | $this->policyService |
| 39 | ->resolveForUserId(ObserverProfilePolicy::KEY, $file->getUserId()) |
| 40 | ->getEffectiveValue(), |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | private function isLivePolicyEnabled(): bool { |
| 45 | return ObserverProfilePolicyValue::normalize( |
| 46 | $this->policyService->resolve(ObserverProfilePolicy::KEY)->getEffectiveValue(), |
| 47 | ); |
| 48 | } |
| 49 | } |