diff --git a/src/router/adminGuard.ts b/src/router/adminGuard.ts index 83d1331..8016b7d 100644 --- a/src/router/adminGuard.ts +++ b/src/router/adminGuard.ts @@ -12,7 +12,14 @@ export async function abilityAndNavUpdate(to: any, from: any, next: any) { let section = to.meta.section; let module = to.meta.module; - if ((admin && ability.isAdmin()) || ability.can(type, section, module)) { + if (to.name == "admin-default") { + navigation.activeNavigation = "club"; + navigation.activeLink = null; + navigation.updateTopLevel(); + navigation.updateNavigation(); + NProgress.done(); + next(); + } else if ((admin && ability.isAdmin()) || ability.can(type, section, module)) { NProgress.done(); navigation.activeNavigation = to.name.split("-")[1]; navigation.activeLink = to.name.split("-")[2]; diff --git a/src/router/index.ts b/src/router/index.ts index 0be84bf..02cbdc3 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -15,7 +15,7 @@ const router = createRouter({ routes: [ { path: "/", - redirect: { name: "admin" }, + redirect: { name: "admin-default" }, }, { path: "/login", @@ -76,12 +76,13 @@ const router = createRouter({ path: "/admin", name: "admin", component: () => import("@/views/admin/View.vue"), - beforeEnter: [isAuthenticated], + beforeEnter: [isAuthenticated, abilityAndNavUpdate], children: [ { path: "", name: "admin-default", component: () => import("@/views/admin/ViewSelect.vue"), + beforeEnter: [abilityAndNavUpdate], }, { path: "club", diff --git a/src/stores/ability.ts b/src/stores/ability.ts index f65f6fe..ed65b5f 100644 --- a/src/stores/ability.ts +++ b/src/stores/ability.ts @@ -33,13 +33,21 @@ export const useAbilityStore = defineStore("ability", { if (type == "admin") return permissions?.admin ?? permissions?.adminByOwner ?? false; if (permissions?.admin || permissions?.adminByOwner) return true; if ( - permissions[section]?.all == "*" || - permissions[section]?.all?.includes(type) || + (permissions[section]?.all == "*" || permissions[section]?.all?.includes(type)) && permissions[section] != undefined ) return true; return false; }, + canAccessSection: + (state) => + (section: PermissionSection): boolean => { + const permissions = state.permissions; + if (state.isOwner) return true; + if (permissions?.admin || permissions?.adminByOwner) return true; + if (permissions[section] != undefined) return true; + return false; + }, isAdmin: (state) => (): boolean => { const permissions = state.permissions; if (state.isOwner) return true; @@ -72,13 +80,20 @@ export const useAbilityStore = defineStore("ability", { if (type == "admin") return permissions?.admin ?? permissions?.adminByOwner ?? false; if (permissions?.admin || permissions?.adminByOwner) return true; if ( - permissions[section]?.all == "*" || - permissions[section]?.all?.includes(type) || + (permissions[section]?.all == "*" || permissions[section]?.all?.includes(type)) && permissions[section] != undefined ) return true; return false; }, + _canAccessSection: + () => + (permissions: PermissionObject, section: PermissionSection): boolean => { + // ignores ownership + if (permissions?.admin || permissions?.adminByOwner) return true; + if (permissions[section] != undefined) return true; + return false; + }, }, actions: { setAbility(permissions: PermissionObject, isOwner: boolean) { diff --git a/src/stores/admin/navigation.ts b/src/stores/admin/navigation.ts index 8d43417..dfd93f4 100644 --- a/src/stores/admin/navigation.ts +++ b/src/stores/admin/navigation.ts @@ -48,7 +48,7 @@ export const useNavigationStore = defineStore("navigation", { updateTopLevel() { const abilityStore = useAbilityStore(); this.topLevel = [ - ...(abilityStore.canSection("read", "club") + ...(abilityStore.canAccessSection("club") ? [ { key: "club", @@ -57,7 +57,7 @@ export const useNavigationStore = defineStore("navigation", { } as topLevelNavigationModel, ] : []), - ...(abilityStore.canSection("read", "configuration") + ...(abilityStore.canAccessSection("configuration") ? [ { key: "configuration", @@ -66,7 +66,7 @@ export const useNavigationStore = defineStore("navigation", { } as topLevelNavigationModel, ] : []), - ...(abilityStore.canSection("read", "management") + ...(abilityStore.canAccessSection("management") ? [ { key: "management", @@ -147,7 +147,8 @@ export const useNavigationStore = defineStore("navigation", { this.activeNavigationObject.main.findIndex((e) => e.key == this.activeLink) == -1 || this.activeLink == "default" ) { - let link = this.activeNavigationObject.main[0].key; + let link = this.activeNavigationObject.main.filter((m) => !m.key.startsWith("divider"))[0].key; + this.activeLink = link; router.push({ name: `admin-${this.activeNavigation}-${link}` }); } }, diff --git a/src/templates/Main.vue b/src/templates/Main.vue index 7176f8e..ee95a6c 100644 --- a/src/templates/Main.vue +++ b/src/templates/Main.vue @@ -16,10 +16,13 @@
- +
+

{{ title }}

+ +
-
+
@@ -51,6 +54,10 @@ export default defineComponent({ type: Boolean, default: true, }, + title: { + type: String, + default: "", + }, }, computed: { ...mapState(useNavigationStore, ["activeLink", "activeNavigation"]), @@ -60,6 +67,9 @@ export default defineComponent({ rootRoute() { return ((this.$route?.name as string) ?? "").split("-")[0]; }, + topBar() { + return this.$slots.topBar; + }, diffMain() { return this.$slots.diffMain; }, diff --git a/src/views/account/Administration.vue b/src/views/account/Administration.vue index d2d0a3b..f95b89a 100644 --- a/src/views/account/Administration.vue +++ b/src/views/account/Administration.vue @@ -1,10 +1,5 @@