ability section update

This commit is contained in:
Julian Krauser 2024-08-27 17:55:10 +02:00
parent 68efdc131b
commit eff79a4697
3 changed files with 18 additions and 4 deletions

View file

@ -26,6 +26,20 @@ export const useAbilityStore = defineStore("ability", {
return true;
return false;
},
canSection:
(state) =>
(type: PermissionType | "admin", section: PermissionSection): boolean => {
const permissions = state.permissions;
if (type == "admin") return permissions.admin ?? false;
if (permissions.admin) return true;
if (
permissions[section]?.all == "*" ||
permissions[section]?.all?.includes(type) ||
permissions[section] != undefined
)
return true;
return false;
},
_can:
() =>
(

View file

@ -81,7 +81,7 @@ export const useNavigationStore = defineStore("navigation", {
updateTopLevel() {
const abilityStore = useAbilityStore();
this.topLevel = [
...(abilityStore.can("read", "club")
...(abilityStore.canSection("read", "club")
? [
{
key: "club",
@ -90,7 +90,7 @@ export const useNavigationStore = defineStore("navigation", {
} as topLevelNavigationModel,
]
: []),
...(abilityStore.can("read", "settings")
...(abilityStore.canSection("read", "settings")
? [
{
key: "settings",
@ -99,7 +99,7 @@ export const useNavigationStore = defineStore("navigation", {
} as topLevelNavigationModel,
]
: []),
...(abilityStore.can("read", "user")
...(abilityStore.canSection("read", "user")
? [
{
key: "user",

View file

@ -12,7 +12,7 @@ export type PermissionModule =
| "user"
| "role";
export type PermissionType = "create" | "read" | "update" | "delete";
export type PermissionType = "read" | "create" | "update" | "delete";
export type PermissionString =
| `${PermissionSection}.${PermissionModule}.${PermissionType}` // für spezifische Berechtigungen