Skip to content

Commit

Permalink
fix: retain legacy enabled field for auth provider setting (#6861)
Browse files Browse the repository at this point in the history
#### What type of PR is this?
/kind bug
/area core
/milestone 2.20.x

#### What this PR does / why we need it:
恢复 #6846 中删除的 SystemSetting.AuthProvider#enabled 字段避免插件应用到了它可能会发生错误,将其标记为过时

#### Does this PR introduce a user-facing change?
```release-note
None
```
  • Loading branch information
guqing authored Oct 14, 2024
1 parent f7b2dcf commit 17eea82
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions api/src/main/java/run/halo/app/infra/SystemSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> enabled;

private List<AuthProviderState> states;

/**
* <p>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.</p>
*
* @deprecated Use {@link #getStates()} instead.
*/
@Deprecated(since = "2.20.0", forRemoval = true)
public Set<String> getEnabled() {
if (states == null) {
return enabled;
}
return this.states.stream()
.filter(AuthProviderState::isEnabled)
.map(AuthProviderState::getName)
.collect(Collectors.toSet());
}
}

@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void testEnable() throws JSONException {
ConfigMap value = captor.getValue();
JSONAssert.assertEquals("""
{
"enabled":["github"],
"states": [
{
"name": "github",
Expand Down Expand Up @@ -102,6 +103,7 @@ void testDisable() throws JSONException {
ConfigMap value = captor.getValue();
JSONAssert.assertEquals("""
{
"enabled":[],
"states": [
{
"name": "github",
Expand Down

0 comments on commit 17eea82

Please sign in to comment.