diff --git a/src/composables/useAcl.js b/src/composables/useAcl.js index ede3591866c..52704fee9bf 100644 --- a/src/composables/useAcl.js +++ b/src/composables/useAcl.js @@ -30,9 +30,16 @@ export function useAcl() { return false; } + function hasAcl(model, prop, accessType) { + const modelAcl = state.getAcls().value[model]; + const propAcl = modelAcl?.[prop] || modelAcl?.['*']; + return !!(propAcl?.[accessType] || propAcl?.['*']); + } + return { fetch, hasAny, state, + hasAcl, }; } diff --git a/src/pages/Account/Card/AccountDescriptorMenu.vue b/src/pages/Account/Card/AccountDescriptorMenu.vue index eafd62df60b..f3eabb53184 100644 --- a/src/pages/Account/Card/AccountDescriptorMenu.vue +++ b/src/pages/Account/Card/AccountDescriptorMenu.vue @@ -100,12 +100,8 @@ const onChangePass = (oldPass) => { }; onMounted(() => { - hasitManagementAccess.value = useAcl().hasAny([ - { model: 'VnUser', props: 'higherPrivileges', accessType: 'WRITE' }, - ]); - hasSysadminAccess.value = useAcl().hasAny([ - { model: 'VnUser', props: 'adminUser', accessType: 'WRITE' }, - ]); + hasitManagementAccess.value = useAcl().hasAcl('VnUser', 'higherPrivileges', 'WRITE'); + hasSysadminAccess.value = useAcl().hasAcl('VnUser', 'adminUser', 'WRITE'); }); diff --git a/src/pages/Worker/Card/WorkerTimeControl.vue b/src/pages/Worker/Card/WorkerTimeControl.vue index 9c0fa675836..b64166c7d65 100644 --- a/src/pages/Worker/Card/WorkerTimeControl.vue +++ b/src/pages/Worker/Card/WorkerTimeControl.vue @@ -68,13 +68,9 @@ const arrayData = useArrayData('Worker'); const acl = useAcl(); const selectedDateYear = computed(() => moment(selectedDate.value).isoWeekYear()); const worker = computed(() => arrayData.store?.data); -const canSend = computed(() => - acl.hasAny([{ model: 'WorkerTimeControl', props: 'sendMail', accessType: 'WRITE' }]), -); +const canSend = computed(() => acl.hasAcl('WorkerTimeControl', 'sendMail', 'WRITE')); const canUpdate = computed(() => - acl.hasAny([ - { model: 'WorkerTimeControl', props: 'updateMailState', accessType: 'WRITE' }, - ]), + acl.hasAcl('WorkerTimeControl', 'updateMailState', 'WRITE'), ); const isHimself = computed(() => user.value.id === Number(route.params.id));