Skip to content

Commit 5703f64

Browse files
committed
refactor(ui): align docmdp settings presentation
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent b6d3dcd commit 5703f64

1 file changed

Lines changed: 78 additions & 34 deletions

File tree

src/views/Settings/DocMDP.vue

Lines changed: 78 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
<div>
1111
<NcCheckboxRadioSwitch type="switch"
1212
v-model="enabled"
13-
:disabled="loading"
13+
:disabled="loading || !canEdit"
1414
@update:modelValue="onEnabledChange">
1515
<!-- TRANSLATORS: Label for enabling DocMDP certification -->
1616
{{ t('libresign', 'Enable DocMDP') }}
1717
</NcCheckboxRadioSwitch>
1818
</div>
19+
<NcNoteCard v-if="!canEdit" type="info">
20+
{{ t('libresign', 'This setting is managed by higher-level policy (%s).', sourceScopeLabel) }}
21+
</NcNoteCard>
1922
<NcNoteCard v-if="errorMessage" type="error">
2023
{{ errorMessage }}
2124
</NcNoteCard>
@@ -30,7 +33,7 @@
3033
type="radio"
3134
v-model="selectedLevelValue"
3235
:value="String(level.value)"
33-
:disabled="loading"
36+
:disabled="loading || !canEdit"
3437
name="docmdp_level"
3538
@update:modelValue="onLevelChange">
3639
<div class="docmdp-option">
@@ -53,9 +56,6 @@
5356
</template>
5457

