Skip to content

Commit 0de711e

Browse files
committed
feat(policy): add docmdp policy provider
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 20ad866 commit 0de711e

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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\DocMdp;
10+
11+
use OCA\Libresign\Enum\DocMdpLevel;
12+
use OCA\Libresign\Service\Policy\Contract\IPolicyDefinition;
13+
use OCA\Libresign\Service\Policy\Contract\IPolicyDefinitionProvider;
14+
use OCA\Libresign\Service\Policy\Model\PolicySpec;
15+
16+
final class DocMdpPolicy implements IPolicyDefinitionProvider {
17+
public const KEY = 'docmdp';
18+
public const SYSTEM_APP_CONFIG_KEY = 'docmdp_level';
19+
20+
#[\Override]
21+
public function keys(): array {
22+
return [
23+
self::KEY,
24+
];
25+
}
26+
27+
#[\Override]
28+
public function get(string|\BackedEnum $policyKey): IPolicyDefinition {
29+
return match ($this->normalizePolicyKey($policyKey)) {
30+
self::KEY => new PolicySpec(
31+
key: self::KEY,
32+
defaultSystemValue: DocMdpLevel::NOT_CERTIFIED->value,
33+
allowedValues: [
34+
DocMdpLevel::NOT_CERTIFIED->value,
35+
DocMdpLevel::CERTIFIED_NO_CHANGES_ALLOWED->value,
36+
DocMdpLevel::CERTIFIED_FORM_FILLING->value,
37+
DocMdpLevel::CERTIFIED_FORM_FILLING_AND_ANNOTATIONS->value,
38+
],
39+
normalizer: static function (mixed $rawValue): mixed {
40+
if ($rawValue instanceof DocMdpLevel) {
41+
return $rawValue->value;
42+
}
43+
44+
if (is_int($rawValue)) {
45+
return $rawValue;
46+
}
47+
48+
return $rawValue;
49+
},
50+
appConfigKey: self::SYSTEM_APP_CONFIG_KEY,
51+
),
52+
default => throw new \InvalidArgumentException('Unknown policy key: ' . $this->normalizePolicyKey($policyKey)),
53+
};
54+
}
55+
56+
private function normalizePolicyKey(string|\BackedEnum $policyKey): string {
57+
if ($policyKey instanceof \BackedEnum) {
58+
return (string)$policyKey->value;
59+
}
60+
61+
return $policyKey;
62+
}
63+
}

0 commit comments

Comments
 (0)