From 99c6caa788fa67121b4b4c662e8a0532f195a9f3 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 20 Jul 2022 22:47:10 +0800 Subject: [PATCH] feat: create labels and annotations enumeration types Signed-off-by: Ryan Wang --- src/constants/annotations.ts | 12 ++++ src/constants/labels.ts | 9 +++ src/modules/interface/themes/ThemeDetail.vue | 18 +++--- src/modules/system/plugins/PluginDetail.vue | 21 ++++--- src/modules/system/roles/RoleDetail.vue | 59 +++++++++++++------ src/modules/system/roles/RoleList.vue | 6 +- .../roles/components/RoleCreationModal.vue | 24 ++++---- src/modules/system/users/UserDetail.vue | 5 +- src/modules/system/users/UserList.vue | 7 +-- .../users/components/UserEditingModal.vue | 6 +- 10 files changed, 106 insertions(+), 61 deletions(-) create mode 100644 src/constants/annotations.ts create mode 100644 src/constants/labels.ts diff --git a/src/constants/annotations.ts b/src/constants/annotations.ts new file mode 100644 index 00000000..7a530f24 --- /dev/null +++ b/src/constants/annotations.ts @@ -0,0 +1,12 @@ +// plugin +export enum pluginAnnotations { + DISPLAY_NAME = "plugin.halo.run/display-name", +} + +// rbac +export enum rbacAnnotations { + MODULE = "rbac.authorization.halo.run/module", + ROLE_NAMES = "rbac.authorization.halo.run/role-names", + DISPLAY_NAME = "rbac.authorization.halo.run/display-name", + DEPENDENCIES = "rbac.authorization.halo.run/dependencies", +} diff --git a/src/constants/labels.ts b/src/constants/labels.ts new file mode 100644 index 00000000..e8844916 --- /dev/null +++ b/src/constants/labels.ts @@ -0,0 +1,9 @@ +// plugin +export enum pluginLabels { + NAME = "plugin.halo.run/plugin-name", +} + +// role +export enum roleLabels { + TEMPLATE = "halo.run/role-template", +} diff --git a/src/modules/interface/themes/ThemeDetail.vue b/src/modules/interface/themes/ThemeDetail.vue index 3aaec347..f1e90f5c 100644 --- a/src/modules/interface/themes/ThemeDetail.vue +++ b/src/modules/interface/themes/ThemeDetail.vue @@ -354,16 +354,18 @@ onMounted(handleFetchThemes); -
- - - - - - +
+
+ + + + + + +
-
+
保存
diff --git a/src/modules/system/plugins/PluginDetail.vue b/src/modules/system/plugins/PluginDetail.vue index e3a40b6b..7714d974 100644 --- a/src/modules/system/plugins/PluginDetail.vue +++ b/src/modules/system/plugins/PluginDetail.vue @@ -12,14 +12,16 @@ import { useRoute } from "vue-router"; import { computed, onMounted, ref } from "vue"; import { apiClient } from "@halo-dev/admin-shared"; import type { - Plugin, ConfigMap, + Plugin, + Role, Setting, SettingSpec, - Role, } from "@halo-dev/api-client"; import cloneDeep from "lodash.clonedeep"; import type { FormKitSchemaCondition, FormKitSchemaNode } from "@formkit/core"; +import { pluginLabels } from "@/constants/labels"; +import { rbacAnnotations } from "@/constants/annotations"; interface FormKitSettingSpec extends Omit { formSchema: FormKitSchemaCondition | FormKitSchemaNode[]; @@ -195,8 +197,7 @@ const handleFetchRoles = async () => { const pluginRoleTemplates = computed(() => { return roles.value.filter((item) => { return ( - item.metadata.labels?.["plugin.halo.run/plugin-name"] === - plugin.value.metadata.name + item.metadata.labels?.[pluginLabels.NAME] === plugin.value.metadata.name ); }); }); @@ -206,15 +207,13 @@ const pluginRoleTemplateGroups = computed(() => { pluginRoleTemplates.value.forEach((role) => { const group = groups.find( (group) => - group.module === - role.metadata.annotations?.["rbac.authorization.halo.run/module"] + group.module === role.metadata.annotations?.[rbacAnnotations.MODULE] ); if (group) { group.roles.push(role); } else { groups.push({ - module: - role.metadata.annotations?.["rbac.authorization.halo.run/module"], + module: role.metadata.annotations?.[rbacAnnotations.MODULE], roles: [role], }); } @@ -370,14 +369,14 @@ onMounted(() => { {{ role.metadata.annotations?.[ - "rbac.authorization.halo.run/display-name" + rbacAnnotations.DISPLAY_NAME ] }} { {{ JSON.parse( role.metadata.annotations?.[ - "rbac.authorization.halo.run/dependencies" + rbacAnnotations.DEPENDENCIES ] ).join(", ") }} diff --git a/src/modules/system/roles/RoleDetail.vue b/src/modules/system/roles/RoleDetail.vue index 585c3b34..694c18d5 100644 --- a/src/modules/system/roles/RoleDetail.vue +++ b/src/modules/system/roles/RoleDetail.vue @@ -13,6 +13,8 @@ import { useRoute, useRouter } from "vue-router"; import { computed, onMounted, ref } from "vue"; import { apiClient } from "@halo-dev/admin-shared"; import type { Role, User } from "@halo-dev/api-client"; +import { pluginLabels, roleLabels } from "@/constants/labels"; +import { rbacAnnotations } from "@/constants/annotations"; interface RoleTemplateGroup { module: string | null | undefined; @@ -38,8 +40,8 @@ const formState = ref({ name: "", labels: {}, annotations: { - "rbac.authorization.halo.run/dependencies": "", - "rbac.authorization.halo.run/display-name": "", + [rbacAnnotations.DEPENDENCIES]: "", + [rbacAnnotations.DISPLAY_NAME]: "", }, }, rules: [], @@ -51,7 +53,7 @@ const formState = ref({ const roleTemplates = computed(() => { return roles.value.filter( (role) => - role.metadata.labels?.["halo.run/role-template"] === "true" && + role.metadata.labels?.[roleLabels.TEMPLATE] === "true" && role.metadata.labels?.["halo.run/hidden"] !== "true" ); }); @@ -61,15 +63,13 @@ const roleTemplateGroups = computed(() => { roleTemplates.value.forEach((role) => { const group = groups.find( (group) => - group.module === - role.metadata.annotations?.["rbac.authorization.halo.run/module"] + group.module === role.metadata.annotations?.[rbacAnnotations.MODULE] ); if (group) { group.roles.push(role); } else { groups.push({ - module: - role.metadata.annotations?.["rbac.authorization.halo.run/module"], + module: role.metadata.annotations?.[rbacAnnotations.MODULE], roles: [role], }); } @@ -84,9 +84,7 @@ const handleFetchRole = async () => { ); formState.value.role = response.data; formState.value.selectedRoleTemplates = JSON.parse( - response.data.metadata.annotations?.[ - "rbac.authorization.halo.run/dependencies" - ] || "[]" + response.data.metadata.annotations?.[rbacAnnotations.DEPENDENCIES] || "[]" ); } catch (error) { console.error(error); @@ -115,9 +113,8 @@ const handleUpdateRole = async () => { try { formState.value.saving = true; if (formState.value.role.metadata.annotations) { - formState.value.role.metadata.annotations[ - "rbac.authorization.halo.run/dependencies" - ] = JSON.stringify(formState.value.selectedRoleTemplates); + formState.value.role.metadata.annotations[rbacAnnotations.DEPENDENCIES] = + JSON.stringify(formState.value.selectedRoleTemplates); } await apiClient.extension.role.updatev1alpha1Role( route.params.name as string, @@ -146,7 +143,7 @@ onMounted(() => {