Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
EmailSignerSignaturePolicy
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 keys
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 get
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4/**
5 * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
6 * SPDX-License-Identifier: AGPL-3.0-or-later
7 */
8
9namespace OCA\Libresign\Service\Policy\Provider\EmailSignerSignature;
10
11use OCA\Libresign\Service\Policy\Contract\IPolicyDefinition;
12use OCA\Libresign\Service\Policy\Contract\IPolicyDefinitionProvider;
13use OCA\Libresign\Service\Policy\Model\PolicySpec;
14use OCA\Libresign\Service\Policy\Provider\Helper\PolicyKeyNormalizer;
15
16/**
17 * Lets signers identified only by email keep their visible signature
18 * across documents. Signers without an account have no group or user
19 * scope, so only the system scope is supported.
20 */
21final class EmailSignerSignaturePolicy implements IPolicyDefinitionProvider {
22    public const KEY = 'persist_email_signer_signatures';
23    public const SYSTEM_APP_CONFIG_KEY = self::KEY;
24
25    #[\Override]
26    public function keys(): array {
27        return [
28            self::KEY,
29        ];
30    }
31
32    #[\Override]
33    public function get(string|\BackedEnum $policyKey): IPolicyDefinition {
34        return match (PolicyKeyNormalizer::normalize($policyKey)) {
35            self::KEY => new PolicySpec(
36                key: self::KEY,
37                defaultSystemValue: false,
38                allowedValues: [
39                    false,
40                    true,
41                ],
42                normalizer: static fn (mixed $rawValue): bool => filter_var($rawValue, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) ?? false,
43                appConfigKey: self::SYSTEM_APP_CONFIG_KEY,
44                supportsUserPreference: false,
45                supportsRequestOverride: false,
46                requestLifecycle: PolicySpec::LIFECYCLE_RUNTIME,
47                supportedScopes: [PolicySpec::SCOPE_SYSTEM],
48                supportsGroupAdminDelegation: false,
49            ),
50            default => throw new \InvalidArgumentException('Unknown policy key: ' . PolicyKeyNormalizer::normalize($policyKey)),
51        };
52    }
53}