feat: support for configuring the redirection location after login for roles (#4918)

#### 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
支持为自定义的角色配置登录之后默认跳转位置。
```
pull/4878/head^2
Ryan Wang 2023-11-27 22:10:09 +08:00 committed by GitHub
parent 927398b6bd
commit 82a6ba6d90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 4 deletions

View File

@ -154,6 +154,15 @@ const handleResetForm = () => {
type="text"
validation="required|length:0,50"
></FormKit>
<FormKit
v-model="
formState.metadata.annotations[
rbacAnnotations.REDIRECT_ON_LOGIN
]
"
type="text"
label="登录之后默认跳转位置"
></FormKit>
</FormKit>
</div>
</div>

View File

@ -1,3 +1,4 @@
import { rbacAnnotations } from "@/constants/annotations";
import { useUserStore } from "@/stores/user";
import type { Router } from "vue-router";
@ -29,14 +30,28 @@ export function setupAuthCheckGuard(router: Router) {
redirect_uri: to.query.redirect_uri,
},
});
} else {
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;
}
}
}
next();
});

View File

@ -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