Skip to content

Commit

Permalink
refactor: attach document
Browse files Browse the repository at this point in the history
Signed-off-by: Vitor Mattos <vitor@php.rio>
  • Loading branch information
vitormattos committed Jan 27, 2025
1 parent c4b306e commit ee7e36f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
16 changes: 14 additions & 2 deletions lib/Service/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
43 changes: 43 additions & 0 deletions src/store/identificationDocument.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { defineStore } from 'pinia'

Check failure on line 6 in src/store/identificationDocument.js

View workflow job for this annotation

GitHub Actions / NPM lint

There should be at least one empty line between import groups
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
}

Check warning on line 31 in src/store/identificationDocument.js

View workflow job for this annotation

GitHub Actions / NPM lint

Missing trailing comma
},
})

const identificationDocumentStore = store(...args)

// Make sure we only register the listeners once
if (!identificationDocumentStore._initialized) {
identificationDocumentStore._initialized = true
}

return identificationDocumentStore
}
28 changes: 27 additions & 1 deletion src/views/SignPDF/_partials/Sign.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
</template>
{{ t('libresign', 'Sign the document.') }}
</NcButton>
<div v-else-if="identificationDocumentStore.enabled">
<p>
{{ t('libresign', 'Identification documents') }}
</p>
<NcButton v-if="identificationDocumentStore.enabled"
:wide="true"
:disabled="loading"
type="primary"
@click="identificationDocumentStore.showModal()">
{{ t('libresign', 'Your profile documents') }}
</NcButton>
</div>
<div v-else-if="signMethodsStore.needCreatePassword()">
<p>
{{ t('libresign', 'Please define your sign password') }}
Expand Down Expand Up @@ -46,6 +58,13 @@
</p>
</div>
</div>
<NcDialog v-if="identificationDocumentStore.modal"
:can-close="!loading"
:name="t('libresign', 'Your profile documents')"
size="normal"
@closing="identificationDocumentStore.closeModal()">
<Documents />
</NcDialog>
<NcDialog v-if="signMethodsStore.modal.clickToSign"
:can-close="!loading"
:name="t('libresign', 'Confirm')"
Expand Down Expand Up @@ -120,6 +139,7 @@ import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
import NcPasswordField from '@nextcloud/vue/dist/Components/NcPasswordField.js'

import Documents from '../../Account/partials/Documents.vue'

Check failure on line 142 in src/views/SignPDF/_partials/Sign.vue

View workflow job for this annotation

GitHub Actions / NPM lint

`../../Account/partials/Documents.vue` import should occur after import of `../../../views/CreatePassword.vue`
import EmailManager from './ModalEmailManager.vue'
import SMSManager from './ModalSMSManager.vue'
import Draw from '../../../Components/Draw/Draw.vue'
Expand All @@ -131,6 +151,7 @@ import { useSidebarStore } from '../../../store/sidebar.js'
import { useSignStore } from '../../../store/sign.js'

Check failure on line 151 in src/views/SignPDF/_partials/Sign.vue

View workflow job for this annotation

GitHub Actions / NPM lint

`../../../store/sign.js` import should occur after import of `../../../store/identificationDocument.js`
import { useSignatureElementsStore } from '../../../store/signatureElements.js'

Check failure on line 152 in src/views/SignPDF/_partials/Sign.vue

View workflow job for this annotation

GitHub Actions / NPM lint

`../../../store/signatureElements.js` import should occur after import of `../../../store/identificationDocument.js`
import { useSignMethodsStore } from '../../../store/signMethods.js'

Check failure on line 153 in src/views/SignPDF/_partials/Sign.vue

View workflow job for this annotation

GitHub Actions / NPM lint

`../../../store/signMethods.js` import should occur after import of `../../../store/identificationDocument.js`
import { useIdentificationDocumentStore } from '../../../store/identificationDocument.js'

export default {
name: 'Sign',
Expand All @@ -140,6 +161,7 @@ export default {
NcLoadingIcon,
NcPasswordField,
CreatePassword,
Documents,
SMSManager,
EmailManager,
Signatures,
Expand All @@ -151,7 +173,8 @@ export default {
const signMethodsStore = useSignMethodsStore()
const signatureElementsStore = useSignatureElementsStore()
const sidebarStore = useSidebarStore()
return { signStore, signMethodsStore, signatureElementsStore, sidebarStore }
const identificationDocumentStore = useIdentificationDocumentStore()
return { signStore, signMethodsStore, signatureElementsStore, sidebarStore, identificationDocumentStore }
},
data() {
return {
Expand Down Expand Up @@ -192,6 +215,9 @@ export default {
if (this.signMethodsStore.needCreatePassword()) {
return false
}
if (this.identificationDocumentStore.needIdentificationDocument()) {
return false
}
if (this.needCreateSignature) {
return false
}
Expand Down

0 comments on commit ee7e36f

Please sign in to comment.