From 2ca70e7b723ab8f90906a0c9a285734d0f562c0d Mon Sep 17 00:00:00 2001 From: Halo Dev Bot <87291978+halo-dev-bot@users.noreply.github.com> Date: Wed, 7 Dec 2022 14:18:54 +0800 Subject: [PATCH] [release-2.0] feat: refining the logic of user roles (#756) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is an automated cherry-pick of #749 /assign JohnNiang ```release-note 完善 Console 端用户角色的相关逻辑 ``` --- src/constants/constants.ts | 1 + src/constants/labels.ts | 1 + src/modules/system/roles/RoleDetail.vue | 64 ++++++++++++++----- src/modules/system/roles/RoleList.vue | 59 +++++++++++++---- .../system/roles/composables/use-role.ts | 8 ++- 5 files changed, 105 insertions(+), 28 deletions(-) create mode 100644 src/constants/constants.ts diff --git a/src/constants/constants.ts b/src/constants/constants.ts new file mode 100644 index 00000000..1a9befd1 --- /dev/null +++ b/src/constants/constants.ts @@ -0,0 +1 @@ +export const SUPER_ROLE_NAME = "super-role"; diff --git a/src/constants/labels.ts b/src/constants/labels.ts index c5df31e2..1cb0ac07 100644 --- a/src/constants/labels.ts +++ b/src/constants/labels.ts @@ -6,6 +6,7 @@ export enum pluginLabels { // role export enum roleLabels { TEMPLATE = "halo.run/role-template", + SYSTEM_RESERVED = "rbac.authorization.halo.run/system-reserved", } // post diff --git a/src/modules/system/roles/RoleDetail.vue b/src/modules/system/roles/RoleDetail.vue index a4263a0b..76ce43e5 100644 --- a/src/modules/system/roles/RoleDetail.vue +++ b/src/modules/system/roles/RoleDetail.vue @@ -8,17 +8,19 @@ import { VTabbar, VTag, VAvatar, + VAlert, } from "@halo-dev/components"; import { useRoute } from "vue-router"; -import { onMounted, ref, watch } from "vue"; +import { computed, onMounted, ref, watch } from "vue"; import { apiClient } from "@/utils/api-client"; -import { pluginLabels } from "@/constants/labels"; +import { pluginLabels, roleLabels } from "@/constants/labels"; import { rbacAnnotations } from "@/constants/annotations"; import { useRoleForm, useRoleTemplateSelection, } from "@/modules/system/roles/composables/use-role"; import { useUserFetch } from "@/modules/system/users/composables/use-user"; +import { SUPER_ROLE_NAME } from "@/constants/constants"; const route = useRoute(); @@ -31,6 +33,28 @@ const { formState, saving, handleCreateOrUpdate } = useRoleForm(); const { users } = useUserFetch({ fetchOnMounted: false }); +const isSystemReserved = computed(() => { + return ( + formState.value.metadata.labels?.[roleLabels.SYSTEM_RESERVED] === "true" + ); +}); + +const isSuperRole = computed(() => { + return formState.value.metadata.name === SUPER_ROLE_NAME; +}); + +const getRoleCountText = computed(() => { + if (formState.value.metadata.name === SUPER_ROLE_NAME) { + return `包含所有权限`; + } + + const dependenciesCount = JSON.parse( + formState.value.metadata.annotations?.[rbacAnnotations.DEPENDENCIES] || "[]" + ).length; + + return `包含 ${dependenciesCount} 个权限`; +}); + watch( () => selectedRoleTemplates.value, (newValue) => { @@ -97,17 +121,7 @@ onMounted(() => {
- 包含 - {{ - JSON.parse( - formState.metadata.annotations?.[ - rbacAnnotations.DEPENDENCIES - ] || "[]" - ).length - }} - 个权限 + {{ getRoleCountText }}