|
43 | 43 | </div> |
44 | 44 | </NcSettingsSection> |
45 | 45 | </template> |
46 | | -<script> |
| 46 | +<script setup lang="ts"> |
47 | 47 | import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch' |
48 | 48 | import NcSettingsSection from '@nextcloud/vue/components/NcSettingsSection' |
49 | 49 | import { t } from '@nextcloud/l10n' |
| 50 | +import { computed, onMounted, watch } from 'vue' |
50 | 51 |
|
51 | 52 | import { useConfigureCheckStore } from '../../store/configureCheck.js' |
52 | 53 |
|
53 | | -export default { |
| 54 | +defineOptions({ |
54 | 55 | name: 'IdentificationFactors', |
55 | | - components: { |
56 | | - NcCheckboxRadioSwitch, |
57 | | - NcSettingsSection, |
58 | | - }, |
59 | | - setup() { |
60 | | - const configureCheckStore = useConfigureCheckStore() |
61 | | - return { t, configureCheckStore } |
62 | | - }, |
63 | | - computed: { |
64 | | - description() { |
65 | | - // TRANSLATORS Name of a section at "Administration Settings" of LibreSign that an admin can configure the ways that a person will be identified when accessing the link to sign a document. |
66 | | - return t('libresign', 'Ways to identify a person who will sign a document.') |
67 | | - }, |
68 | | - isNoneEngine() { |
69 | | - return this.configureCheckStore.isNoneEngine |
70 | | - }, |
71 | | - identifyMethods() { |
72 | | - return this.configureCheckStore.identifyMethods |
73 | | - }, |
74 | | - }, |
75 | | - mounted() { |
76 | | - this.updateSignatureMethodsEnabled() |
77 | | - }, |
78 | | - watch: { |
79 | | - identifyMethods: { |
80 | | - handler() { |
81 | | - this.updateSignatureMethodsEnabled() |
82 | | - }, |
83 | | - deep: true, |
84 | | - }, |
85 | | - }, |
86 | | - methods: { |
87 | | - updateSignatureMethodsEnabled() { |
88 | | - this.identifyMethods.forEach((identifyMethod) => { |
89 | | - if (!Object.hasOwn(identifyMethod, 'signatureMethodEnabled')) { |
90 | | - identifyMethod.signatureMethodEnabled = '' |
91 | | - } |
92 | | - if (identifyMethod.signatureMethodEnabled.length === 0) { |
93 | | - const signatureMethodEnabled = Object.keys(identifyMethod.signatureMethods) |
94 | | - .reduce((signatureMethodEnabled, signatureMethodName) => { |
95 | | - if (signatureMethodEnabled.length === 0 && identifyMethod.signatureMethods[signatureMethodName].enabled) { |
96 | | - signatureMethodEnabled = signatureMethodName |
97 | | - } |
98 | | - return signatureMethodEnabled |
99 | | - }, identifyMethod.signatureMethodEnabled) |
100 | | - if (signatureMethodEnabled.length > 0) { |
101 | | - identifyMethod.signatureMethodEnabled = signatureMethodEnabled |
102 | | - } else { |
103 | | - identifyMethod.signatureMethodEnabled = Object.keys(identifyMethod.signatureMethods)[0] |
| 56 | +}) |
| 57 | +
|
| 58 | +type SignatureMethod = { |
| 59 | + enabled: boolean |
| 60 | + label?: string |
| 61 | +} |
| 62 | +
|
| 63 | +type IdentifyMethod = { |
| 64 | + name: string |
| 65 | + friendly_name: string |
| 66 | + enabled: boolean |
| 67 | + can_create_account?: boolean |
| 68 | + mandatory?: boolean |
| 69 | + signatureMethods: Record<string, SignatureMethod> |
| 70 | + signatureMethodEnabled?: string |
| 71 | +} |
| 72 | +
|
| 73 | +type ConfigureCheckStore = { |
| 74 | + isNoneEngine: boolean |
| 75 | + identifyMethods: IdentifyMethod[] |
| 76 | +} |
| 77 | +
|
| 78 | +type AppConfigGlobal = { |
| 79 | + AppConfig: { |
| 80 | + setValue: (app: string, key: string, value: string) => void |
| 81 | + } |
| 82 | +} |
| 83 | +
|
| 84 | +const configureCheckStore = useConfigureCheckStore() as ConfigureCheckStore |
| 85 | +
|
| 86 | +const description = computed(() => { |
| 87 | + // TRANSLATORS Name of a section at "Administration Settings" of LibreSign that an admin can configure the ways that a person will be identified when accessing the link to sign a document. |
| 88 | + return t('libresign', 'Ways to identify a person who will sign a document.') |
| 89 | +}) |
| 90 | +
|
| 91 | +const isNoneEngine = computed(() => configureCheckStore.isNoneEngine) |
| 92 | +const identifyMethods = computed(() => configureCheckStore.identifyMethods) |
| 93 | +
|
| 94 | +function updateSignatureMethodsEnabled() { |
| 95 | + identifyMethods.value.forEach((identifyMethod) => { |
| 96 | + if (!Object.hasOwn(identifyMethod, 'signatureMethodEnabled')) { |
| 97 | + identifyMethod.signatureMethodEnabled = '' |
| 98 | + } |
| 99 | +
|
| 100 | + if (identifyMethod.signatureMethodEnabled.length === 0) { |
| 101 | + const selectedSignatureMethod = Object.keys(identifyMethod.signatureMethods) |
| 102 | + .reduce((currentSelection, signatureMethodName) => { |
| 103 | + if (currentSelection.length === 0 && identifyMethod.signatureMethods[signatureMethodName].enabled) { |
| 104 | + return signatureMethodName |
104 | 105 | } |
105 | | - } |
106 | | - Object.keys(identifyMethod.signatureMethods).forEach(signatureMethodName => { |
107 | | - identifyMethod.signatureMethods[signatureMethodName].enabled |
108 | | - = identifyMethod.signatureMethodEnabled === signatureMethodName |
109 | | - }) |
110 | | - }) |
111 | | - }, |
112 | | - save() { |
113 | | - this.updateSignatureMethodsEnabled() |
114 | | - // Get only enabled |
115 | | - let props = this.identifyMethods.filter(identifyMethod => identifyMethod.enabled) |
116 | | - // Remove label from signature method, we don't need to save this |
117 | | - props = JSON.parse(JSON.stringify(props)) |
118 | | - .map(identifyMethod => { |
119 | | - Object.keys(identifyMethod.signatureMethods).forEach(id => { |
120 | | - Object.keys(identifyMethod.signatureMethods[id]).forEach(signatureMethdoPropName => { |
121 | | - if (signatureMethdoPropName === 'label') { |
122 | | - delete identifyMethod.signatureMethods[id][signatureMethdoPropName] |
123 | | - } |
124 | | - }) |
125 | | - }) |
126 | | - return identifyMethod |
127 | | - }) |
128 | | - OCP.AppConfig.setValue('libresign', 'identify_methods', |
129 | | - JSON.stringify(props), |
130 | | - ) |
131 | | - }, |
132 | | - }, |
| 106 | + return currentSelection |
| 107 | + }, identifyMethod.signatureMethodEnabled) |
| 108 | +
|
| 109 | + identifyMethod.signatureMethodEnabled = selectedSignatureMethod.length > 0 |
| 110 | + ? selectedSignatureMethod |
| 111 | + : Object.keys(identifyMethod.signatureMethods)[0] |
| 112 | + } |
| 113 | +
|
| 114 | + Object.keys(identifyMethod.signatureMethods).forEach((signatureMethodName) => { |
| 115 | + identifyMethod.signatureMethods[signatureMethodName].enabled = identifyMethod.signatureMethodEnabled === signatureMethodName |
| 116 | + }) |
| 117 | + }) |
133 | 118 | } |
| 119 | +
|
| 120 | +function save() { |
| 121 | + updateSignatureMethodsEnabled() |
| 122 | +
|
| 123 | + const props = JSON.parse(JSON.stringify( |
| 124 | + identifyMethods.value.filter((identifyMethod) => identifyMethod.enabled), |
| 125 | + )) as IdentifyMethod[] |
| 126 | +
|
| 127 | + props.forEach((identifyMethod) => { |
| 128 | + Object.keys(identifyMethod.signatureMethods).forEach((id) => { |
| 129 | + delete identifyMethod.signatureMethods[id].label |
| 130 | + }) |
| 131 | + }) |
| 132 | +
|
| 133 | + ;(globalThis as typeof globalThis & { OCP: AppConfigGlobal }).OCP.AppConfig.setValue( |
| 134 | + 'libresign', |
| 135 | + 'identify_methods', |
| 136 | + JSON.stringify(props), |
| 137 | + ) |
| 138 | +} |
| 139 | +
|
| 140 | +onMounted(() => { |
| 141 | + updateSignatureMethodsEnabled() |
| 142 | +}) |
| 143 | +
|
| 144 | +watch(identifyMethods, () => { |
| 145 | + updateSignatureMethodsEnabled() |
| 146 | +}, { deep: true }) |
| 147 | +
|
| 148 | +defineExpose({ |
| 149 | + description, |
| 150 | + isNoneEngine, |
| 151 | + identifyMethods, |
| 152 | + updateSignatureMethodsEnabled, |
| 153 | + save, |
| 154 | +}) |
134 | 155 | </script> |
135 | 156 | <style lang="scss" scoped> |
136 | 157 | .settings-section{ |
|
0 commit comments