5558
<script setup lang="ts">
56-
import axios from '@nextcloud/axios'
57-
import { loadState } from '@nextcloud/initial-state'
58-
import { generateOcsUrl } from '@nextcloud/router'
5959
import { t } from '@nextcloud/l10n'
6060
import { computed, onMounted, ref } from 'vue'
6161
@@ -64,34 +64,76 @@ import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
6464
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
6565
import NcSavingIndicatorIcon from '@nextcloud/vue/components/NcSavingIndicatorIcon'
6666
import NcSettingsSection from '@nextcloud/vue/components/NcSettingsSection'
67-
import type { AdminDocMdpConfigState, AdminDocMdpLevelOption } from '../../types'
68-
import type { operations } from '../../types/openapi/openapi-administration'
67+
import { usePoliciesStore } from '../../store/policies'
68+
import type { EffectivePolicyState, SystemPolicyWriteErrorResponse } from '../../types'
6969
7070
defineOptions({
7171
name: 'DocMDP',
7272
})
7373
74-
type DocMdpRequestBody = operations['admin-set-doc-mdp-config']['requestBody']['content']['application/json']
75-
type DocMdpErrorResponse =
76-
| operations['admin-set-doc-mdp-config']['responses'][400]['content']['application/json']
77-
| operations['admin-set-doc-mdp-config']['responses'][500]['content']['application/json']
74+
type DocMdpLevelOption = {
75+
value: number
76+
label: string
77+
description: string
78+
}
7879
7980
type DocMdpRequestError = {
8081
response?: {
81-
data?: DocMdpErrorResponse
82+
data?: {
83+
ocs?: {
84+
data?: SystemPolicyWriteErrorResponse
85+
}
86+
}
8287
}
8388
}
8489
8590
const PREFERRED_DEFAULT_LEVEL = 2
91+
const DOCMDP_DISABLED_LEVEL = 0
8692
93+
const policiesStore = usePoliciesStore()
8794
const enabled = ref(false)
88-
const selectedLevel = ref<AdminDocMdpLevelOption | null>(null)
89-
const availableLevels = ref<AdminDocMdpLevelOption[]>([])
95+
const selectedLevel = ref<DocMdpLevelOption | null>(null)
9096
const loading = ref(false)
9197
const errorMessage = ref('')
9298
const saved = ref(false)
9399
const showErrorIcon = ref(false)
94100
101+
const docMdpPolicy = computed<EffectivePolicyState | null>(() => policiesStore.getPolicy('docmdp'))
102+
const canEdit = computed(() => docMdpPolicy.value?.editableByCurrentActor ?? true)
103+
104+
const availableLevels = computed<DocMdpLevelOption[]>(() => [
105+
{
106+
value: 1,
107+
label: t('libresign', 'No changes allowed'),
108+
description: t('libresign', 'After signing, no changes are allowed in the document.'),
109+
},
110+
{
111+
value: 2,
112+
label: t('libresign', 'Form filling'),
113+
description: t('libresign', 'After signing, only form filling is allowed.'),
114+
},
115+
{
116+
value: 3,
117+
label: t('libresign', 'Form filling and annotations'),
118+
description: t('libresign', 'After signing, form filling and annotations are allowed.'),
119+
},
120+
])
121+
122+
const sourceScopeLabel = computed(() => {
123+
switch (docMdpPolicy.value?.sourceScope) {
124+
case 'group':
125+
return t('libresign', 'group')
126+
case 'user':
127+
return t('libresign', 'user preference')
128+
case 'request':
129+
return t('libresign', 'request override')
130+
case 'global':
131+
return t('libresign', 'global')
132+
default:
133+
return t('libresign', 'system')
134+
}
135+
})
136+
95137
const name = computed(() => {
96138
return t('libresign', 'PDF certification (DocMDP)')
97139
})
@@ -107,26 +149,26 @@ const selectedLevelValue = computed({
107149
})
108150
109151
function getPreferredDefaultLevel() {
110-
return availableLevels.value.find(level => level.value === PREFERRED_DEFAULT_LEVEL)
152+
return availableLevels.value.find((level) => level.value === PREFERRED_DEFAULT_LEVEL)
111153
?? availableLevels.value[0]
112154
?? null
113155
}
114156
157+
function applyPolicy(policy: EffectivePolicyState | null) {
158+
const effectiveValue = Number(policy?.effectiveValue ?? DOCMDP_DISABLED_LEVEL)
159+
if (effectiveValue > DOCMDP_DISABLED_LEVEL) {
160+
enabled.value = true
161+
selectedLevel.value = availableLevels.value.find((level) => level.value === effectiveValue) ?? getPreferredDefaultLevel()
162+
return
163+
}
164+
165+
enabled.value = false
166+
selectedLevel.value = getPreferredDefaultLevel()
167+
}
168+
115169
function loadConfig() {
116170
try {
117-
const config = loadState<AdminDocMdpConfigState>('libresign', 'docmdp_config', {
118-
enabled: false,
119-
defaultLevel: PREFERRED_DEFAULT_LEVEL,
120-
availableLevels: [],
121-
})
122-
123-
enabled.value = config.enabled
124-
availableLevels.value = config.availableLevels
125-
selectedLevel.value = availableLevels.value.find(level => level.value === config.defaultLevel) ?? null
126-
127-
if (!selectedLevel.value) {
128-
selectedLevel.value = getPreferredDefaultLevel()
129-
}
171+
applyPolicy(docMdpPolicy.value)
130172
} catch (error) {
131173
console.error('Error loading DocMDP configuration:', error)
132174
errorMessage.value = t('libresign', 'Could not load configuration.')
@@ -163,12 +205,11 @@ async function saveConfig() {
163205
showErrorIcon.value = false
164206
165207
try {
166-
const url = generateOcsUrl('apps/libresign/api/v1/admin/docmdp/config')
167-
const payload: DocMdpRequestBody = {
168-
enabled: enabled.value,
169-
defaultLevel: enabled.value ? (selectedLevel.value?.value ?? 0) : 0,
170-
}
171-
await axios.post(url, payload)
208+
const savedPolicy = await policiesStore.saveSystemPolicy(
209+
'docmdp',
210+
enabled.value ? (selectedLevel.value?.value ?? PREFERRED_DEFAULT_LEVEL) : DOCMDP_DISABLED_LEVEL,
211+
)
212+
applyPolicy(savedPolicy)
172213
173214
saved.value = true
174215
setTimeout(() => {
@@ -178,6 +219,7 @@ async function saveConfig() {
178219
console.error('Error saving DocMDP configuration:', error)
179220
errorMessage.value = getErrorMessage(error) ?? t('libresign', 'Could not save configuration.')
180221
showErrorIcon.value = true
222+
applyPolicy(docMdpPolicy.value)
181223
setTimeout(() => {
182224
showErrorIcon.value = false
183225
}, 3000)
@@ -193,6 +235,8 @@ onMounted(() => {
193235
defineExpose({
194236
enabled,
195237
selectedLevel,
238+
canEdit,
239+
docMdpPolicy,
196240
onEnabledChange,
197241
})
198242
</script>

0 commit comments

Comments
 (0)