Skip to content

Commit

Permalink
Merge pull request #2402 from LibreSign/feature/remove-old-store
Browse files Browse the repository at this point in the history
Remove references to old store
  • Loading branch information
vitormattos authored Feb 29, 2024
2 parents b3981b9 + 071812b commit 9f81702
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 111 deletions.
2 changes: 0 additions & 2 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import sidebar from './modules/sidebar.js'
import files from './modules/files.js'
import error from './modules/errors.js'
import settings from './modules/settings.js'
import user from './modules/user.js'

Vue.use(Vuex)

Expand Down Expand Up @@ -82,6 +81,5 @@ export default new Store({
sidebar,
files,
error,
user,
},
})
84 changes: 0 additions & 84 deletions src/store/modules/user.js

This file was deleted.

24 changes: 21 additions & 3 deletions src/store/signMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,38 @@ export const useSignMethodsStore = defineStore('signMethods', {
set(this.modal, modalCode, true)
},
blurredEmail() {
return this.settings.emailToken.blurredEmail
return this.settings?.emailToken?.blurredEmail ?? ''
},
hasEmailConfirmCode(hasConfirmCode) {
if (!Object.hasOwn(this.settings, 'emailToken')) {
set(this.settings, 'emailToken', {})
}
set(this.settings.emailToken, 'hasConfirmCode', hasConfirmCode)
},
setEmailToken(token) {
if (!Object.hasOwn(this.settings, 'emailToken')) {
set(this.settings, 'emailToken', {})
}
set(this.settings.emailToken, 'token', token)
},
hasSignatureFile(hasSignatureFile) {
hasSignatureFile() {
return Object.hasOwn(this.settings, 'password')
&& Object.hasOwn(this.settings.password, 'hasSignatureFile')
&& this.settings.password.hasSignatureFile
},
setHasSignatureFile(hasSignatureFile) {
if (!Object.hasOwn(this.settings, 'password')) {
set(this.settings, 'password', {})
}
set(this.settings.password, 'hasSignatureFile', hasSignatureFile)
},
needCreatePassword() {
return this.needSignWithPassword()
&& !this.settings.password.hasSignatureFile
&& (
!Object.hasOwn(this.settings, 'password')
|| !Object.hasOwn(this.settings.password, 'hasSignatureFile')
|| !this.settings.password.hasSignatureFile
)
},
needSignWithPassword() {
return Object.hasOwn(this.settings, 'password')
Expand Down
32 changes: 13 additions & 19 deletions src/views/Account/Account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
<NcButton @click="uploadCertificate()">
{{ t('libresign', 'Upload certificate') }}
</NcButton>
<NcButton v-if="getHasPfx" @click="deleteCertificate()">
<NcButton v-if="signMethodsStore.hasSignatureFile()" @click="deleteCertificate()">
{{ t('libresign', 'Delete certificate') }}
</NcButton>
<NcButton v-if="certificateEngine !== 'none' && !getHasPfx" @click="handleModal(true)">
<NcButton v-if="certificateEngine !== 'none' && !signMethodsStore.hasSignatureFile()" @click="handleModal(true)">
{{ t('libresign', 'Create certificate') }}
</NcButton>
<NcButton v-else-if="getHasPfx" @click="handleModal(true)">
<NcButton v-else-if="signMethodsStore.hasSignatureFile()" @click="handleModal(true)">
{{ t('librsign', 'Change password') }}
</NcButton>
</div>
<NcModal v-if="modal"
@close="handleModal(false)">
<CreatePassword v-if="!getHasPfx" @close="handleModal(false)" />
<ResetPassword v-if="getHasPfx" @close="handleModal(false)" />
<CreatePassword v-if="!signMethodsStore.hasSignatureFile()" @close="handleModal(false)" />
<ResetPassword v-if="signMethodsStore.hasSignatureFile()" @close="handleModal(false)" />
</NcModal>
</div>
</div>
Expand All @@ -52,12 +52,12 @@ import { loadState } from '@nextcloud/initial-state'
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { mapGetters } from 'vuex'
import CreatePassword from '../CreatePassword.vue'
import ResetPassword from '../ResetPassword.vue'
import UserImage from './partials/UserImage.vue'
import Signatures from './partials/Signatures.vue'
import Documents from './partials/Documents.vue'
import { useSignMethodsStore } from '../../store/signMethods.js'
export default {
name: 'Account',
Expand All @@ -72,6 +72,10 @@ export default {
UserImage,
Documents,
},
setup() {
const signMethodsStore = useSignMethodsStore()
return { signMethodsStore }
},
data() {
return {
Expand All @@ -80,14 +84,8 @@ export default {
certificateEngine: loadState('libresign', 'certificate_engine', ''),
}
},
computed: {
...mapGetters({
getHasPfx: 'getHasPfx',
}),
},
mounted() {
this.$store.commit('setHasPfx', loadState('libresign', 'config', {})?.hasSignatureFile ?? false)
this.signMethodsStore.setHasSignatureFile(loadState('libresign', 'config', {})?.hasSignatureFile ?? false)
},
methods: {
uploadCertificate() {
Expand All @@ -114,19 +112,15 @@ export default {
formData.append('file', file)
const response = await axios.post(generateOcsUrl('/apps/libresign/api/v1/account/pfx'), formData)
showSuccess(response.data.message)
if (this.$store) {
this.$store.commit('setHasPfx', true)
}
this.signMethodsStore.setHasSignatureFile(true)
} catch (err) {
showError(err.response.data.message)
}
},
async deleteCertificate() {
const response = await axios.delete(generateOcsUrl('/apps/libresign/api/v1/account/pfx'))
showSuccess(response.data.message)
if (this.$store) {
this.$store.commit('setHasPfx', false)
}
this.signMethodsStore.setHasSignatureFile(false)
},
handleModal(status) {
this.modal = status
Expand Down
4 changes: 2 additions & 2 deletions src/views/CreatePassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ export default {
signPassword: this.password,
})
showSuccess(t('libresign', 'New password to sign documents has been created'))
this.signMethodsStore.hasSignatureFile(true)
this.signMethodsStore.setHasSignatureFile(true)
this.clear()
this.$emit('close', true)
this.$emit('password:created', true)
} catch (err) {
this.signMethodsStore.hasSignatureFile(false)
this.signMethodsStore.setHasSignatureFile(false)
if (err.response.data.message) {
showError(err.response.data.message)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/views/SignPDF/_partials/Sign.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
@close="signMethodsStore.closeModal('createSignature')" />
<NcModal v-if="signMethodsStore.modal.createPassword"
@close="signMethodsStore.closeModal('createPassword')">
<CreatePassword @password:created="signMethodsStore.hasSignatureFile"
<CreatePassword @password:created="signMethodsStore.setHasSignatureFile"
@close="signMethodsStore.closeModal('createPassword')" />
</NcModal>
<SMSManager v-if="signMethodsStore.modal.sms"
Expand Down

0 comments on commit 9f81702

Please sign in to comment.