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
Ryan Wang 2023-03-27 16:32:12 +08:00 committed by GitHub
parent 6bc712d263
commit 8ce0913c0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 1 deletions

View File

@ -23,6 +23,8 @@ import run.halo.app.extension.GVK;
singular = "authprovider", plural = "authproviders")
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";
@Schema(requiredMode = REQUIRED)

View File

@ -139,12 +139,18 @@ public class AuthProviderServiceImpl implements AuthProviderService {
.helpPage(authProvider.getSpec().getHelpPage())
.bindingUrl(authProvider.getSpec().getBindingUrl())
.unbindingUrl(authProvider.getSpec().getUnbindUrl())
.supportsBinding(supportsBinding(authProvider))
.isBound(false)
.enabled(false)
.privileged(privileged(authProvider))
.build();
}
private static boolean supportsBinding(AuthProvider authProvider) {
return BooleanUtils.TRUE.equals(MetadataUtil.nullSafeLabels(authProvider)
.get(AuthProvider.AUTH_BINDING_LABEL));
}
private boolean privileged(AuthProvider authProvider) {
return BooleanUtils.TRUE.equals(MetadataUtil.nullSafeLabels(authProvider)
.get(AuthProvider.PRIVILEGED_LABEL));

View File

@ -39,5 +39,7 @@ public class ListedAuthProvider {
Boolean enabled;
Boolean supportsBinding;
Boolean privileged;
}

View File

@ -3,6 +3,7 @@ kind: AuthProvider
metadata:
name: local
labels:
auth.halo.run/auth-binding: "false"
auth.halo.run/privileged: "true"
finalizers:
- system-protection

View File

@ -144,6 +144,7 @@ class AuthProviderServiceImplTest {
"bindingUrl": "fake-binding-url",
"enabled": true,
"isBound": false,
"supportsBinding": false,
"privileged": false
}, {
"name": "gitlab",
@ -151,6 +152,7 @@ class AuthProviderServiceImplTest {
"bindingUrl": "fake-binding-url",
"enabled": false,
"isBound": false,
"supportsBinding": false,
"privileged": false
},{
@ -158,6 +160,7 @@ class AuthProviderServiceImplTest {
"displayName": "gitee",
"enabled": false,
"isBound": false,
"supportsBinding": false,
"privileged": false
}]
""",

View File

@ -72,6 +72,12 @@ export interface ListedAuthProvider {
* @memberof ListedAuthProvider
*/
name: string;
/**
*
* @type {boolean}
* @memberof ListedAuthProvider
*/
supportsBinding?: boolean;
/**
*
* @type {boolean}

View File

@ -158,7 +158,10 @@ const handleBindAuth = (authProvider: ListedAuthProvider) => {
<dd class="mt-1 text-sm sm:col-span-3 sm:mt-0">
<ul class="space-y-2">
<template v-for="(authProvider, index) in authProviders">
<li v-if="authProvider.bindingUrl" :key="index">
<li
v-if="authProvider.supportsBinding && authProvider.enabled"
:key="index"
>
<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"
>