fix: navigation with restricted permissions

This commit is contained in:
Julian Krauser 2025-07-24 08:49:18 +02:00
parent 89bc0f9373
commit e10bfdd315
6 changed files with 18 additions and 7 deletions

View file

@ -6,7 +6,7 @@
<div class="w-full flex flex-row gap-2 h-full align-middle"> <div class="w-full flex flex-row gap-2 h-full align-middle">
<TopLevelLink <TopLevelLink
v-if="routeName == 'admin' || routeName.includes('admin-')" v-if="routeName == 'admin' || routeName.includes('admin-')"
v-for="item in topLevel" v-for="item in topLevelObject"
:key="item.key" :key="item.key"
:link="item" :link="item"
:disableSubLink="true" :disableSubLink="true"
@ -34,7 +34,7 @@ import TopLevelLink from "./admin/TopLevelLink.vue";
export default defineComponent({ export default defineComponent({
computed: { computed: {
...mapState(useAuthStore, ["authCheck"]), ...mapState(useAuthStore, ["authCheck"]),
...mapState(useNavigationStore, ["topLevel"]), ...mapState(useNavigationStore, ["topLevelObject"]),
routeName() { routeName() {
return typeof this.$route.name == "string" ? this.$route.name : ""; return typeof this.$route.name == "string" ? this.$route.name : "";
}, },

View file

@ -10,7 +10,7 @@
<div v-if="authCheck" class="hidden md:flex flex-row gap-2 h-full align-middle"> <div v-if="authCheck" class="hidden md:flex flex-row gap-2 h-full align-middle">
<TopLevelLink <TopLevelLink
v-if="routeName == 'admin' || routeName.includes('admin-')" v-if="routeName == 'admin' || routeName.includes('admin-')"
v-for="item in topLevel" v-for="item in topLevelObject"
:key="item.key" :key="item.key"
:link="item" :link="item"
/> />
@ -46,7 +46,7 @@ import { useConfigurationStore } from "@/stores/configuration";
export default defineComponent({ export default defineComponent({
computed: { computed: {
...mapState(useAuthStore, ["authCheck"]), ...mapState(useAuthStore, ["authCheck"]),
...mapState(useNavigationStore, ["topLevel"]), ...mapState(useNavigationStore, ["topLevelObject"]),
...mapState(useConfigurationStore, ["clubName"]), ...mapState(useConfigurationStore, ["clubName"]),
routeName() { routeName() {
return typeof this.$route.name == "string" ? this.$route.name : ""; return typeof this.$route.name == "string" ? this.$route.name : "";

View file

@ -19,11 +19,16 @@ export async function abilityAndNavUpdate(to: any, from: any, next: any) {
navigation.updateNavigation(); navigation.updateNavigation();
NProgress.done(); NProgress.done();
next(); next();
} else if ((admin && ability.isAdmin()) || ability.can(type, section, module)) { } else if (module && ((admin && ability.isAdmin()) || ability.can(type, section, module))) {
NProgress.done(); NProgress.done();
navigation.activeNavigation = to.name.split("-")[1]; navigation.activeNavigation = to.name.split("-")[1];
navigation.activeLink = to.name.split("-")[2]; navigation.activeLink = to.name.split("-")[2];
next(); next();
} else if (!module && ((admin && ability.isAdmin()) || ability.canSection(type, section))) {
NProgress.done();
navigation.activeNavigation = to.name.split("-")[1];
navigation.activeLink = null;
next();
} else { } else {
NProgress.done(); NProgress.done();
next({ name: "admin-default" }); next({ name: "admin-default" });

View file

@ -33,7 +33,8 @@ export const useAbilityStore = defineStore("ability", {
if (type == "admin") return permissions?.admin ?? permissions?.adminByOwner ?? false; if (type == "admin") return permissions?.admin ?? permissions?.adminByOwner ?? false;
if (permissions?.admin || permissions?.adminByOwner) return true; if (permissions?.admin || permissions?.adminByOwner) return true;
if ( if (
(permissions[section]?.all == "*" || permissions[section]?.all?.includes(type)) && permissions[section]?.all == "*" ||
permissions[section]?.all?.includes(type) ||
permissions[section] != undefined permissions[section] != undefined
) )
return true; return true;

View file

@ -37,6 +37,11 @@ export const useNavigationStore = defineStore("navigation", {
}; };
}, },
getters: { getters: {
topLevelObject: (state) =>
state.topLevel.map((tl) => ({
...tl,
levelDefault: state.navigation[tl.key].main.filter((m) => !m.key.includes("divider"))[0]?.key ?? "",
})),
activeNavigationObject: (state) => (state.navigation[state.activeNavigation] ?? {}) as navigationSplitModel, activeNavigationObject: (state) => (state.navigation[state.activeNavigation] ?? {}) as navigationSplitModel,
activeTopLevelObject: (state) => activeTopLevelObject: (state) =>
(state.topLevel.find((elem) => elem.key == state.activeNavigation) ?? {}) as topLevelNavigationModel, (state.topLevel.find((elem) => elem.key == state.activeNavigation) ?? {}) as topLevelNavigationModel,

View file

@ -1,5 +1,5 @@
<template> <template>
<div class="flex flex-col items-center"> <div class="flex flex-col gap-2 items-center">
<br /> <br />
<h1 class="w-full p-4 text-center font-bold text-3xl">Kein Zugriff</h1> <h1 class="w-full p-4 text-center font-bold text-3xl">Kein Zugriff</h1>
<br /> <br />