feat: refs #6598 create useAcl composable
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
e3a36c0ab1
commit
0e7e804475
|
@ -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,
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
import { useState } from './useState';
|
import { useState } from './useState';
|
||||||
import { useRole } from './useRole';
|
import { useRole } from './useRole';
|
||||||
|
import { useAcl } from './useAcl';
|
||||||
import { useUserConfig } from './useUserConfig';
|
import { useUserConfig } from './useUserConfig';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import useNotify from './useNotify';
|
import useNotify from './useNotify';
|
||||||
|
@ -88,6 +89,7 @@ export function useSession() {
|
||||||
setSession(data);
|
setSession(data);
|
||||||
|
|
||||||
await useRole().fetch();
|
await useRole().fetch();
|
||||||
|
await useAcl().fetch();
|
||||||
await useUserConfig().fetch();
|
await useUserConfig().fetch();
|
||||||
await useTokenConfig().fetch();
|
await useTokenConfig().fetch();
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ const user = ref({
|
||||||
});
|
});
|
||||||
|
|
||||||
const roles = ref([]);
|
const roles = ref([]);
|
||||||
|
const acls = ref([]);
|
||||||
const tokenConfig = ref({});
|
const tokenConfig = ref({});
|
||||||
const drawer = ref(true);
|
const drawer = ref(true);
|
||||||
const headerMounted = ref(false);
|
const headerMounted = ref(false);
|
||||||
|
@ -53,6 +54,14 @@ export function useState() {
|
||||||
function setRoles(data) {
|
function setRoles(data) {
|
||||||
roles.value = data;
|
roles.value = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAcls() {
|
||||||
|
return computed(() => acls.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setAcls(data) {
|
||||||
|
acls.value = data;
|
||||||
|
}
|
||||||
function getTokenConfig() {
|
function getTokenConfig() {
|
||||||
return computed(() => {
|
return computed(() => {
|
||||||
return tokenConfig.value;
|
return tokenConfig.value;
|
||||||
|
@ -80,6 +89,8 @@ export function useState() {
|
||||||
setUser,
|
setUser,
|
||||||
getRoles,
|
getRoles,
|
||||||
setRoles,
|
setRoles,
|
||||||
|
getAcls,
|
||||||
|
setAcls,
|
||||||
getTokenConfig,
|
getTokenConfig,
|
||||||
setTokenConfig,
|
setTokenConfig,
|
||||||
set,
|
set,
|
||||||
|
|
|
@ -13,6 +13,7 @@ import { useRole } from 'src/composables/useRole';
|
||||||
import { useUserConfig } from 'src/composables/useUserConfig';
|
import { useUserConfig } from 'src/composables/useUserConfig';
|
||||||
import { toLowerCamel } from 'src/filters';
|
import { toLowerCamel } from 'src/filters';
|
||||||
import { useTokenConfig } from 'src/composables/useTokenConfig';
|
import { useTokenConfig } from 'src/composables/useTokenConfig';
|
||||||
|
import { useAcl } from 'src/composables/useAcl';
|
||||||
|
|
||||||
const state = useState();
|
const state = useState();
|
||||||
const session = useSession();
|
const session = useSession();
|
||||||
|
@ -55,6 +56,7 @@ export default route(function (/* { store, ssrContext } */) {
|
||||||
const stateRoles = state.getRoles().value;
|
const stateRoles = state.getRoles().value;
|
||||||
if (stateRoles.length === 0) {
|
if (stateRoles.length === 0) {
|
||||||
await useRole().fetch();
|
await useRole().fetch();
|
||||||
|
await useAcl().fetch();
|
||||||
await useUserConfig().fetch();
|
await useUserConfig().fetch();
|
||||||
await useTokenConfig().fetch();
|
await useTokenConfig().fetch();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue