From fce581bd2d955d314948fe6afb93f8cc5b1ef571 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 15 Feb 2023 13:58:12 +0800 Subject: [PATCH] fix: the issue that role display name (halo-dev/console#847) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /kind improvement #### What this PR does / why we need it: 为系统初始化的角色添加显示名称 #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/3257 #### Screenshots: image #### Special notes for your reviewer: 测试方式: 1. Halo 需要切换到:https://github.com/halo-dev/halo/pull/3280 2. 检查 Console 端显示的系统角色是否正常。 3. 新建若干自定义角色,检查名称是否正常。 #### Does this PR introduce a user-facing change? ```release-note 优化 Console 端用户角色标识的显示名称。 ``` --- src/layouts/BasicLayout.vue | 18 +++++++---- src/main.ts | 3 ++ src/modules/system/roles/RoleList.vue | 4 +++ src/modules/system/users/UserDetail.vue | 9 +++++- src/modules/system/users/UserList.vue | 8 ++++- src/stores/role.ts | 42 +++++++++++++++++-------- 6 files changed, 63 insertions(+), 21 deletions(-) diff --git a/src/layouts/BasicLayout.vue b/src/layouts/BasicLayout.vue index 9092c952df..cc2629e701 100644 --- a/src/layouts/BasicLayout.vue +++ b/src/layouts/BasicLayout.vue @@ -27,6 +27,7 @@ import sortBy from "lodash.sortby"; import { useRoleStore } from "@/stores/role"; import { hasPermission } from "@/utils/permission"; import { useUserStore } from "@/stores/user"; +import { rbacAnnotations } from "@/constants/annotations"; const route = useRoute(); const router = useRouter(); @@ -56,11 +57,16 @@ const handleLogout = () => { }; const currentRole = computed(() => { - return JSON.parse( - userStore.currentUser?.metadata.annotations?.[ - "rbac.authorization.halo.run/role-names" - ] || "[]" - )[0]; + const names = JSON.parse( + userStore.currentUser?.metadata.annotations?.[rbacAnnotations.ROLE_NAMES] || + "[]" + ); + + if (names.length === 0) { + return; + } + + return roleStore.getRoleDisplayName(names[0]); }); // Global Search @@ -228,7 +234,7 @@ onMounted(generateMenus);
{{ userStore.currentUser?.spec.displayName }}
-
+