Skip to content

Commit ec200ad

Browse files
authored
Merge pull request #6707 from LibreSign/backport/6705/stable33
[stable33] fix: add able to sign getter
2 parents eb7f798 + 8ec984d commit ec200ad

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

src/store/sign.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import axios from '@nextcloud/axios'
1313
import { useFilesStore } from './files.js'
1414
import { useSidebarStore } from './sidebar.js'
1515
import { useSignMethodsStore } from './signMethods.js'
16+
import { FILE_STATUS } from '../constants.js'
1617

1718
const defaultState = {
1819
errors: [],
@@ -36,6 +37,26 @@ const defaultState = {
3637
export const useSignStore = defineStore('sign', {
3738
state: () => ({ ...defaultState }),
3839

40+
getters: {
41+
ableToSign(state) {
42+
const allowedStatuses = [FILE_STATUS.ABLE_TO_SIGN, FILE_STATUS.PARTIAL_SIGNED]
43+
if (!allowedStatuses.includes(state.document?.status)) {
44+
return false
45+
}
46+
47+
const mySigner = state.document?.signers?.find(signer => signer.me)
48+
if (!mySigner) {
49+
return false
50+
}
51+
52+
if (mySigner.status !== 1) {
53+
return false
54+
}
55+
56+
return true
57+
},
58+
},
59+
3960
actions: {
4061
async initFromState() {
4162
this.errors = loadState('libresign', 'errors', [])

src/store/sign.spec.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { describe, expect, it, beforeEach } from 'vitest'
77
import { setActivePinia, createPinia } from 'pinia'
88
import { useSignStore } from './sign.js'
9+
import { FILE_STATUS } from '../constants.js'
910

1011
describe('useSignStore', () => {
1112
beforeEach(() => {
@@ -44,4 +45,66 @@ describe('useSignStore', () => {
4445
expect(store.pendingAction).toBe('createPassword')
4546
})
4647
})
48+
49+
describe('ableToSign getter', () => {
50+
it('returns false when document status is not ABLE_TO_SIGN or PARTIAL_SIGNED', () => {
51+
const store = useSignStore()
52+
store.document = {
53+
status: FILE_STATUS.DRAFT,
54+
signers: [{ me: true, status: 1 }],
55+
}
56+
expect(store.ableToSign).toBe(false)
57+
})
58+
59+
it('returns false when there is no signer with me: true', () => {
60+
const store = useSignStore()
61+
store.document = {
62+
status: FILE_STATUS.ABLE_TO_SIGN,
63+
signers: [{ me: false, status: 1 }],
64+
}
65+
expect(store.ableToSign).toBe(false)
66+
})
67+
68+
it('returns false when signer status is not ABLE_TO_SIGN (status 1)', () => {
69+
const store = useSignStore()
70+
store.document = {
71+
status: FILE_STATUS.ABLE_TO_SIGN,
72+
signers: [{ me: true, status: 0 }],
73+
}
74+
expect(store.ableToSign).toBe(false)
75+
})
76+
77+
it('returns true when document status is ABLE_TO_SIGN and signer can sign', () => {
78+
const store = useSignStore()
79+
store.document = {
80+
status: FILE_STATUS.ABLE_TO_SIGN,
81+
signers: [{ me: true, status: 1 }],
82+
}
83+
expect(store.ableToSign).toBe(true)
84+
})
85+
86+
it('returns true when document status is PARTIAL_SIGNED and signer can sign', () => {
87+
const store = useSignStore()
88+
store.document = {
89+
status: FILE_STATUS.PARTIAL_SIGNED,
90+
signers: [{ me: true, status: 1 }],
91+
}
92+
expect(store.ableToSign).toBe(true)
93+
})
94+
95+
it('returns false when document is undefined', () => {
96+
const store = useSignStore()
97+
store.document = undefined
98+
expect(store.ableToSign).toBe(false)
99+
})
100+
101+
it('returns false when signers array is empty', () => {
102+
const store = useSignStore()
103+
store.document = {
104+
status: FILE_STATUS.ABLE_TO_SIGN,
105+
signers: [],
106+
}
107+
expect(store.ableToSign).toBe(false)
108+
})
109+
})
47110
})

0 commit comments

Comments
 (0)