Skip to content

Commit 17345d0

Browse files
authored
Merge pull request #6358 from LibreSign/backport/6356/stable32
[stable32] refactor: unify signature request methods
2 parents 94c7a9a + f0a088f commit 17345d0

File tree

4 files changed

+9
-83
lines changed

4 files changed

+9
-83
lines changed

src/Components/Request/IdentifySigner.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export default {
223223
})
224224
225225
try {
226-
await this.filesStore.saveWithVisibleElements({ visibleElements: [] })
226+
await this.filesStore.saveOrUpdateSignatureRequest({})
227227
} catch (error) {
228228
console.error('Error saving signer:', error)
229229
}

src/Components/Request/VisibleElements.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ export default {
432432
const visibleElements = this.buildVisibleElements()
433433
434434
try {
435-
const response = await this.filesStore.saveWithVisibleElements({ visibleElements })
435+
const response = await this.filesStore.saveOrUpdateSignatureRequest({ visibleElements })
436436
showSuccess(t('libresign', response.message))
437437
this.closeModal()
438438
this.loading = false

src/Components/RightSidebar/RequestSignatureTab.vue

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -624,8 +624,7 @@ export default {
624624
this.debouncedSave = debounce(async () => {
625625
try {
626626
const file = this.filesStore.getFile()
627-
await this.filesStore.saveWithVisibleElements({
628-
visibleElements: [],
627+
await this.filesStore.saveOrUpdateSignatureRequest({
629628
signatureFlow: file?.signatureFlow,
630629
})
631630
} catch (error) {
@@ -874,9 +873,9 @@ export default {
874873
}
875874
return s
876875
})
877-
await this.filesStore.updateSignatureRequest({
878-
visibleElements: [],
876+
await this.filesStore.saveOrUpdateSignatureRequest({
879877
signers,
878+
status: 1,
880879
})
881880
showSuccess(t('libresign', 'Signature requested'))
882881
this.showConfirmRequestSigner = false
@@ -910,7 +909,7 @@ export default {
910909
async save() {
911910
this.hasLoading = true
912911
try {
913-
await this.filesStore.saveWithVisibleElements({ visibleElements: [] })
912+
await this.filesStore.saveOrUpdateSignatureRequest({})
914913
emit('libresign:show-visible-elements')
915914
} catch (error) {
916915
if (error.response?.data?.ocs?.data?.message) {
@@ -927,7 +926,7 @@ export default {
927926
async confirmRequest() {
928927
this.hasLoading = true
929928
try {
930-
const response = await this.filesStore.updateSignatureRequest({ visibleElements: [], status: 1 })
929+
const response = await this.filesStore.saveOrUpdateSignatureRequest({ status: 1 })
931930
showSuccess(t('libresign', response.message))
932931
this.showConfirmRequest = false
933932
} catch (error) {

src/store/files.js

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -509,81 +509,7 @@ export const useFilesStore = function(...args) {
509509
filesSorted() {
510510
return this.ordered.map(key => this.files[key])
511511
},
512-
async saveWithVisibleElements({ visibleElements = [], signers = null, uuid = null, fileId = null, signatureFlow = null }) {
513-
const file = this.getFile()
514-
515-
let flowValue = signatureFlow || file.signatureFlow
516-
if (typeof flowValue === 'number') {
517-
const flowMap = { 0: 'none', 1: 'parallel', 2: 'ordered_numeric' }
518-
flowValue = flowMap[flowValue] || 'parallel'
519-
}
520-
521-
const config = {
522-
url: generateOcsUrl('/apps/libresign/api/v1/request-signature'),
523-
method: uuid || file.uuid ? 'patch' : 'post',
524-
data: {
525-
name: file?.name,
526-
users: signers || file.signers || [],
527-
visibleElements,
528-
status: 0,
529-
signatureFlow: flowValue,
530-
},
531-
}
532-
533-
if (uuid || file.uuid) {
534-
config.data.uuid = uuid || file.uuid
535-
} else if (file.id) {
536-
config.data.file = { fileId: file.id }
537-
} else if (file.files) {
538-
config.data.files = file.files
539-
} else if (!isNaN(file.nodeId)) {
540-
config.data.file = { nodeId: file.nodeId }
541-
}
542-
543-
if (file.settings) {
544-
if (config.data.file) {
545-
config.data.file.settings = file.settings
546-
} else if (config.data.files) {
547-
config.data.settings = file.settings
548-
}
549-
}
550-
551-
const { data } = await axios(config)
552-
const responseFile = data?.ocs?.data
553-
554-
if (file.nodeType === 'envelope' && typeof file.nodeId === 'string' && responseFile.nodeId !== file.nodeId) {
555-
delete this.files[file.nodeId]
556-
const index = this.ordered.indexOf(file.nodeId)
557-
if (index !== -1) {
558-
this.ordered.splice(index, 1)
559-
}
560-
}
561-
562-
if (responseFile.nodeId) {
563-
const nodeId = responseFile.nodeId
564-
const existingFile = this.files[file.nodeId] || this.files[nodeId]
565-
if (existingFile?.settings) {
566-
responseFile.settings = { ...existingFile.settings, ...responseFile.settings }
567-
}
568-
set(this.files, nodeId, responseFile)
569-
this.addUniqueIdentifierToAllSigners(this.files[nodeId].signers)
570-
if (!this.ordered.includes(nodeId)) {
571-
this.ordered.push(nodeId)
572-
}
573-
if (this.selectedNodeId === file.nodeId) {
574-
this.selectedNodeId = nodeId
575-
}
576-
} else {
577-
this.addFile(responseFile)
578-
}
579-
const eventName = (!uuid && !file.uuid) ? 'libresign:file:created' : 'libresign:file:updated'
580-
emit(eventName, {
581-
path: responseFile.settings?.path,
582-
nodeId: responseFile.nodeId,
583-
})
584-
return data.ocs.data
585-
},
586-
async updateSignatureRequest({ visibleElements = [], signers = null, uuid = null, fileId = null, status = 1, signatureFlow = null }) {
512+
async saveOrUpdateSignatureRequest({ visibleElements = [], signers = null, uuid = null, fileId = null, status = 0, signatureFlow = null } = {}) {
587513
const file = this.getFile()
588514

589515
let flowValue = signatureFlow || file.signatureFlow
@@ -621,6 +547,7 @@ export const useFilesStore = function(...args) {
621547
config.data.settings = file.settings
622548
}
623549
}
550+
624551
const { data } = await axios(config)
625552
const responseFile = data?.ocs?.data
626553

0 commit comments

Comments
 (0)