|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2026 LibreCode coop and LibreCode contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import { t } from '@nextcloud/l10n' |
| 7 | + |
| 8 | +import SignatureFlowScalarRuleEditor from './SignatureFlowScalarRuleEditor.vue' |
| 9 | +import type { EffectivePolicyValue } from '../../../../../types/index' |
| 10 | +import type { RealPolicySettingDefinition } from '../realTypes' |
| 11 | + |
| 12 | +export function resolveSignatureFlowMode(value: EffectivePolicyValue): string | null { |
| 13 | + if (value === 0) { |
| 14 | + return 'none' |
| 15 | + } |
| 16 | + |
| 17 | + if (value === 1) { |
| 18 | + return 'parallel' |
| 19 | + } |
| 20 | + |
| 21 | + if (value === 2) { |
| 22 | + return 'ordered_numeric' |
| 23 | + } |
| 24 | + |
| 25 | + if (typeof value === 'string') { |
| 26 | + if (value === 'parallel' || value === 'ordered_numeric' || value === 'none') { |
| 27 | + return value |
| 28 | + } |
| 29 | + |
| 30 | + return null |
| 31 | + } |
| 32 | + |
| 33 | + if (value && typeof value === 'object' && 'flow' in (value as Record<string, unknown>)) { |
| 34 | + const candidate = (value as { flow?: unknown }).flow |
| 35 | + return typeof candidate === 'string' ? candidate : null |
| 36 | + } |
| 37 | + |
| 38 | + return null |
| 39 | +} |
| 40 | + |
| 41 | +export const signatureFlowRealDefinition: RealPolicySettingDefinition = { |
| 42 | + key: 'signature_flow', |
| 43 | + title: t('libresign', 'Signing order'), |
| 44 | + description: t('libresign', 'Choose whether documents are signed in order or all at once.'), |
| 45 | + editor: SignatureFlowScalarRuleEditor, |
| 46 | + createEmptyValue: () => '' as unknown as EffectivePolicyValue, |
| 47 | + summarizeValue: (value: EffectivePolicyValue) => { |
| 48 | + const flowValue = resolveSignatureFlowMode(value) |
| 49 | + switch (flowValue) { |
| 50 | + case 'parallel': |
| 51 | + return t('libresign', 'Simultaneous (Parallel)') |
| 52 | + case 'ordered_numeric': |
| 53 | + return t('libresign', 'Sequential') |
| 54 | + case 'none': |
| 55 | + return t('libresign', 'User choice') |
| 56 | + default: |
| 57 | + return t('libresign', 'Not configured') |
| 58 | + } |
| 59 | + }, |
| 60 | + formatAllowOverride: (allowChildOverride: boolean) => |
| 61 | + allowChildOverride |
| 62 | + ? t('libresign', 'Groups and users can set their own rule') |
| 63 | + : t('libresign', 'Groups and users must follow this value'), |
| 64 | +} |
0 commit comments