From d3d934093d3ccbb421f92891bbf8547619851602 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Tue, 19 Jul 2022 11:18:47 +0800 Subject: [PATCH] feat: refine roles management Signed-off-by: Ryan Wang --- src/main.ts | 6 ++++ src/modules/system/roles/RoleDetail.vue | 29 ++++++++++------ src/modules/system/roles/RoleList.vue | 3 +- .../roles/components/RoleCreationModal.vue | 33 ++++++++++++------- 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/main.ts b/src/main.ts index 1a055074..236e0818 100644 --- a/src/main.ts +++ b/src/main.ts @@ -174,6 +174,12 @@ async function loadCurrentUser() { })(); async function initApp() { + // TODO 实验性特性 + const theme = localStorage.getItem("theme"); + if (theme) { + document.body.classList.add(theme); + } + try { loadCoreModules(); await loadPluginModules(); diff --git a/src/modules/system/roles/RoleDetail.vue b/src/modules/system/roles/RoleDetail.vue index f35122cd..e32eab7e 100644 --- a/src/modules/system/roles/RoleDetail.vue +++ b/src/modules/system/roles/RoleDetail.vue @@ -15,7 +15,8 @@ import { apiClient } from "@halo-dev/admin-shared"; import type { Role, User } from "@halo-dev/api-client"; interface RoleTemplateGroup { - name: string | null | undefined; + module: string | null | undefined; + displayName: string | null | undefined; roles: Role[]; } @@ -39,7 +40,7 @@ const formState = ref({ labels: {}, annotations: { "rbac.authorization.halo.run/dependencies": "", - "plugin.halo.run/display-name": "", + "rbac.authorization.halo.run/display-name": "", }, }, rules: [], @@ -50,7 +51,9 @@ const formState = ref({ const roleTemplates = computed(() => { return roles.value.filter( - (role) => role.metadata.labels?.["plugin.halo.run/role-template"] === "true" + (role) => + role.metadata.labels?.["halo.run/role-template"] === "true" && + role.metadata.labels?.["halo.run/hidden"] !== "true" ); }); @@ -59,13 +62,19 @@ const roleTemplateGroups = computed(() => { roleTemplates.value.forEach((role) => { const group = groups.find( (group) => - group.name === role.metadata.annotations?.["plugin.halo.run/module"] + group.module === + role.metadata.annotations?.["rbac.authorization.halo.run/module"] ); if (group) { group.roles.push(role); } else { groups.push({ - name: role.metadata.annotations?.["plugin.halo.run/module"], + module: + role.metadata.annotations?.["rbac.authorization.halo.run/module"], + displayName: + role.metadata.annotations?.[ + "rbac.authorization.halo.run/display-name" + ], roles: [role], }); } @@ -295,12 +304,12 @@ onMounted(() => { class="bg-white px-4 py-5 hover:bg-gray-50 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6" >
- {{ group.name }} + {{ group.displayName }}
  • -
    { class="h-4 w-4 rounded border-gray-300 text-indigo-600" type="checkbox" /> -
    +
    {{ role.metadata.annotations?.[ - "plugin.halo.run/display-name" + "rbac.authorization.halo.run/display-name" ] }} @@ -335,7 +344,7 @@ onMounted(() => { }}
    -
    +
diff --git a/src/modules/system/roles/RoleList.vue b/src/modules/system/roles/RoleList.vue index 74ef214b..3e4e85c0 100644 --- a/src/modules/system/roles/RoleList.vue +++ b/src/modules/system/roles/RoleList.vue @@ -22,8 +22,7 @@ const roles = ref([]); const basicRoles = computed(() => { return roles.value.filter( - (role) => - role.metadata?.labels?.["plugin.halo.run/role-template"] !== "true" + (role) => role.metadata?.labels?.["halo.run/role-template"] !== "true" ); }); diff --git a/src/modules/system/roles/components/RoleCreationModal.vue b/src/modules/system/roles/components/RoleCreationModal.vue index bd3fe26f..6ca7f8a6 100644 --- a/src/modules/system/roles/components/RoleCreationModal.vue +++ b/src/modules/system/roles/components/RoleCreationModal.vue @@ -5,7 +5,8 @@ import { apiClient } from "@halo-dev/admin-shared"; import type { Role } from "@halo-dev/api-client"; interface RoleTemplateGroup { - name: string | null | undefined; + module: string | null | undefined; + displayName: string | null | undefined; roles: Role[]; } @@ -35,7 +36,7 @@ const creationFormState = ref({ labels: {}, annotations: { "rbac.authorization.halo.run/dependencies": "", - "plugin.halo.run/display-name": "", + "rbac.authorization.halo.run/display-name": "", }!, }, rules: [], @@ -46,7 +47,9 @@ const creationFormState = ref({ const roleTemplates = computed(() => { return roles.value.filter( - (role) => role.metadata.labels?.["plugin.halo.run/role-template"] === "true" + (role) => + role.metadata.labels?.["halo.run/role-template"] === "true" && + role.metadata.labels?.["halo.run/hidden"] !== "true" ); }); @@ -55,13 +58,19 @@ const roleTemplateGroups = computed(() => { roleTemplates.value.forEach((role) => { const group = groups.find( (group) => - group.name === role.metadata.annotations?.["plugin.halo.run/module"] + group.module === + role.metadata.annotations?.["rbac.authorization.halo.run/module"] ); if (group) { group.roles.push(role); } else { groups.push({ - name: role.metadata.annotations?.["plugin.halo.run/module"], + module: + role.metadata.annotations?.["rbac.authorization.halo.run/module"], + displayName: + role.metadata.annotations?.[ + "rbac.authorization.halo.run/display-name" + ], roles: [role], }); } @@ -132,7 +141,7 @@ watch(
- {{ group.name }} + {{ group.displayName }}
  • -
    -
    +
    {{ role.metadata.annotations?.[ - "plugin.halo.run/display-name" + "rbac.authorization.halo.run/display-name" ] }} @@ -196,7 +205,7 @@ watch( }}
    -
    +