diff --git a/lib/Controller/AdminController.php b/lib/Controller/AdminController.php index 98760b726f..c4fd4eac01 100644 --- a/lib/Controller/AdminController.php +++ b/lib/Controller/AdminController.php @@ -898,7 +898,8 @@ public function footerTemplatePreviewPdf(string $template = '', int $width = 595 /** * Set signature flow configuration * - * @param string $mode Signature flow mode: 'parallel' or 'ordered_numeric' + * @param bool $enabled Whether to force a signature flow for all documents + * @param string|null $mode Signature flow mode: 'parallel' or 'ordered_numeric' (only used when enabled is true) * @return DataResponse|DataResponse|DataResponse * * 200: Configuration saved successfully @@ -906,26 +907,35 @@ public function footerTemplatePreviewPdf(string $template = '', int $width = 595 * 500: Internal server error */ #[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/admin/signature-flow/config', requirements: ['apiVersion' => '(v1)'])] - public function setSignatureFlowConfig(string $mode): DataResponse { + public function setSignatureFlowConfig(bool $enabled, ?string $mode = null): DataResponse { try { - $signatureFlow = \OCA\Libresign\Enum\SignatureFlow::from($mode); - } catch (\ValueError) { - return new DataResponse([ - 'error' => $this->l10n->t('Invalid signature flow mode. Use "parallel" or "ordered_numeric".'), - ], Http::STATUS_BAD_REQUEST); - } - - try { - if ($signatureFlow === \OCA\Libresign\Enum\SignatureFlow::PARALLEL) { + if (!$enabled) { $this->appConfig->deleteKey(Application::APP_ID, 'signature_flow'); - } else { - $this->appConfig->setValueString( - Application::APP_ID, - 'signature_flow', - $signatureFlow->value - ); + return new DataResponse([ + 'message' => $this->l10n->t('Settings saved'), + ]); + } + + if ($mode === null) { + return new DataResponse([ + 'error' => $this->l10n->t('Mode is required when signature flow is enabled.'), + ], Http::STATUS_BAD_REQUEST); + } + + try { + $signatureFlow = \OCA\Libresign\Enum\SignatureFlow::from($mode); + } catch (\ValueError) { + return new DataResponse([ + 'error' => $this->l10n->t('Invalid signature flow mode. Use "parallel" or "ordered_numeric".'), + ], Http::STATUS_BAD_REQUEST); } + $this->appConfig->setValueString( + Application::APP_ID, + 'signature_flow', + $signatureFlow->value + ); + return new DataResponse([ 'message' => $this->l10n->t('Settings saved'), ]); diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php index 341d6371b2..cd02c3bfe2 100644 --- a/lib/Settings/Admin.php +++ b/lib/Settings/Admin.php @@ -9,7 +9,6 @@ namespace OCA\Libresign\Settings; use OCA\Libresign\AppInfo\Application; -use OCA\Libresign\Enum\SignatureFlow; use OCA\Libresign\Exception\LibresignException; use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory; use OCA\Libresign\Service\CertificatePolicyService; @@ -80,7 +79,7 @@ public function getForm(): TemplateResponse { $this->initialState->provideInitialState('tsa_username', $this->appConfig->getValueString(Application::APP_ID, 'tsa_username', '')); $this->initialState->provideInitialState('tsa_password', $this->appConfig->getValueString(Application::APP_ID, 'tsa_password', self::PASSWORD_PLACEHOLDER)); $this->initialState->provideInitialState('docmdp_config', $this->docMdpConfigService->getConfig()); - $this->initialState->provideInitialState('signature_flow', $this->appConfig->getValueString(Application::APP_ID, 'signature_flow', SignatureFlow::PARALLEL->value)); + $this->initialState->provideInitialState('signature_flow', $this->appConfig->getValueString(Application::APP_ID, 'signature_flow', '')); return new TemplateResponse(Application::APP_ID, 'admin_settings'); } diff --git a/openapi-administration.json b/openapi-administration.json index 94e998b68e..7e503d90a6 100644 --- a/openapi-administration.json +++ b/openapi-administration.json @@ -2987,12 +2987,17 @@ "schema": { "type": "object", "required": [ - "mode" + "enabled" ], "properties": { + "enabled": { + "type": "boolean", + "description": "Whether to force a signature flow for all documents" + }, "mode": { "type": "string", - "description": "Signature flow mode: 'parallel' or 'ordered_numeric'" + "nullable": true, + "description": "Signature flow mode: 'parallel' or 'ordered_numeric' (only used when enabled is true)" } } } diff --git a/openapi-full.json b/openapi-full.json index de9ee08dc6..410bdc6f7e 100644 --- a/openapi-full.json +++ b/openapi-full.json @@ -11504,12 +11504,17 @@ "schema": { "type": "object", "required": [ - "mode" + "enabled" ], "properties": { + "enabled": { + "type": "boolean", + "description": "Whether to force a signature flow for all documents" + }, "mode": { "type": "string", - "description": "Signature flow mode: 'parallel' or 'ordered_numeric'" + "nullable": true, + "description": "Signature flow mode: 'parallel' or 'ordered_numeric' (only used when enabled is true)" } } } diff --git a/src/types/openapi/openapi-administration.ts b/src/types/openapi/openapi-administration.ts index 1ff8e4a665..7398f8c83f 100644 --- a/src/types/openapi/openapi-administration.ts +++ b/src/types/openapi/openapi-administration.ts @@ -1635,8 +1635,10 @@ export interface operations { requestBody: { content: { "application/json": { - /** @description Signature flow mode: 'parallel' or 'ordered_numeric' */ - mode: string; + /** @description Whether to force a signature flow for all documents */ + enabled: boolean; + /** @description Signature flow mode: 'parallel' or 'ordered_numeric' (only used when enabled is true) */ + mode?: string | null; }; }; }; diff --git a/src/types/openapi/openapi-full.ts b/src/types/openapi/openapi-full.ts index d62a0f5623..d3b0efb37d 100644 --- a/src/types/openapi/openapi-full.ts +++ b/src/types/openapi/openapi-full.ts @@ -6048,8 +6048,10 @@ export interface operations { requestBody: { content: { "application/json": { - /** @description Signature flow mode: 'parallel' or 'ordered_numeric' */ - mode: string; + /** @description Whether to force a signature flow for all documents */ + enabled: boolean; + /** @description Signature flow mode: 'parallel' or 'ordered_numeric' (only used when enabled is true) */ + mode?: string | null; }; }; }; diff --git a/src/views/Settings/SignatureFlow.vue b/src/views/Settings/SignatureFlow.vue index 720eecf6bd..ec981e575e 100644 --- a/src/views/Settings/SignatureFlow.vue +++ b/src/views/Settings/SignatureFlow.vue @@ -7,7 +7,26 @@ {{ errorMessage }} -
+ +
+ + {{ t('libresign', 'Set default signing order') }} + + + + + + + + + + +
+ +
- - - + + +
@@ -58,6 +77,7 @@ export default { data() { return { name: t('libresign', 'Signing order'), + enabled: false, selectedFlow: null, availableFlows: [ { @@ -75,6 +95,7 @@ export default { errorMessage: '', saved: false, showErrorIcon: false, + flowChanging: false, } }, async mounted() { @@ -83,25 +104,40 @@ export default { methods: { loadConfig() { try { - const mode = loadState('libresign', 'signature_flow', 'parallel') - - this.selectedFlow = this.availableFlows.find( - flow => flow.value === mode - ) + const mode = loadState('libresign', 'signature_flow', null) - if (!this.selectedFlow) { + if (mode === null || mode === '') { + this.enabled = false this.selectedFlow = this.availableFlows[0] + } else { + this.enabled = true + this.selectedFlow = this.availableFlows.find( + flow => flow.value === mode + ) + + if (!this.selectedFlow) { + this.selectedFlow = this.availableFlows[0] + } } } catch (error) { console.error('Error loading signature flow configuration:', error) this.errorMessage = t('libresign', 'Could not load configuration.') + this.enabled = false this.selectedFlow = this.availableFlows[0] } }, + onToggleChange(value) { + this.enabled = value + this.errorMessage = '' + this.showErrorIcon = false + this.flowChanging = false + this.saveConfig() + }, onFlowChange(value) { this.selectedFlow = this.availableFlows.find(flow => flow.value === value) this.errorMessage = '' this.showErrorIcon = false + this.flowChanging = true this.saveConfig() }, async saveConfig() { @@ -113,12 +149,14 @@ export default { try { const url = generateOcsUrl('apps/libresign/api/v1/admin/signature-flow/config') await axios.post(url, { - mode: this.selectedFlow?.value ?? 'parallel', + enabled: this.enabled, + mode: this.enabled ? (this.selectedFlow?.value ?? 'parallel') : null, }) this.saved = true setTimeout(() => { this.saved = false + this.flowChanging = false }, 3000) } catch (error) { console.error('Error saving signature flow configuration:', error) @@ -134,8 +172,27 @@ export default {