diff --git a/api/src/main/java/run/halo/app/infra/SystemSetting.java b/api/src/main/java/run/halo/app/infra/SystemSetting.java index 6339b54512..163b709ea6 100644 --- a/api/src/main/java/run/halo/app/infra/SystemSetting.java +++ b/api/src/main/java/run/halo/app/infra/SystemSetting.java @@ -3,6 +3,8 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import lombok.Data; import lombok.experimental.Accessors; import org.springframework.boot.convert.ApplicationConversionService; @@ -114,7 +116,34 @@ public static class Menu { @Data public static class AuthProvider { public static final String GROUP = "authProvider"; + /** + * Currently keep it to be compatible with the reference of the plugin. + * + * @deprecated Use {@link #getStates()} instead. + */ + @Deprecated(since = "2.20.0", forRemoval = true) + private Set enabled; + private List states; + + /** + *

To be compatible with the old version of the enabled field and retained, + * since 2.20.0 version, we uses the states field, so the data needs to be synchronized + * to the enabled field, and this method needs to be deleted when the enabled field is + * removed.

+ * + * @deprecated Use {@link #getStates()} instead. + */ + @Deprecated(since = "2.20.0", forRemoval = true) + public Set getEnabled() { + if (states == null) { + return enabled; + } + return this.states.stream() + .filter(AuthProviderState::isEnabled) + .map(AuthProviderState::getName) + .collect(Collectors.toSet()); + } } @Data diff --git a/application/src/test/java/run/halo/app/security/AuthProviderServiceImplTest.java b/application/src/test/java/run/halo/app/security/AuthProviderServiceImplTest.java index a0bbd463ad..6583e13c23 100644 --- a/application/src/test/java/run/halo/app/security/AuthProviderServiceImplTest.java +++ b/application/src/test/java/run/halo/app/security/AuthProviderServiceImplTest.java @@ -66,6 +66,7 @@ void testEnable() throws JSONException { ConfigMap value = captor.getValue(); JSONAssert.assertEquals(""" { + "enabled":["github"], "states": [ { "name": "github", @@ -102,6 +103,7 @@ void testDisable() throws JSONException { ConfigMap value = captor.getValue(); JSONAssert.assertEquals(""" { + "enabled":[], "states": [ { "name": "github",