diff --git a/src/components/admin/user/Permission.vue b/src/components/admin/Permission.vue similarity index 99% rename from src/components/admin/user/Permission.vue rename to src/components/admin/Permission.vue index 2f40ef4..7a5c0c2 100644 --- a/src/components/admin/user/Permission.vue +++ b/src/components/admin/Permission.vue @@ -85,7 +85,7 @@ import type { import { sectionsAndModules, permissionSections, permissionTypes } from "@/types/permissionTypes"; import { mapState, mapActions } from "pinia"; import { EyeIcon, PencilIcon, PlusIcon, TrashIcon } from "@heroicons/vue/outline"; -import { useAbilityStore } from "../../../stores/ability"; +import { useAbilityStore } from "@/stores/ability"; import _cloneDeep from "lodash.clonedeep"; diff --git a/src/components/admin/user/role/CreateRoleModal.vue b/src/components/admin/user/role/CreateRoleModal.vue new file mode 100644 index 0000000..99b6408 --- /dev/null +++ b/src/components/admin/user/role/CreateRoleModal.vue @@ -0,0 +1,57 @@ + + + + Rolle erstellen + + + + + Rollenbezeichnung + + + + + erstellen + + + + + + + + + + schließen + + + + + + + + diff --git a/src/components/admin/user/role/RoleListItem.vue b/src/components/admin/user/role/RoleListItem.vue new file mode 100644 index 0000000..b49d049 --- /dev/null +++ b/src/components/admin/user/role/RoleListItem.vue @@ -0,0 +1,27 @@ + + + + {{ role.role }} (Admin) + + + + + + + + diff --git a/src/components/admin/user/user/UserListItem.vue b/src/components/admin/user/user/UserListItem.vue new file mode 100644 index 0000000..2a30d7a --- /dev/null +++ b/src/components/admin/user/user/UserListItem.vue @@ -0,0 +1,45 @@ + + + + {{ user.firstname }} {{ user.lastname }} + + + + + Benutzer: + {{ user.username }} + + + Mail: + {{ user.mail }} + + + Rollen: + + + {{ role.role }} + + + + + + + + + + diff --git a/src/stores/ability.ts b/src/stores/ability.ts index a9f3162..697df93 100644 --- a/src/stores/ability.ts +++ b/src/stores/ability.ts @@ -12,8 +12,8 @@ export const useAbilityStore = defineStore("ability", { (state) => (type: PermissionType | "admin", section: PermissionSection, module?: PermissionModule): boolean => { const permissions = state.permissions; - if (type == "admin") return permissions.admin ?? false; - if (permissions.admin) return true; + if (type == "admin") return permissions?.admin ?? false; + if (permissions?.admin) return true; if ( (!module && permissions[section] != undefined && @@ -30,8 +30,8 @@ export const useAbilityStore = defineStore("ability", { (state) => (type: PermissionType | "admin", section: PermissionSection): boolean => { const permissions = state.permissions; - if (type == "admin") return permissions.admin ?? false; - if (permissions.admin) return true; + if (type == "admin") return permissions?.admin ?? false; + if (permissions?.admin) return true; if ( permissions[section]?.all == "*" || permissions[section]?.all?.includes(type) || @@ -48,8 +48,8 @@ export const useAbilityStore = defineStore("ability", { section: PermissionSection, module?: PermissionModule ): boolean => { - if (type == "admin") return permissions.admin ?? false; - if (permissions.admin) return true; + if (type == "admin") return permissions?.admin ?? false; + if (permissions?.admin) return true; if ( (!module && permissions[section] != undefined && diff --git a/src/stores/admin/navigation.ts b/src/stores/admin/navigation.ts index ea92171..db699ea 100644 --- a/src/stores/admin/navigation.ts +++ b/src/stores/admin/navigation.ts @@ -56,6 +56,7 @@ export const useNavigationStore = defineStore("navigation", { if (!disableSubLink) this.setLink(level.levelDefault); else this.setLink(null); } + this.resetComponentOverwrite(); }, setLink(key: string | null) { let nav = this.navigation[this.activeNavigation]; @@ -65,6 +66,7 @@ export const useNavigationStore = defineStore("navigation", { } let links = [...Object.values(nav.main), ...Object.values(nav.top ?? {})]; this.activeLink = links.find((e) => e.key == key) ?? null; + this.resetComponentOverwrite(); }, setTopLevelNav(topLeveLinks: Array) { this.topLevel = topLeveLinks; @@ -209,12 +211,12 @@ export const useNavigationStore = defineStore("navigation", { }, ] : []), - ...(abilityStore.can("admin", "user", "role") + ...(abilityStore.can("read", "user", "role") ? [ { key: "#role", title: "Rollen", - component: shallowRef(defineAsyncComponent(() => import("@/views/admin/members/Overview.vue"))), + component: shallowRef(defineAsyncComponent(() => import("@/views/admin/user/Role.vue"))), }, ] : []), diff --git a/src/stores/admin/role.ts b/src/stores/admin/role.ts new file mode 100644 index 0000000..569dcbf --- /dev/null +++ b/src/stores/admin/role.ts @@ -0,0 +1,59 @@ +import { defineStore } from "pinia"; +import type { RoleViewModel } from "../../viewmodels/admin/role.models"; +import { http } from "../../serverCom"; + +export const useRoleStore = defineStore("role", { + state: () => { + return { + roles: [] as Array, + role: null as null | RoleViewModel, + loadingAll: null as null | "loading" | "success" | "failed", + loadingSingle: null as null | "loading" | "success" | "failed", + createStatus: null as null | "loading" | { status: "success" | "failed"; reason?: string }, + }; + }, + actions: { + fetchRoles() { + this.loadingAll = "loading"; + http + .get("/admin/role") + .then((result) => { + this.roles = result.data; + this.loadingAll = "success"; + }) + .catch((err) => { + this.loadingAll = "failed"; + }); + }, + fetchRolesById(id: number) { + this.role = null; + this.loadingSingle = "loading"; + http + .get(`/admin/role/${id}`) + .then((result) => { + this.role = result.data; + this.loadingSingle = "success"; + }) + .catch((err) => { + this.loadingSingle = "failed"; + }); + }, + resetCreateStatus() { + this.createStatus = null; + }, + createRole(role: string) { + this.createStatus = "loading"; + http + .post("/admin/role", { + role: role, + }) + .then((res) => { + this.createStatus = { status: "success" }; + this.fetchRoles(); + }) + .catch((err) => { + this.createStatus = { status: "failed", reason: err.data }; + }); + }, + }, +}); diff --git a/src/stores/admin/user.ts b/src/stores/admin/user.ts new file mode 100644 index 0000000..8b36fe5 --- /dev/null +++ b/src/stores/admin/user.ts @@ -0,0 +1,41 @@ +import { defineStore } from "pinia"; +import type { UserViewModel } from "../../viewmodels/admin/user.models"; +import { http } from "../../serverCom"; + +export const useUserStore = defineStore("user", { + state: () => { + return { + users: [] as Array, + user: null as null | UserViewModel, + loadingAll: "loading" as "loading" | "fetched" | "failed", + loadingSingle: "loading" as "loading" | "fetched" | "failed", + }; + }, + actions: { + fetchUsers() { + this.loadingAll = "loading"; + http + .get("/admin/user") + .then((result) => { + this.users = result.data; + this.loadingAll = "fetched"; + }) + .catch((err) => { + this.loadingAll = "failed"; + }); + }, + fetchUsersById(id: number) { + this.user = null; + this.loadingSingle = "loading"; + http + .get(`/admin/user/${id}`) + .then((result) => { + this.user = result.data; + this.loadingSingle = "fetched"; + }) + .catch((err) => { + this.loadingSingle = "failed"; + }); + }, + }, +}); diff --git a/src/viewmodels/admin/role.models.ts b/src/viewmodels/admin/role.models.ts new file mode 100644 index 0000000..c810ca2 --- /dev/null +++ b/src/viewmodels/admin/role.models.ts @@ -0,0 +1,7 @@ +import { PermissionObject } from "../../type/permissionTypes"; + +export interface RoleViewModel { + id: number; + permissions: PermissionObject; + role: string; +} diff --git a/src/viewmodels/admin/user.models.ts b/src/viewmodels/admin/user.models.ts new file mode 100644 index 0000000..39ee152 --- /dev/null +++ b/src/viewmodels/admin/user.models.ts @@ -0,0 +1,13 @@ +import { PermissionObject } from "../../type/permissionTypes"; +import { RoleViewModel } from "./role.models"; + +export interface UserViewModel { + id: number; + username: string; + mail: string; + firstname: string; + lastname: string; + permissions: PermissionObject; + roles: Array; + permissions_total: PermissionObject; +} diff --git a/src/views/admin/user/Role.vue b/src/views/admin/user/Role.vue new file mode 100644 index 0000000..bf8fcf6 --- /dev/null +++ b/src/views/admin/user/Role.vue @@ -0,0 +1,46 @@ + + + + + Rollen + + + + + + + + + Rolle erstellen + + + + + + + + + diff --git a/src/views/admin/user/User.vue b/src/views/admin/user/User.vue index 2d3d1d3..3b73671 100644 --- a/src/views/admin/user/User.vue +++ b/src/views/admin/user/User.vue @@ -5,19 +5,38 @@ Benutzer - - + + + + + + + Nutzer einladen + offene Einladungen + +
Rolle erstellen
{{ role.role }} (Admin)
{{ user.firstname }} {{ user.lastname }}
Benutzer:
{{ user.username }}
Mail:
{{ user.mail }}
Rollen:
+ {{ role.role }} +