Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DelegationLayerHelper | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
13 | |
100.00% |
1 / 1 |
| hasExplicitGlobalDelegation | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
5 | |||
| hasSystemCreatedGroupDelegation | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
8 | |||
| 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\Helper; |
| 10 | |
| 11 | use OCA\Libresign\Service\Policy\Model\PolicyLayer; |
| 12 | |
| 13 | final class DelegationLayerHelper { |
| 14 | public static function hasExplicitGlobalDelegation(?PolicyLayer $systemPolicy): bool { |
| 15 | return $systemPolicy instanceof PolicyLayer |
| 16 | && $systemPolicy->getScope() === 'global' |
| 17 | && $systemPolicy->isVisibleToChild() |
| 18 | && $systemPolicy->isAllowChildOverride() |
| 19 | && $systemPolicy->getValue() !== null; |
| 20 | } |
| 21 | |
| 22 | /** @param array<array-key, PolicyLayer> $groupLayers */ |
| 23 | public static function hasSystemCreatedGroupDelegation(array $groupLayers): bool { |
| 24 | foreach ($groupLayers as $groupLayer) { |
| 25 | if (!$groupLayer instanceof PolicyLayer) { |
| 26 | continue; |
| 27 | } |
| 28 | |
| 29 | if (!$groupLayer->isVisibleToChild() || $groupLayer->getValue() === null) { |
| 30 | continue; |
| 31 | } |
| 32 | |
| 33 | if ($groupLayer->isDelegatedFromSystemCreatedSeed()) { |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | if ($groupLayer->isAllowChildOverride() && $groupLayer->isCreatedBySystemAdmin()) { |
| 38 | return true; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | return false; |
| 43 | } |
| 44 | } |