Skip to content

Commit ee7e36f

Browse files
committed
refactor: attach document
Signed-off-by: Vitor Mattos <vitor@php.rio>
1 parent c4b306e commit ee7e36f

File tree

4 files changed

+91
-3
lines changed

4 files changed

+91
-3
lines changed

lib/Controller/PageController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,18 @@ public function sign(string $uuid): TemplateResponse {
292292
->setFile($this->getFileEntity())
293293
->setHost($this->request->getServerHost())
294294
->setMe($this->userSession->getUser())
295+
->setSignerIdentified()
295296
->setIdentifyMethodId($this->sessionService->getIdentifyMethodId())
296297
->setSignRequest($this->getSignRequestEntity())
297298
->showVisibleElements()
298299
->showSigners()
300+
->showSettings()
299301
->toArray();
302+
$this->initialState->provideInitialState('config', [
303+
'identificationDocumentsFlow' => $file['settings']['needIdentificationDocuments'] ?? false,
304+
]);
305+
$this->initialState->provideInitialState('needIdentificationDocuments', $file['settings']['needIdentificationDocuments'] ?? false);
306+
$this->initialState->provideInitialState('identificationDocumentsWaitingApproval', $file['settings']['identificationDocumentsWaitingApproval'] ?? false);
300307
$this->initialState->provideInitialState('status', $file['status']);
301308
$this->initialState->provideInitialState('statusText', $file['statusText']);
302309
$this->initialState->provideInitialState('signers', $file['signers']);

lib/Service/FileService.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class FileService {
5252
private bool $showMessages = false;
5353
private bool $validateFile = false;
5454
private bool $signersLibreSignLoaded = false;
55+
private bool $signerIdentified = false;
5556
private string $fileContent = '';
5657
private string $host = '';
5758
private ?File $file = null;
@@ -141,6 +142,11 @@ public function setMe(?IUser $user): self {
141142
return $this;
142143
}
143144

145+
public function setSignerIdentified(bool $identified = true): self {
146+
$this->signerIdentified = $identified;
147+
return $this;
148+
}
149+
144150
public function setIdentifyMethodId(?int $id): self {
145151
$this->identifyMethodId = $id;
146152
return $this;
@@ -570,7 +576,9 @@ private function loadSettings(): void {
570576
if ($this->me) {
571577
$this->fileData->settings = array_merge($this->fileData->settings, $this->accountService->getSettings($this->me));
572578
$this->fileData->settings['phoneNumber'] = $this->getPhoneNumber();
573-
$status = $this->getIdentificationDocumentsStatus($this->me->getUID());
579+
}
580+
if ($this->signerIdentified || $this->me) {
581+
$status = $this->getIdentificationDocumentsStatus();
574582
if ($status === self::IDENTIFICATION_DOCUMENTS_NEED_SEND) {
575583
$this->fileData->settings['needIdentificationDocuments'] = true;
576584
$this->fileData->settings['identificationDocumentsWaitingApproval'] = false;
@@ -581,14 +589,18 @@ private function loadSettings(): void {
581589
}
582590
}
583591

584-
public function getIdentificationDocumentsStatus(?string $userId): int {
592+
public function getIdentificationDocumentsStatus(string $userId = ''): int {
585593
if (!$this->appConfig->getValueBool(Application::APP_ID, 'identification_documents', false)) {
586594
return self::IDENTIFICATION_DOCUMENTS_DISABLED;
587595
}
588596

597+
if (!$userId && $this->me instanceof IUser) {
598+
$userId = $this->me->getUID();
599+
}
589600
if (!empty($userId)) {
590601
$files = $this->fileMapper->getFilesOfAccount($userId);
591602
}
603+
592604
if (empty($files) || !count($files)) {
593605
return self::IDENTIFICATION_DOCUMENTS_NEED_SEND;
594606
}

src/store/identificationDocument.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import { defineStore } from 'pinia'
7+
import { loadState } from '@nextcloud/initial-state'
8+
9+
export const useIdentificationDocumentStore = function(...args) {
10+
const store = defineStore('identificationDocument', {
11+
state: () => ({
12+
modal: false,
13+
enabled: loadState('libresign', 'needIdentificationDocuments', false),
14+
waitingApproval: loadState('libresign', 'identificationDocumentsWaitingApproval', false),
15+
}),
16+
actions: {
17+
needIdentificationDocument() {
18+
return this.enabled && !this.waitingApproval
19+
},
20+
setEnabled(enabled) {
21+
this.enabled = enabled
22+
},
23+
setWaitingApproval(waitingApproval) {
24+
this.waitingApproval = waitingApproval
25+
},
26+
showModal() {
27+
this.modal = true
28+
},
29+
closeModal() {
30+
this.modal = false
31+
}
32+
},
33+
})
34+
35+
const identificationDocumentStore = store(...args)
36+
37+
// Make sure we only register the listeners once
38+
if (!identificationDocumentStore._initialized) {
39+
identificationDocumentStore._initialized = true
40+
}
41+
42+
return identificationDocumentStore
43+
}

src/views/SignPDF/_partials/Sign.vue

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@
1818
</template>
1919
{{ t('libresign', 'Sign the document.') }}
2020
</NcButton>
21+
<div v-else-if="identificationDocumentStore.enabled">
22+
<p>
23+
{{ t('libresign', 'Identification documents') }}
24+
</p>
25+
<NcButton v-if="identificationDocumentStore.enabled"
26+
:wide="true"
27+
:disabled="loading"
28+
type="primary"
29+
@click="identificationDocumentStore.showModal()">
30+
{{ t('libresign', 'Your profile documents') }}
31+
</NcButton>
32+
</div>
2133
<div v-else-if="signMethodsStore.needCreatePassword()">
2234
<p>
2335
{{ t('libresign', 'Please define your sign password') }}
@@ -46,6 +58,13 @@
4658
</p>
4759
</div>
4860
</div>
61+
<NcDialog v-if="identificationDocumentStore.modal"
62+
:can-close="!loading"
63+
:name="t('libresign', 'Your profile documents')"
64+
size="normal"
65+
@closing="identificationDocumentStore.closeModal()">
66+
<Documents />
67+
</NcDialog>
4968
<NcDialog v-if="signMethodsStore.modal.clickToSign"
5069
:can-close="!loading"
5170
:name="t('libresign', 'Confirm')"
@@ -120,6 +139,7 @@ import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js'
120139
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
121140
import NcPasswordField from '@nextcloud/vue/dist/Components/NcPasswordField.js'
122141
142+
import Documents from '../../Account/partials/Documents.vue'
123143
import EmailManager from './ModalEmailManager.vue'
124144
import SMSManager from './ModalSMSManager.vue'
125145
import Draw from '../../../Components/Draw/Draw.vue'
@@ -131,6 +151,7 @@ import { useSidebarStore } from '../../../store/sidebar.js'
131151
import { useSignStore } from '../../../store/sign.js'
132152
import { useSignatureElementsStore } from '../../../store/signatureElements.js'
133153
import { useSignMethodsStore } from '../../../store/signMethods.js'
154+
import { useIdentificationDocumentStore } from '../../../store/identificationDocument.js'
134155
135156
export default {
136157
name: 'Sign',
@@ -140,6 +161,7 @@ export default {
140161
NcLoadingIcon,
141162
NcPasswordField,
142163
CreatePassword,
164+
Documents,
143165
SMSManager,
144166
EmailManager,
145167
Signatures,
@@ -151,7 +173,8 @@ export default {
151173
const signMethodsStore = useSignMethodsStore()
152174
const signatureElementsStore = useSignatureElementsStore()
153175
const sidebarStore = useSidebarStore()
154-
return { signStore, signMethodsStore, signatureElementsStore, sidebarStore }
176+
const identificationDocumentStore = useIdentificationDocumentStore()
177+
return { signStore, signMethodsStore, signatureElementsStore, sidebarStore, identificationDocumentStore }
155178
},
156179
data() {
157180
return {
@@ -192,6 +215,9 @@ export default {
192215
if (this.signMethodsStore.needCreatePassword()) {
193216
return false
194217
}
218+
if (this.identificationDocumentStore.needIdentificationDocument()) {
219+
return false
220+
}
195221
if (this.needCreateSignature) {
196222
return false
197223
}

0 commit comments

Comments
 (0)