From 79e8e3005da3499de7098e7434bded57d0f842cb Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 20 Jul 2022 15:24:35 +0800 Subject: [PATCH] feat: plugin details support display of included roles Signed-off-by: Ryan Wang --- src/modules/system/plugins/PluginDetail.vue | 162 +++++++++++--------- 1 file changed, 87 insertions(+), 75 deletions(-) diff --git a/src/modules/system/plugins/PluginDetail.vue b/src/modules/system/plugins/PluginDetail.vue index 33880646..e3a40b6b 100644 --- a/src/modules/system/plugins/PluginDetail.vue +++ b/src/modules/system/plugins/PluginDetail.vue @@ -16,6 +16,7 @@ import type { ConfigMap, Setting, SettingSpec, + Role, } from "@halo-dev/api-client"; import cloneDeep from "lodash.clonedeep"; import type { FormKitSchemaCondition, FormKitSchemaNode } from "@formkit/core"; @@ -174,7 +175,57 @@ const handleChangePluginStatus = async () => { }); }; -onMounted(handleFetchPlugin); +// TODO 临时解决方案 +interface RoleTemplateGroup { + module: string | null | undefined; + roles: Role[]; +} + +const roles = ref([]); + +const handleFetchRoles = async () => { + try { + const { data } = await apiClient.extension.role.listv1alpha1Role(); + roles.value = data.items; + } catch (e) { + console.error(e); + } +}; + +const pluginRoleTemplates = computed(() => { + return roles.value.filter((item) => { + return ( + item.metadata.labels?.["plugin.halo.run/plugin-name"] === + plugin.value.metadata.name + ); + }); +}); + +const pluginRoleTemplateGroups = computed(() => { + const groups: RoleTemplateGroup[] = []; + pluginRoleTemplates.value.forEach((role) => { + const group = groups.find( + (group) => + group.module === + role.metadata.annotations?.["rbac.authorization.halo.run/module"] + ); + if (group) { + group.roles.push(role); + } else { + groups.push({ + module: + role.metadata.annotations?.["rbac.authorization.halo.run/module"], + roles: [role], + }); + } + }); + return groups; +}); + +onMounted(() => { + handleFetchPlugin(); + handleFetchRoles(); +});