@@ -10,8 +10,9 @@ import { generateOcsUrl } from '@nextcloud/router'
1010import { computed , reactive , ref } from 'vue'
1111import { t } from '@nextcloud/l10n'
1212
13- import DocMdpScalarRuleEditor from './settings/docmdp/DocMdpScalarRuleEditor.vue'
14- import SignatureFlowScalarRuleEditor from './settings/signature-flow/SignatureFlowScalarRuleEditor.vue'
13+ import { resolveDocMdpLevel } from './settings/docmdp/realDefinition'
14+ import { realDefinitions } from './settings/realDefinitions'
15+ import { resolveSignatureFlowMode } from './settings/signature-flow/realDefinition'
1516import { usePoliciesStore } from '../../../store/policies'
1617import type { EffectivePolicyState , EffectivePolicyValue } from '../../../types/index'
1718import logger from '../../../logger.js'
@@ -53,17 +54,6 @@ interface PolicyEditorDraft {
5354 allowChildOverride : boolean
5455}
5556
56- interface PolicySettingDefinition {
57- key : string
58- title : string
59- context ?: string
60- description : string
61- editor : unknown
62- createEmptyValue : ( ) => EffectivePolicyValue
63- summarizeValue : ( value : EffectivePolicyValue ) => string
64- formatAllowOverride : ( allowChildOverride : boolean ) => string
65- }
66-
6757interface PolicySettingSummary {
6858 key : string
6959 title : string
@@ -128,90 +118,6 @@ function isUserDetailsRecord(candidate: unknown): candidate is UserDetailsRecord
128118 return true
129119}
130120
131- const realDefinitions = {
132- signature_flow : {
133- key : 'signature_flow' ,
134- title : t ( 'libresign' , 'Signing order' ) ,
135- context : undefined ,
136- description : t ( 'libresign' , 'Choose whether documents are signed in order or all at once.' ) ,
137- editor : SignatureFlowScalarRuleEditor ,
138- createEmptyValue : ( ) => '' as unknown as EffectivePolicyValue ,
139- summarizeValue : ( value : EffectivePolicyValue ) => {
140- const flowValue = resolveSignatureFlowMode ( value )
141- switch ( flowValue ) {
142- case 'parallel' :
143- return t ( 'libresign' , 'Simultaneous (Parallel)' )
144- case 'ordered_numeric' :
145- return t ( 'libresign' , 'Sequential' )
146- case 'none' :
147- return t ( 'libresign' , 'User choice' )
148- default :
149- return t ( 'libresign' , 'Not configured' )
150- }
151- } ,
152- formatAllowOverride : ( allowChildOverride : boolean ) =>
153- allowChildOverride
154- ? t ( 'libresign' , 'Groups and users can set their own rule' )
155- : t ( 'libresign' , 'Groups and users must follow this value' ) ,
156- } ,
157- docmdp : {
158- key : 'docmdp' ,
159- title : t ( 'libresign' , 'PDF certification' ) ,
160- context : t ( 'libresign' , 'DocMDP' ) ,
161- description : t ( 'libresign' , 'Control what changes are allowed after a document is signed.' ) ,
162- editor : DocMdpScalarRuleEditor ,
163- createEmptyValue : ( ) => 0 ,
164- summarizeValue : ( value : EffectivePolicyValue ) => {
165- const level = resolveDocMdpLevel ( value )
166- switch ( level ) {
167- case 0 :
168- return t ( 'libresign' , 'Disabled' )
169- case 1 :
170- return t ( 'libresign' , 'No changes allowed' )
171- case 2 :
172- return t ( 'libresign' , 'Form filling' )
173- case 3 :
174- return t ( 'libresign' , 'Form filling and annotations' )
175- default :
176- return t ( 'libresign' , 'Not configured' )
177- }
178- } ,
179- formatAllowOverride : ( allowChildOverride : boolean ) =>
180- allowChildOverride
181- ? t ( 'libresign' , 'Groups and users can set their own rule' )
182- : t ( 'libresign' , 'Groups and users must follow this value' ) ,
183- } ,
184- }
185-
186- function resolveSignatureFlowMode ( value : EffectivePolicyValue ) : string | null {
187- if ( value === 0 ) {
188- return 'none'
189- }
190-
191- if ( value === 1 ) {
192- return 'parallel'
193- }
194-
195- if ( value === 2 ) {
196- return 'ordered_numeric'
197- }
198-
199- if ( typeof value === 'string' ) {
200- if ( value === 'parallel' || value === 'ordered_numeric' || value === 'none' ) {
201- return value
202- }
203-
204- return null
205- }
206-
207- if ( value && typeof value === 'object' && 'flow' in ( value as Record < string , unknown > ) ) {
208- const candidate = ( value as { flow ?: unknown } ) . flow
209- return typeof candidate === 'string' ? candidate : null
210- }
211-
212- return null
213- }
214-
215121function normalizeDraftValueForPolicy ( policyKey : string , value : EffectivePolicyValue ) : EffectivePolicyValue {
216122 if ( policyKey === 'signature_flow' ) {
217123 const mode = resolveSignatureFlowMode ( value )
@@ -267,18 +173,6 @@ function getDocMdpFallbackSystemDefault(policy: EffectivePolicyState | null): Ef
267173 return 0
268174}
269175
270- function resolveDocMdpLevel ( value : EffectivePolicyValue ) : number | null {
271- if ( typeof value === 'number' && value >= 0 && value <= 3 ) {
272- return value
273- }
274-
275- if ( typeof value === 'string' && / ^ [ 0 - 3 ] $ / . test ( value ) ) {
276- return Number ( value )
277- }
278-
279- return null
280- }
281-
282176function toDraftSnapshot ( draft : PolicyEditorDraft | null ) : string {
283177 if ( ! draft ) {
284178 return ''
0 commit comments