diff --git a/src/components/admin/user/webapi/CreateWebapiModal.vue b/src/components/admin/user/webapi/CreateWebapiModal.vue new file mode 100644 index 0000000..1b3df8d --- /dev/null +++ b/src/components/admin/user/webapi/CreateWebapiModal.vue @@ -0,0 +1,81 @@ + + + + + diff --git a/src/components/admin/user/webapi/DeleteWebapiModal.vue b/src/components/admin/user/webapi/DeleteWebapiModal.vue new file mode 100644 index 0000000..002157c --- /dev/null +++ b/src/components/admin/user/webapi/DeleteWebapiModal.vue @@ -0,0 +1,75 @@ + + + + + diff --git a/src/components/admin/user/webapi/WebapiListItem.vue b/src/components/admin/user/webapi/WebapiListItem.vue new file mode 100644 index 0000000..64b2d19 --- /dev/null +++ b/src/components/admin/user/webapi/WebapiListItem.vue @@ -0,0 +1,107 @@ + + + + + diff --git a/src/components/admin/user/webapi/WebapiTokenModal.vue b/src/components/admin/user/webapi/WebapiTokenModal.vue new file mode 100644 index 0000000..e3b6d91 --- /dev/null +++ b/src/components/admin/user/webapi/WebapiTokenModal.vue @@ -0,0 +1,56 @@ + + + + + diff --git a/src/router/index.ts b/src/router/index.ts index 335f7fa..eeb1ba3 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -582,6 +582,36 @@ const router = createRouter({ }, ], }, + { + path: "webapi", + name: "admin-user-webapi-route", + component: () => import("@/views/RouterView.vue"), + meta: { type: "read", section: "user", module: "webapi" }, + beforeEnter: [abilityAndNavUpdate], + children: [ + { + path: "", + name: "admin-user-webapi", + component: () => import("@/views/admin/user/webapi/Webapi.vue"), + }, + { + path: ":id/edit", + name: "admin-user-webapi-edit", + component: () => import("@/views/admin/user/webapi/WebapiEdit.vue"), + meta: { type: "update", section: "user", module: "webapi" }, + beforeEnter: [abilityAndNavUpdate], + props: true, + }, + { + path: ":id/permission", + name: "admin-user-webapi-permission", + component: () => import("@/views/admin/user/webapi/WebapiEditPermission.vue"), + meta: { type: "update", section: "user", module: "webapi" }, + beforeEnter: [abilityAndNavUpdate], + props: true, + }, + ], + }, ], }, { diff --git a/src/stores/admin/navigation.ts b/src/stores/admin/navigation.ts index 782e42f..bd1bc84 100644 --- a/src/stores/admin/navigation.ts +++ b/src/stores/admin/navigation.ts @@ -131,6 +131,7 @@ export const useNavigationStore = defineStore("navigation", { main: [ ...(abilityStore.can("read", "user", "user") ? [{ key: "user", title: "Benutzer" }] : []), ...(abilityStore.can("read", "user", "role") ? [{ key: "role", title: "Rollen" }] : []), + ...(abilityStore.can("read", "user", "webapi") ? [{ key: "webapi", title: "Webapi-Token" }] : []), ], }, } as navigationModel; diff --git a/src/stores/admin/user/webapi.ts b/src/stores/admin/user/webapi.ts new file mode 100644 index 0000000..66a57e7 --- /dev/null +++ b/src/stores/admin/user/webapi.ts @@ -0,0 +1,63 @@ +import { defineStore } from "pinia"; +import type { + CreateWebapiViewModel, + UpdateWebapiViewModel, + WebapiViewModel, +} from "@/viewmodels/admin/user/webapi.models"; +import { http } from "@/serverCom"; +import type { PermissionObject } from "@/types/permissionTypes"; +import type { AxiosResponse } from "axios"; + +export const useWebapiStore = defineStore("webapi", { + state: () => { + return { + webapis: [] as Array, + loading: null as null | "loading" | "success" | "failed", + }; + }, + actions: { + fetchWebapis() { + this.loading = "loading"; + http + .get("/admin/webapi") + .then((result) => { + this.webapis = result.data; + this.loading = "success"; + }) + .catch((err) => { + this.loading = "failed"; + }); + }, + fetchWebapiById(id: number): Promise> { + return http.get(`/admin/webapi/${id}`); + }, + fetchWebapiTokenById(id: number): Promise> { + return http.get(`/admin/webapi/${id}/token`); + }, + async createWebapi(webapi: CreateWebapiViewModel): Promise> { + const result = await http.post("/admin/webapi", webapi); + this.fetchWebapis(); + return result; + }, + async updateActiveWebapi(id: number, webapi: UpdateWebapiViewModel): Promise> { + const result = await http.patch(`/admin/webapi/${id}`, webapi); + this.fetchWebapis(); + return result; + }, + async updateActiveWebapiPermissions( + webapi: number, + permission: PermissionObject + ): Promise> { + const result = await http.patch(`/admin/webapi/${webapi}/permissions`, { + permissions: permission, + }); + this.fetchWebapis(); + return result; + }, + async deleteWebapi(webapi: number): Promise> { + const result = await http.delete(`/admin/webapi/${webapi}`); + this.fetchWebapis(); + return result; + }, + }, +}); diff --git a/src/types/permissionTypes.ts b/src/types/permissionTypes.ts index 95ea543..5ba5cb4 100644 --- a/src/types/permissionTypes.ts +++ b/src/types/permissionTypes.ts @@ -14,6 +14,7 @@ export type PermissionModule = | "calendar_type" | "user" | "role" + | "webapi" | "query" | "query_store" | "template" @@ -55,6 +56,7 @@ export const permissionModules: Array = [ "calendar_type", "user", "role", + "webapi", "query", "query_store", "template", @@ -75,5 +77,5 @@ export const sectionsAndModules: SectionsAndModulesObject = { "template_usage", "newsletter_config", ], - user: ["user", "role"], + user: ["user", "role", "webapi"], }; diff --git a/src/viewmodels/admin/user/webapi.models.ts b/src/viewmodels/admin/user/webapi.models.ts new file mode 100644 index 0000000..015837c --- /dev/null +++ b/src/viewmodels/admin/user/webapi.models.ts @@ -0,0 +1,20 @@ +import type { PermissionObject } from "@/types/permissionTypes"; + +export interface WebapiViewModel { + id: number; + permissions: PermissionObject; + title: string; + createdAt: Date; + lastUsage?: Date; + expiry?: Date; +} + +export interface CreateWebapiViewModel { + title: string; + expiry?: Date; +} + +export interface UpdateWebapiViewModel { + title: string; + expiry?: Date; +} diff --git a/src/views/admin/user/webapi/Webapi.vue b/src/views/admin/user/webapi/Webapi.vue new file mode 100644 index 0000000..75f264f --- /dev/null +++ b/src/views/admin/user/webapi/Webapi.vue @@ -0,0 +1,52 @@ + + + + + diff --git a/src/views/admin/user/webapi/WebapiEdit.vue b/src/views/admin/user/webapi/WebapiEdit.vue new file mode 100644 index 0000000..8eb85f7 --- /dev/null +++ b/src/views/admin/user/webapi/WebapiEdit.vue @@ -0,0 +1,126 @@ + + + + + diff --git a/src/views/admin/user/webapi/WebapiEditPermission.vue b/src/views/admin/user/webapi/WebapiEditPermission.vue new file mode 100644 index 0000000..44b6020 --- /dev/null +++ b/src/views/admin/user/webapi/WebapiEditPermission.vue @@ -0,0 +1,87 @@ + + + + +