mirror of https://github.com/halo-dev/halo
perf: hide disabled auth providers in user profile (#3561)
#### What type of PR is this? /kind improvement /area console #### What this PR does / why we need it: 隐藏个人资料中未启用的认证方式。 #### Which issue(s) this PR fixes: Fixes #3556 #### Special notes for your reviewer: 测试方式: 1. 安装 OAuth 2 插件:https://github.com/halo-sigs/plugin-oauth2/pull/3 2. 再不做任何配置的情况下,访问已登录用户的个人资料页面,检查是否列出了认证方式。 3. 配置某个认证方式并开启,再检查是否列出了已启用的认证方式。 #### Does this PR introduce a user-facing change? ```release-note None ```pull/3578/head^2
parent
6bc712d263
commit
8ce0913c0e
|
@ -23,6 +23,8 @@ import run.halo.app.extension.GVK;
|
||||||
singular = "authprovider", plural = "authproviders")
|
singular = "authprovider", plural = "authproviders")
|
||||||
public class AuthProvider extends AbstractExtension {
|
public class AuthProvider extends AbstractExtension {
|
||||||
|
|
||||||
|
public static final String AUTH_BINDING_LABEL = "auth.halo.run/auth-binding";
|
||||||
|
|
||||||
public static final String PRIVILEGED_LABEL = "auth.halo.run/privileged";
|
public static final String PRIVILEGED_LABEL = "auth.halo.run/privileged";
|
||||||
|
|
||||||
@Schema(requiredMode = REQUIRED)
|
@Schema(requiredMode = REQUIRED)
|
||||||
|
|
|
@ -139,12 +139,18 @@ public class AuthProviderServiceImpl implements AuthProviderService {
|
||||||
.helpPage(authProvider.getSpec().getHelpPage())
|
.helpPage(authProvider.getSpec().getHelpPage())
|
||||||
.bindingUrl(authProvider.getSpec().getBindingUrl())
|
.bindingUrl(authProvider.getSpec().getBindingUrl())
|
||||||
.unbindingUrl(authProvider.getSpec().getUnbindUrl())
|
.unbindingUrl(authProvider.getSpec().getUnbindUrl())
|
||||||
|
.supportsBinding(supportsBinding(authProvider))
|
||||||
.isBound(false)
|
.isBound(false)
|
||||||
.enabled(false)
|
.enabled(false)
|
||||||
.privileged(privileged(authProvider))
|
.privileged(privileged(authProvider))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean supportsBinding(AuthProvider authProvider) {
|
||||||
|
return BooleanUtils.TRUE.equals(MetadataUtil.nullSafeLabels(authProvider)
|
||||||
|
.get(AuthProvider.AUTH_BINDING_LABEL));
|
||||||
|
}
|
||||||
|
|
||||||
private boolean privileged(AuthProvider authProvider) {
|
private boolean privileged(AuthProvider authProvider) {
|
||||||
return BooleanUtils.TRUE.equals(MetadataUtil.nullSafeLabels(authProvider)
|
return BooleanUtils.TRUE.equals(MetadataUtil.nullSafeLabels(authProvider)
|
||||||
.get(AuthProvider.PRIVILEGED_LABEL));
|
.get(AuthProvider.PRIVILEGED_LABEL));
|
||||||
|
|
|
@ -39,5 +39,7 @@ public class ListedAuthProvider {
|
||||||
|
|
||||||
Boolean enabled;
|
Boolean enabled;
|
||||||
|
|
||||||
|
Boolean supportsBinding;
|
||||||
|
|
||||||
Boolean privileged;
|
Boolean privileged;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ kind: AuthProvider
|
||||||
metadata:
|
metadata:
|
||||||
name: local
|
name: local
|
||||||
labels:
|
labels:
|
||||||
|
auth.halo.run/auth-binding: "false"
|
||||||
auth.halo.run/privileged: "true"
|
auth.halo.run/privileged: "true"
|
||||||
finalizers:
|
finalizers:
|
||||||
- system-protection
|
- system-protection
|
||||||
|
|
|
@ -144,6 +144,7 @@ class AuthProviderServiceImplTest {
|
||||||
"bindingUrl": "fake-binding-url",
|
"bindingUrl": "fake-binding-url",
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"isBound": false,
|
"isBound": false,
|
||||||
|
"supportsBinding": false,
|
||||||
"privileged": false
|
"privileged": false
|
||||||
}, {
|
}, {
|
||||||
"name": "gitlab",
|
"name": "gitlab",
|
||||||
|
@ -151,6 +152,7 @@ class AuthProviderServiceImplTest {
|
||||||
"bindingUrl": "fake-binding-url",
|
"bindingUrl": "fake-binding-url",
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"isBound": false,
|
"isBound": false,
|
||||||
|
"supportsBinding": false,
|
||||||
"privileged": false
|
"privileged": false
|
||||||
},{
|
},{
|
||||||
|
|
||||||
|
@ -158,6 +160,7 @@ class AuthProviderServiceImplTest {
|
||||||
"displayName": "gitee",
|
"displayName": "gitee",
|
||||||
"enabled": false,
|
"enabled": false,
|
||||||
"isBound": false,
|
"isBound": false,
|
||||||
|
"supportsBinding": false,
|
||||||
"privileged": false
|
"privileged": false
|
||||||
}]
|
}]
|
||||||
""",
|
""",
|
||||||
|
|
|
@ -72,6 +72,12 @@ export interface ListedAuthProvider {
|
||||||
* @memberof ListedAuthProvider
|
* @memberof ListedAuthProvider
|
||||||
*/
|
*/
|
||||||
name: string;
|
name: string;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @type {boolean}
|
||||||
|
* @memberof ListedAuthProvider
|
||||||
|
*/
|
||||||
|
supportsBinding?: boolean;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
|
|
|
@ -158,7 +158,10 @@ const handleBindAuth = (authProvider: ListedAuthProvider) => {
|
||||||
<dd class="mt-1 text-sm sm:col-span-3 sm:mt-0">
|
<dd class="mt-1 text-sm sm:col-span-3 sm:mt-0">
|
||||||
<ul class="space-y-2">
|
<ul class="space-y-2">
|
||||||
<template v-for="(authProvider, index) in authProviders">
|
<template v-for="(authProvider, index) in authProviders">
|
||||||
<li v-if="authProvider.bindingUrl" :key="index">
|
<li
|
||||||
|
v-if="authProvider.supportsBinding && authProvider.enabled"
|
||||||
|
:key="index"
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
class="flex w-full cursor-pointer flex-wrap justify-between gap-y-3 rounded border p-5 hover:border-primary sm:w-1/2"
|
class="flex w-full cursor-pointer flex-wrap justify-between gap-y-3 rounded border p-5 hover:border-primary sm:w-1/2"
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in New Issue