Skip to content

Commit

Permalink
Merge pull request #2763 from LibreSign/backport/2762/stable28
Browse files Browse the repository at this point in the history
[stable28] fix: load signature method saved
  • Loading branch information
vitormattos authored Apr 12, 2024
2 parents b31d0dd + bdbd527 commit 4aecc7d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 36 deletions.
4 changes: 3 additions & 1 deletion lib/Service/IdentifyMethod/AbstractIdentifyMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ private function loadSavedSettings(): void {
foreach ($this->availableSignatureMethods as $signatureMethodName) {
$this->signatureMethods[$signatureMethodName] =
$this->getEmptyInstanceOfSignatureMethodByName($signatureMethodName);
if (isset($this->settings[$signatureMethodName]['enabled']) && $this->settings[$signatureMethodName]['enabled']) {
if (isset($this->settings['signatureMethods'][$signatureMethodName]['enabled'])
&& $this->settings['signatureMethods'][$signatureMethodName]['enabled']
) {
$this->signatureMethods[$signatureMethodName]->enable();
$enabled = true;
}
Expand Down
27 changes: 11 additions & 16 deletions src/views/SignPDF/_partials/ModalEmailManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import md5 from 'blueimp-md5'
import { onError } from '../../../helpers/errors.js'
import { validateEmail } from '../../../utils/validators.js'
import { useSignMethodsStore } from '../../../store/signMethods.js'
import { useSignStore } from '../../../store/sign.js'
const sanitizeNumber = val => {
val = val.replace(/\D/g, '')
Expand All @@ -88,21 +89,10 @@ export default {
EmailIcon,
NcButton,
},
props: {
fileId: {
type: Number,
required: false,
default: 0,
},
uuid: {
type: String,
required: false,
default: '',
},
},
setup() {
const signStore = useSignStore()
const signMethodsStore = useSignMethodsStore()
return { signMethodsStore }
return { signStore, signMethodsStore }
},
data: () => ({
loading: false,
Expand Down Expand Up @@ -153,9 +143,11 @@ export default {
await this.$nextTick()
try {
if (this.fileId.length > 0) {
if (this.signStore.document.fileId) {
const { data } = await axios.post(
generateOcsUrl('/apps/libresign/api/v1/sign/file_id/{fileId}/code', { fileId: this.fileId }),
generateOcsUrl('/apps/libresign/api/v1/sign/file_id/{fileId}/code', {
fileId: this.signStore.document.fileId,
}),
{
identify: this.sendTo,
identifyMethod: this.signMethodsStore.settings.emailToken.identifyMethod,
Expand All @@ -164,8 +156,11 @@ export default {
)
showSuccess(data.message)
} else {
const signer = this.signStore.document.signers.find(row => row.me) || {}
const { data } = await axios.post(
generateOcsUrl('/apps/libresign/api/v1/sign/uuid/{uuid}/code', { uuid: this.uuid }),
generateOcsUrl('/apps/libresign/api/v1/sign/uuid/{uuid}/code', {
uuid: signer.sign_uuid,
}),
{
identify: this.sendTo,
identifyMethod: this.signMethodsStore.settings.emailToken.identifyMethod,
Expand Down
22 changes: 9 additions & 13 deletions src/views/SignPDF/_partials/ModalSMSManager.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { confirmPassword } from '@nextcloud/password-confirmation'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { onError } from '../../../helpers/errors.js'
import { settingsService } from '../../../domains/settings/index.js'
import { useSignStore } from '../../../store/sign.js'
const sanitizeNumber = val => {
val = val.replace(/\D/g, '')
Expand All @@ -74,16 +75,10 @@ export default {
type: String,
required: true,
},
fileId: {
type: Number,
required: false,
default: 0,
},
uuid: {
type: String,
required: false,
default: '',
},
},
setup() {
const signStore = useSignStore()
return { signStore }
},
data: () => ({
token: '',
Expand Down Expand Up @@ -123,14 +118,15 @@ export default {
await this.$nextTick()
try {
if (this.fileId.length > 0) {
if (this.signStore.document.fileId) {
const { data } = await axios.post(generateOcsUrl('/apps/libresign/api/v1/sign/file_id/{fileId}/code', {
fileId: this.fileId,
fileId: this.signStore.document.fileId,
}))
showSuccess(data.message)
} else {
const signer = this.signStore.document.signers.find(row => row.me) || {}
const { data } = await axios.post(generateOcsUrl('/apps/libresign/api/v1/sign/uuid/{fileId}/code', {
uuid: this.uuid,
uuid: signer.sign_uuid,
}))
showSuccess(data.message)
}
Expand Down
4 changes: 0 additions & 4 deletions src/views/SignPDF/_partials/Sign.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,11 @@
<CreatePassword @password:created="signMethodsStore.setHasSignatureFile" />
<SMSManager v-if="signMethodsStore.modal.sms"
:phone-number="user?.account?.phoneNumber"
:uuid="signStore.uuid"
:file-id="signStore.document.fileId"
@change="signWithSMSCode"
@update:phone="val => $emit('update:phone', val)"
@close="signMethodsStore.closeModal('sms')" />

<EmailManager v-if="signMethodsStore.modal.emailToken"
:uuid="signStore.uuid"
:file-id="signStore.document.fileId"
@change="signWithEmailToken"
@close="signMethodsStore.closeModal('emailToken')" />
</div>
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/features/admin/initial_state.feature
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ Feature: admin/initial_state
Scenario: Update identify methods and retrieve with success as initial state
Given as user "admin"
When sending "post" to ocs "/apps/provisioning_api/api/v1/config/apps/libresign/identify_methods"
| value | (string)[{"name":"account","enabled":true,"mandatory":true},{"name":"email","enabled":false,"mandatory":false}] |
| value | (string)[{"name":"account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":true}}},{"name":"email","enabled":false,"mandatory":false}] |
Then sending "get" to "/settings/admin/libresign"
And the response should contain the initial state "libresign-identify_methods" with the following values:
"""
[
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":true,"label":"Certificate with password","name":"password"}}},
{"name":"account","friendly_name":"Account","enabled":true,"mandatory":true,"signatureMethods":{"clickToSign":{"enabled":true,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":false,"label":"Email token","name":"emailToken"},"password":{"enabled":false,"label":"Certificate with password","name":"password"}}},
{"name":"email","friendly_name":"Email","enabled":false,"mandatory":false,"can_create_account":true,"test_url":"/index.php/settings/admin/mailtest","signatureMethods":{"clickToSign":{"enabled":false,"label":"Click to sign","name":"clickToSign"},"emailToken":{"enabled":true,"label":"Email token","name":"emailToken"}}}
]
"""

0 comments on commit 4aecc7d

Please sign in to comment.