From ee7e36fa16fb77e85dc8cf8402ca2cbdcbfa54f1 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Mon, 27 Jan 2025 08:03:22 -0300 Subject: [PATCH] refactor: attach document Signed-off-by: Vitor Mattos --- lib/Controller/PageController.php | 7 +++++ lib/Service/FileService.php | 16 +++++++++-- src/store/identificationDocument.js | 43 ++++++++++++++++++++++++++++ src/views/SignPDF/_partials/Sign.vue | 28 +++++++++++++++++- 4 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 src/store/identificationDocument.js diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 62d6aa918e..6f1bc516ba 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -292,11 +292,18 @@ public function sign(string $uuid): TemplateResponse { ->setFile($this->getFileEntity()) ->setHost($this->request->getServerHost()) ->setMe($this->userSession->getUser()) + ->setSignerIdentified() ->setIdentifyMethodId($this->sessionService->getIdentifyMethodId()) ->setSignRequest($this->getSignRequestEntity()) ->showVisibleElements() ->showSigners() + ->showSettings() ->toArray(); + $this->initialState->provideInitialState('config', [ + 'identificationDocumentsFlow' => $file['settings']['needIdentificationDocuments'] ?? false, + ]); + $this->initialState->provideInitialState('needIdentificationDocuments', $file['settings']['needIdentificationDocuments'] ?? false); + $this->initialState->provideInitialState('identificationDocumentsWaitingApproval', $file['settings']['identificationDocumentsWaitingApproval'] ?? false); $this->initialState->provideInitialState('status', $file['status']); $this->initialState->provideInitialState('statusText', $file['statusText']); $this->initialState->provideInitialState('signers', $file['signers']); diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index 34d7124c00..d1fea8c381 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -52,6 +52,7 @@ class FileService { private bool $showMessages = false; private bool $validateFile = false; private bool $signersLibreSignLoaded = false; + private bool $signerIdentified = false; private string $fileContent = ''; private string $host = ''; private ?File $file = null; @@ -141,6 +142,11 @@ public function setMe(?IUser $user): self { return $this; } + public function setSignerIdentified(bool $identified = true): self { + $this->signerIdentified = $identified; + return $this; + } + public function setIdentifyMethodId(?int $id): self { $this->identifyMethodId = $id; return $this; @@ -570,7 +576,9 @@ private function loadSettings(): void { if ($this->me) { $this->fileData->settings = array_merge($this->fileData->settings, $this->accountService->getSettings($this->me)); $this->fileData->settings['phoneNumber'] = $this->getPhoneNumber(); - $status = $this->getIdentificationDocumentsStatus($this->me->getUID()); + } + if ($this->signerIdentified || $this->me) { + $status = $this->getIdentificationDocumentsStatus(); if ($status === self::IDENTIFICATION_DOCUMENTS_NEED_SEND) { $this->fileData->settings['needIdentificationDocuments'] = true; $this->fileData->settings['identificationDocumentsWaitingApproval'] = false; @@ -581,14 +589,18 @@ private function loadSettings(): void { } } - public function getIdentificationDocumentsStatus(?string $userId): int { + public function getIdentificationDocumentsStatus(string $userId = ''): int { if (!$this->appConfig->getValueBool(Application::APP_ID, 'identification_documents', false)) { return self::IDENTIFICATION_DOCUMENTS_DISABLED; } + if (!$userId && $this->me instanceof IUser) { + $userId = $this->me->getUID(); + } if (!empty($userId)) { $files = $this->fileMapper->getFilesOfAccount($userId); } + if (empty($files) || !count($files)) { return self::IDENTIFICATION_DOCUMENTS_NEED_SEND; } diff --git a/src/store/identificationDocument.js b/src/store/identificationDocument.js new file mode 100644 index 0000000000..e3adcec609 --- /dev/null +++ b/src/store/identificationDocument.js @@ -0,0 +1,43 @@ +/** + * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { defineStore } from 'pinia' +import { loadState } from '@nextcloud/initial-state' + +export const useIdentificationDocumentStore = function(...args) { + const store = defineStore('identificationDocument', { + state: () => ({ + modal: false, + enabled: loadState('libresign', 'needIdentificationDocuments', false), + waitingApproval: loadState('libresign', 'identificationDocumentsWaitingApproval', false), + }), + actions: { + needIdentificationDocument() { + return this.enabled && !this.waitingApproval + }, + setEnabled(enabled) { + this.enabled = enabled + }, + setWaitingApproval(waitingApproval) { + this.waitingApproval = waitingApproval + }, + showModal() { + this.modal = true + }, + closeModal() { + this.modal = false + } + }, + }) + + const identificationDocumentStore = store(...args) + + // Make sure we only register the listeners once + if (!identificationDocumentStore._initialized) { + identificationDocumentStore._initialized = true + } + + return identificationDocumentStore +} diff --git a/src/views/SignPDF/_partials/Sign.vue b/src/views/SignPDF/_partials/Sign.vue index 49e014ef14..dde4c28303 100644 --- a/src/views/SignPDF/_partials/Sign.vue +++ b/src/views/SignPDF/_partials/Sign.vue @@ -18,6 +18,18 @@ {{ t('libresign', 'Sign the document.') }} +
+

+ {{ t('libresign', 'Identification documents') }} +

+ + {{ t('libresign', 'Your profile documents') }} + +

{{ t('libresign', 'Please define your sign password') }} @@ -46,6 +58,13 @@

+ + +