From 82a6ba6d9064d6b2af9ff5f0feac24453e699fa5 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Mon, 27 Nov 2023 22:10:09 +0800 Subject: [PATCH] feat: support for configuring the redirection location after login for roles (#4918) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #### What type of PR is this? /area console /kind feature /milestone 2.11.x #### What this PR does / why we need it: 支持为自定义的角色配置登录之后默认跳转位置。 #### Special notes for your reviewer: 1. 创建一个新的角色,设置跳转位置。 2. 为一个用户赋予这个角色。 3. 测试登录之后是否正常跳转到设置的位置。 #### Does this PR introduce a user-facing change? ```release-note 支持为自定义的角色配置登录之后默认跳转位置。 ``` --- .../roles/components/RoleEditingModal.vue | 9 ++++++++ .../console-src/router/guards/auth-check.ts | 23 +++++++++++++++---- console/src/constants/annotations.ts | 1 + 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/console/console-src/modules/system/roles/components/RoleEditingModal.vue b/console/console-src/modules/system/roles/components/RoleEditingModal.vue index 00b1d1a56..c093e5754 100644 --- a/console/console-src/modules/system/roles/components/RoleEditingModal.vue +++ b/console/console-src/modules/system/roles/components/RoleEditingModal.vue @@ -154,6 +154,15 @@ const handleResetForm = () => { type="text" validation="required|length:0,50" > + diff --git a/console/console-src/router/guards/auth-check.ts b/console/console-src/router/guards/auth-check.ts index 6d2be5a5b..710d579ca 100644 --- a/console/console-src/router/guards/auth-check.ts +++ b/console/console-src/router/guards/auth-check.ts @@ -1,3 +1,4 @@ +import { rbacAnnotations } from "@/constants/annotations"; import { useUserStore } from "@/stores/user"; import type { Router } from "vue-router"; @@ -29,12 +30,26 @@ export function setupAuthCheckGuard(router: Router) { redirect_uri: to.query.redirect_uri, }, }); - } else { - next({ - name: "Dashboard", - }); return; } + + const roleHasRedirectOnLogin = userStore.currentRoles?.find( + (role) => + role.metadata.annotations?.[rbacAnnotations.REDIRECT_ON_LOGIN] + ); + + if (roleHasRedirectOnLogin) { + window.location.href = + roleHasRedirectOnLogin.metadata.annotations?.[ + rbacAnnotations.REDIRECT_ON_LOGIN + ] || "/"; + return; + } + + next({ + name: "Dashboard", + }); + return; } } diff --git a/console/src/constants/annotations.ts b/console/src/constants/annotations.ts index 76ae27bab..93ee694cf 100644 --- a/console/src/constants/annotations.ts +++ b/console/src/constants/annotations.ts @@ -11,6 +11,7 @@ export enum rbacAnnotations { DEPENDENCIES = "rbac.authorization.halo.run/dependencies", AVATAR_ATTACHMENT_NAME = "halo.run/avatar-attachment-name", LAST_AVATAR_ATTACHMENT_NAME = "halo.run/last-avatar-attachment-name", + REDIRECT_ON_LOGIN = "rbac.authorization.halo.run/redirect-on-login", } // content