From 7e9f8128c3b46f36700a44f0a06f450c53d0e4ad Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Wed, 31 Jan 2024 15:42:57 +0800 Subject: [PATCH] fix: issue of non-template roles being displayed in personal token roles Signed-off-by: Ryan Wang --- console/src/constants/labels.ts | 1 + .../PersonalAccessTokenCreationModal.vue | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/console/src/constants/labels.ts b/console/src/constants/labels.ts index 1cb0ac071b..63939483ca 100644 --- a/console/src/constants/labels.ts +++ b/console/src/constants/labels.ts @@ -6,6 +6,7 @@ export enum pluginLabels { // role export enum roleLabels { TEMPLATE = "halo.run/role-template", + HIDDEN = "halo.run/hidden", SYSTEM_RESERVED = "rbac.authorization.halo.run/system-reserved", } diff --git a/console/uc-src/modules/profile/components/PersonalAccessTokenCreationModal.vue b/console/uc-src/modules/profile/components/PersonalAccessTokenCreationModal.vue index dee7ab2d23..e868a29cab 100644 --- a/console/uc-src/modules/profile/components/PersonalAccessTokenCreationModal.vue +++ b/console/uc-src/modules/profile/components/PersonalAccessTokenCreationModal.vue @@ -7,11 +7,11 @@ import { Dialog, Toast, VButton, VModal, VSpace } from "@halo-dev/components"; import { useMutation, useQueryClient } from "@tanstack/vue-query"; import { useClipboard } from "@vueuse/core"; import type { PatSpec, PersonalAccessToken } from "@halo-dev/api-client"; -import { ref } from "vue"; +import { computed, ref } from "vue"; import { useRoleTemplateSelection } from "@/composables/use-role"; import { useRoleStore } from "@/stores/role"; -import { toRefs } from "vue"; import { useI18n } from "vue-i18n"; +import { roleLabels } from "@/constants/labels"; const queryClient = useQueryClient(); const { t } = useI18n(); @@ -45,8 +45,17 @@ const formState = ref< const { permissions } = useRoleStore(); +const availableRoleTemplates = computed(() => { + return permissions.permissions.filter((role) => { + return ( + role.metadata.labels?.[roleLabels.TEMPLATE] === "true" && + role.metadata.labels?.[roleLabels.HIDDEN] !== "true" + ); + }); +}); + const { roleTemplateGroups, handleRoleTemplateSelect, selectedRoleTemplates } = - useRoleTemplateSelection(toRefs(permissions).permissions); + useRoleTemplateSelection(availableRoleTemplates); const { copy } = useClipboard({ legacy: true,