From c03a56f69fb774c3399f8147bf8e5521da9769ea Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 28 Mar 2025 09:28:24 +0100 Subject: [PATCH 1/3] feat: refs #7995 added hasAcl to check only one acl --- src/composables/useAcl.js | 11 +++++++++++ src/pages/Account/Card/AccountDescriptorMenu.vue | 10 +++------- src/pages/Customer/Card/CustomerBalance.vue | 6 ++---- .../Ticket/Card/BasicData/TicketBasicDataForm.vue | 4 +--- src/pages/Ticket/Card/TicketSaleMoreActions.vue | 4 +--- src/pages/Travel/Card/TravelDescriptorMenuItems.vue | 2 +- src/pages/Worker/Card/WorkerCalendar.vue | 4 +--- src/pages/Worker/Card/WorkerLocker.vue | 8 ++------ src/pages/Worker/Card/WorkerTimeControl.vue | 8 ++------ 9 files changed, 24 insertions(+), 33 deletions(-) diff --git a/src/composables/useAcl.js b/src/composables/useAcl.js index ede3591866c..581e553aab1 100644 --- a/src/composables/useAcl.js +++ b/src/composables/useAcl.js @@ -30,9 +30,20 @@ export function useAcl() { return false; } + function hasAcl(model, props, accessType) { + const modelAcl = state.getAcls().value[model]; + const access = modelAcl[props]; + if (!modelAcl || !access) return false; + if (access[accessType] || access['*']) { + return true; + } + return false; + } + 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)); From f8cc7b95abe28463859b7e02e7daf705330f38e5 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 31 Mar 2025 09:51:40 +0200 Subject: [PATCH 2/3] refactor: refs #7995 modified hasAcl function --- src/composables/useAcl.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/composables/useAcl.js b/src/composables/useAcl.js index 581e553aab1..4033ee9a6a4 100644 --- a/src/composables/useAcl.js +++ b/src/composables/useAcl.js @@ -32,12 +32,13 @@ export function useAcl() { function hasAcl(model, props, accessType) { const modelAcl = state.getAcls().value[model]; - const access = modelAcl[props]; - if (!modelAcl || !access) return false; - if (access[accessType] || access['*']) { - return true; - } - return false; + const propAcl = modelAcl[props] || {}; + return !!( + propAcl[accessType] || + modelAcl['*']?.[accessType] || + propAcl['*'] || + modelAcl['*']?.['*'] + ); } return { From b00d89a4bee022b8810ff7b308332e8691cce30f Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 1 Apr 2025 09:34:38 +0200 Subject: [PATCH 3/3] perf: refs #7995 has acl function --- src/composables/useAcl.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/composables/useAcl.js b/src/composables/useAcl.js index 4033ee9a6a4..52704fee9bf 100644 --- a/src/composables/useAcl.js +++ b/src/composables/useAcl.js @@ -30,15 +30,10 @@ export function useAcl() { return false; } - function hasAcl(model, props, accessType) { + function hasAcl(model, prop, accessType) { const modelAcl = state.getAcls().value[model]; - const propAcl = modelAcl[props] || {}; - return !!( - propAcl[accessType] || - modelAcl['*']?.[accessType] || - propAcl['*'] || - modelAcl['*']?.['*'] - ); + const propAcl = modelAcl?.[prop] || modelAcl?.['*']; + return !!(propAcl?.[accessType] || propAcl?.['*']); } return {