Skip to content

Commit 72f3928

Browse files
committed
fix: fixed saving of user profile changes
1 parent 2844e37 commit 72f3928

File tree

1 file changed

+14
-8
lines changed
  • server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/user/model

1 file changed

+14
-8
lines changed

server/api-service/lowcoder-domain/src/main/java/org/lowcoder/domain/user/model/User.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import lombok.*;
1212
import lombok.experimental.SuperBuilder;
1313
import lombok.extern.jackson.Jacksonized;
14+
import org.apache.commons.collections4.CollectionUtils;
15+
import org.apache.commons.collections4.ListUtils;
1416
import org.apache.commons.collections4.SetUtils;
1517
import org.apache.commons.lang3.StringUtils;
1618
import org.lowcoder.domain.mongodb.AfterMongodbRead;
@@ -79,8 +81,7 @@ public class User extends HasIdAndAuditing implements BeforeMongodbWrite, AfterM
7981
/**
8082
* Only used for mongodb (de)serialization
8183
*/
82-
@Builder.Default
83-
private List<Object> apiKeys = new ArrayList<>();
84+
private List<Object> apiKeys;
8485

8586
@Transient
8687
@JsonIgnore
@@ -143,15 +144,20 @@ public void markAsDeleted() {
143144

144145
@Override
145146
public void beforeMongodbWrite(MongodbInterceptorContext context) {
146-
this.apiKeysList.forEach(apiKey -> apiKey.doEncrypt(s -> context.encryptionService().encryptString(s)));
147-
apiKeys = JsonUtils.fromJsonSafely(JsonUtils.toJsonSafely(apiKeysList, SerializeConfig.JsonViews.Internal.class), new TypeReference<>() {
148-
}, new ArrayList<>());
147+
if (CollectionUtils.isNotEmpty(this.apiKeysList)) {
148+
this.apiKeysList.forEach(apiKey -> apiKey.doEncrypt(s -> context.encryptionService().encryptString(s)));
149+
apiKeys = JsonUtils.fromJsonSafely(JsonUtils.toJsonSafely(apiKeysList, SerializeConfig.JsonViews.Internal.class), new TypeReference<>() {
150+
}, new ArrayList<>());
151+
}
149152
}
150153

151154
@Override
152155
public void afterMongodbRead(MongodbInterceptorContext context) {
153-
this.apiKeysList = JsonUtils.fromJsonSafely(JsonUtils.toJson(apiKeys), new TypeReference<>() {
154-
}, new ArrayList<>());
155-
this.apiKeysList.forEach(authConfig -> authConfig.doDecrypt(s -> context.encryptionService().decryptString(s)));
156+
if (CollectionUtils.isNotEmpty(apiKeys))
157+
{
158+
this.apiKeysList = JsonUtils.fromJsonSafely(JsonUtils.toJson(apiKeys), new TypeReference<>() {
159+
}, new ArrayList<>());
160+
this.apiKeysList.forEach(authConfig -> authConfig.doDecrypt(s -> context.encryptionService().decryptString(s)));
161+
}
156162
}
157163
}

0 commit comments

Comments
 (0)