From 0e7e804475de24d22033c44211576858473d3fcc Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 3 May 2024 13:18:46 +0200 Subject: [PATCH 01/29] feat: refs #6598 create useAcl composable --- src/composables/useAcl.js | 35 +++++++++++++++++++++++++++++++++++ src/composables/useSession.js | 2 ++ src/composables/useState.js | 11 +++++++++++ src/router/index.js | 2 ++ 4 files changed, 50 insertions(+) create mode 100644 src/composables/useAcl.js diff --git a/src/composables/useAcl.js b/src/composables/useAcl.js new file mode 100644 index 000000000..3121646f1 --- /dev/null +++ b/src/composables/useAcl.js @@ -0,0 +1,35 @@ +import { useState } from './useState'; +import axios from 'axios'; + +export function useAcl() { + const state = useState(); + + async function fetch() { + const { data } = await axios.get('VnUsers/acls'); + const acls = {}; + data.forEach((acl) => { + acls[acl.model] = acls[acl.model] || {}; + acls[acl.model][acl.property] = acls[acl.model][acl.property] || {}; + acls[acl.model][acl.property][acl.accessType] = true; + }); + + state.setAcls(acls); + } + + function hasAny(model, property, accessType) { + const acls = acls[model]; + if (acls) { + for (const prop of ['*', property]) { + const acl = acls[prop]; + if (acl && (acl['*'] || acl[accessType])) return true; + } + } + return false; + } + + return { + fetch, + hasAny, + state, + }; +} diff --git a/src/composables/useSession.js b/src/composables/useSession.js index 56bce0279..ca2abef00 100644 --- a/src/composables/useSession.js +++ b/src/composables/useSession.js @@ -1,5 +1,6 @@ import { useState } from './useState'; import { useRole } from './useRole'; +import { useAcl } from './useAcl'; import { useUserConfig } from './useUserConfig'; import axios from 'axios'; import useNotify from './useNotify'; @@ -88,6 +89,7 @@ export function useSession() { setSession(data); await useRole().fetch(); + await useAcl().fetch(); await useUserConfig().fetch(); await useTokenConfig().fetch(); diff --git a/src/composables/useState.js b/src/composables/useState.js index e671d41bd..95b9fdfd2 100644 --- a/src/composables/useState.js +++ b/src/composables/useState.js @@ -13,6 +13,7 @@ const user = ref({ }); const roles = ref([]); +const acls = ref([]); const tokenConfig = ref({}); const drawer = ref(true); const headerMounted = ref(false); @@ -53,6 +54,14 @@ export function useState() { function setRoles(data) { roles.value = data; } + + function getAcls() { + return computed(() => acls.value); + } + + function setAcls(data) { + acls.value = data; + } function getTokenConfig() { return computed(() => { return tokenConfig.value; @@ -80,6 +89,8 @@ export function useState() { setUser, getRoles, setRoles, + getAcls, + setAcls, getTokenConfig, setTokenConfig, set, diff --git a/src/router/index.js b/src/router/index.js index 7a0aedcae..41ff4c1da 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -13,6 +13,7 @@ import { useRole } from 'src/composables/useRole'; import { useUserConfig } from 'src/composables/useUserConfig'; import { toLowerCamel } from 'src/filters'; import { useTokenConfig } from 'src/composables/useTokenConfig'; +import { useAcl } from 'src/composables/useAcl'; const state = useState(); const session = useSession(); @@ -55,6 +56,7 @@ export default route(function (/* { store, ssrContext } */) { const stateRoles = state.getRoles().value; if (stateRoles.length === 0) { await useRole().fetch(); + await useAcl().fetch(); await useUserConfig().fetch(); await useTokenConfig().fetch(); } From 7c1ce7f56039b333bc1adf3156f0d0a761a430c6 Mon Sep 17 00:00:00 2001 From: jorgep Date: Fri, 3 May 2024 17:38:16 +0200 Subject: [PATCH 02/29] feat: refs #6243 replace url --- src/pages/Route/Cmr/CmrList.vue | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pages/Route/Cmr/CmrList.vue b/src/pages/Route/Cmr/CmrList.vue index 69f030fa0..6963baf41 100644 --- a/src/pages/Route/Cmr/CmrList.vue +++ b/src/pages/Route/Cmr/CmrList.vue @@ -91,8 +91,7 @@ function downloadPdfs() { }