From ee42625d66d93964e424e1459299f8f20b26622b Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Wed, 22 Jan 2025 09:11:39 +0100 Subject: [PATCH 1/3] api store and viewmodels --- src/stores/admin/user/api.ts | 57 +++++++++++++++++++++++++ src/viewmodels/admin/user/api.models.ts | 26 +++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/stores/admin/user/api.ts create mode 100644 src/viewmodels/admin/user/api.models.ts diff --git a/src/stores/admin/user/api.ts b/src/stores/admin/user/api.ts new file mode 100644 index 0000000..2836468 --- /dev/null +++ b/src/stores/admin/user/api.ts @@ -0,0 +1,57 @@ +import { defineStore } from "pinia"; +import type { ApiViewModel } from "@/viewmodels/admin/user/api.models"; +import { http } from "@/serverCom"; +import type { PermissionObject } from "@/types/permissionTypes"; +import type { AxiosResponse } from "axios"; + +export const useApiStore = defineStore("api", { + state: () => { + return { + apis: [] as Array, + loading: null as null | "loading" | "success" | "failed", + }; + }, + actions: { + fetchApis() { + this.loading = "loading"; + http + .get("/admin/api") + .then((result) => { + this.apis = result.data; + this.loading = "success"; + }) + .catch((err) => { + this.loading = "failed"; + }); + }, + fetchApiById(id: number): Promise> { + return http.get(`/admin/api/${id}`); + }, + async createApi(api: string): Promise> { + const result = await http.post("/admin/api", { + api: api, + }); + this.fetchApis(); + return result; + }, + async updateActiveApi(id: number, api: string): Promise> { + const result = await http.patch(`/admin/api/${id}`, { + api: api, + }); + this.fetchApis(); + return result; + }, + async updateActiveApiPermissions(api: number, permission: PermissionObject): Promise> { + const result = await http.patch(`/admin/api/${api}/permissions`, { + permissions: permission, + }); + this.fetchApis(); + return result; + }, + async deleteApi(api: number): Promise> { + const result = await http.delete(`/admin/api/${api}`); + this.fetchApis(); + return result; + }, + }, +}); diff --git a/src/viewmodels/admin/user/api.models.ts b/src/viewmodels/admin/user/api.models.ts new file mode 100644 index 0000000..cc3b3e6 --- /dev/null +++ b/src/viewmodels/admin/user/api.models.ts @@ -0,0 +1,26 @@ +import type { PermissionObject } from "@/types/permissionTypes"; + +export interface ApiViewModel { + id: number; + permissions: PermissionObject; + title: string; + createdAt: Date; + lastUsage?: Date; + expiry?: Date; +} + +export interface CreateApiViewModel { + title: string; + token: string; + expiry?: Date; +} + +export interface UpdateApiViewModel { + id: number; + title: string; + expiry?: Date; +} + +export interface DeleteApiViewModel { + id: number; +} From 7ded4a21bb3a3ba69e925065dcf6deff269929dc Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Wed, 22 Jan 2025 10:17:11 +0100 Subject: [PATCH 2/3] basic structure for webapi --- .../admin/user/webapi/CreateWebapiModal.vue | 72 +++++++++++ .../admin/user/webapi/DeleteWebapiModal.vue | 75 +++++++++++ .../admin/user/webapi/WebapiListItem.vue | 54 ++++++++ src/router/index.ts | 30 +++++ src/stores/admin/navigation.ts | 1 + src/stores/admin/user/api.ts | 57 --------- src/stores/admin/user/webapi.ts | 60 +++++++++ src/types/permissionTypes.ts | 4 +- .../user/{api.models.ts => webapi.models.ts} | 8 +- src/views/admin/user/webapi/Webapi.vue | 52 ++++++++ src/views/admin/user/webapi/WebapiEdit.vue | 116 ++++++++++++++++++ .../user/webapi/WebapiEditPermission.vue | 87 +++++++++++++ 12 files changed, 554 insertions(+), 62 deletions(-) create mode 100644 src/components/admin/user/webapi/CreateWebapiModal.vue create mode 100644 src/components/admin/user/webapi/DeleteWebapiModal.vue create mode 100644 src/components/admin/user/webapi/WebapiListItem.vue delete mode 100644 src/stores/admin/user/api.ts create mode 100644 src/stores/admin/user/webapi.ts rename src/viewmodels/admin/user/{api.models.ts => webapi.models.ts} (66%) create mode 100644 src/views/admin/user/webapi/Webapi.vue create mode 100644 src/views/admin/user/webapi/WebapiEdit.vue create mode 100644 src/views/admin/user/webapi/WebapiEditPermission.vue diff --git a/src/components/admin/user/webapi/CreateWebapiModal.vue b/src/components/admin/user/webapi/CreateWebapiModal.vue new file mode 100644 index 0000000..ec87edc --- /dev/null +++ b/src/components/admin/user/webapi/CreateWebapiModal.vue @@ -0,0 +1,72 @@ + + + + + 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..8e7b286 --- /dev/null +++ b/src/components/admin/user/webapi/WebapiListItem.vue @@ -0,0 +1,54 @@ + + + + + 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/api.ts b/src/stores/admin/user/api.ts deleted file mode 100644 index 2836468..0000000 --- a/src/stores/admin/user/api.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { defineStore } from "pinia"; -import type { ApiViewModel } from "@/viewmodels/admin/user/api.models"; -import { http } from "@/serverCom"; -import type { PermissionObject } from "@/types/permissionTypes"; -import type { AxiosResponse } from "axios"; - -export const useApiStore = defineStore("api", { - state: () => { - return { - apis: [] as Array, - loading: null as null | "loading" | "success" | "failed", - }; - }, - actions: { - fetchApis() { - this.loading = "loading"; - http - .get("/admin/api") - .then((result) => { - this.apis = result.data; - this.loading = "success"; - }) - .catch((err) => { - this.loading = "failed"; - }); - }, - fetchApiById(id: number): Promise> { - return http.get(`/admin/api/${id}`); - }, - async createApi(api: string): Promise> { - const result = await http.post("/admin/api", { - api: api, - }); - this.fetchApis(); - return result; - }, - async updateActiveApi(id: number, api: string): Promise> { - const result = await http.patch(`/admin/api/${id}`, { - api: api, - }); - this.fetchApis(); - return result; - }, - async updateActiveApiPermissions(api: number, permission: PermissionObject): Promise> { - const result = await http.patch(`/admin/api/${api}/permissions`, { - permissions: permission, - }); - this.fetchApis(); - return result; - }, - async deleteApi(api: number): Promise> { - const result = await http.delete(`/admin/api/${api}`); - this.fetchApis(); - return result; - }, - }, -}); diff --git a/src/stores/admin/user/webapi.ts b/src/stores/admin/user/webapi.ts new file mode 100644 index 0000000..4ddf939 --- /dev/null +++ b/src/stores/admin/user/webapi.ts @@ -0,0 +1,60 @@ +import { defineStore } from "pinia"; +import type { 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}`); + }, + async createWebapi(webapi: string): Promise> { + const result = await http.post("/admin/webapi", { + webapi: webapi, + }); + this.fetchWebapis(); + return result; + }, + async updateActiveWebapi(id: number, webapi: string): Promise> { + const result = await http.patch(`/admin/webapi/${id}`, { + webapi: 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/api.models.ts b/src/viewmodels/admin/user/webapi.models.ts similarity index 66% rename from src/viewmodels/admin/user/api.models.ts rename to src/viewmodels/admin/user/webapi.models.ts index cc3b3e6..1bdf93c 100644 --- a/src/viewmodels/admin/user/api.models.ts +++ b/src/viewmodels/admin/user/webapi.models.ts @@ -1,6 +1,6 @@ import type { PermissionObject } from "@/types/permissionTypes"; -export interface ApiViewModel { +export interface WebapiViewModel { id: number; permissions: PermissionObject; title: string; @@ -9,18 +9,18 @@ export interface ApiViewModel { expiry?: Date; } -export interface CreateApiViewModel { +export interface CreateWebapiViewModel { title: string; token: string; expiry?: Date; } -export interface UpdateApiViewModel { +export interface UpdateWebapiViewModel { id: number; title: string; expiry?: Date; } -export interface DeleteApiViewModel { +export interface DeleteWebapiViewModel { id: number; } 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..7c17d94 --- /dev/null +++ b/src/views/admin/user/webapi/WebapiEdit.vue @@ -0,0 +1,116 @@ + + + + + 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 @@ + + + + + From 4f13b70ac83d6408b1063695141fc08410c6b05b Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Wed, 22 Jan 2025 11:55:48 +0100 Subject: [PATCH 3/3] form update & token copy --- .../admin/user/webapi/CreateWebapiModal.vue | 15 ++++- .../admin/user/webapi/WebapiListItem.vue | 55 +++++++++++++++++- .../admin/user/webapi/WebapiTokenModal.vue | 56 +++++++++++++++++++ src/stores/admin/user/webapi.ts | 21 ++++--- src/viewmodels/admin/user/webapi.models.ts | 6 -- src/views/admin/user/webapi/WebapiEdit.vue | 18 ++++-- 6 files changed, 148 insertions(+), 23 deletions(-) create mode 100644 src/components/admin/user/webapi/WebapiTokenModal.vue diff --git a/src/components/admin/user/webapi/CreateWebapiModal.vue b/src/components/admin/user/webapi/CreateWebapiModal.vue index ec87edc..1b3df8d 100644 --- a/src/components/admin/user/webapi/CreateWebapiModal.vue +++ b/src/components/admin/user/webapi/CreateWebapiModal.vue @@ -6,8 +6,12 @@
- - + + +
+
+ +
@@ -35,6 +39,7 @@ import Spinner from "@/components/Spinner.vue"; import SuccessCheckmark from "@/components/SuccessCheckmark.vue"; import FailureXMark from "@/components/FailureXMark.vue"; import { useWebapiStore } from "@/stores/admin/user/webapi"; +import type { CreateWebapiViewModel } from "../../../../viewmodels/admin/user/webapi.models"; + + diff --git a/src/stores/admin/user/webapi.ts b/src/stores/admin/user/webapi.ts index 4ddf939..66a57e7 100644 --- a/src/stores/admin/user/webapi.ts +++ b/src/stores/admin/user/webapi.ts @@ -1,5 +1,9 @@ import { defineStore } from "pinia"; -import type { WebapiViewModel } from "@/viewmodels/admin/user/webapi.models"; +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"; @@ -27,17 +31,16 @@ export const useWebapiStore = defineStore("webapi", { fetchWebapiById(id: number): Promise> { return http.get(`/admin/webapi/${id}`); }, - async createWebapi(webapi: string): Promise> { - const result = await http.post("/admin/webapi", { - webapi: webapi, - }); + 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: string): Promise> { - const result = await http.patch(`/admin/webapi/${id}`, { - webapi: webapi, - }); + async updateActiveWebapi(id: number, webapi: UpdateWebapiViewModel): Promise> { + const result = await http.patch(`/admin/webapi/${id}`, webapi); this.fetchWebapis(); return result; }, diff --git a/src/viewmodels/admin/user/webapi.models.ts b/src/viewmodels/admin/user/webapi.models.ts index 1bdf93c..015837c 100644 --- a/src/viewmodels/admin/user/webapi.models.ts +++ b/src/viewmodels/admin/user/webapi.models.ts @@ -11,16 +11,10 @@ export interface WebapiViewModel { export interface CreateWebapiViewModel { title: string; - token: string; expiry?: Date; } export interface UpdateWebapiViewModel { - id: number; title: string; expiry?: Date; } - -export interface DeleteWebapiViewModel { - id: number; -} diff --git a/src/views/admin/user/webapi/WebapiEdit.vue b/src/views/admin/user/webapi/WebapiEdit.vue index 7c17d94..8eb85f7 100644 --- a/src/views/admin/user/webapi/WebapiEdit.vue +++ b/src/views/admin/user/webapi/WebapiEdit.vue @@ -17,8 +17,12 @@ @submit.prevent="triggerWebapiUpdate" >
- - + + +
+
+ +