Skip to content

Commit 596c466

Browse files
authored
Merge pull request #424 from lowcoder-org/oauth-fixes
Add Handling To Delete An Auth Config Permanently
2 parents e3fd6df + 62bb7dd commit 596c466

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/authentication/AuthenticationController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public Mono<ResponseView<Void>> enableAuthConfig(@RequestBody AuthConfigRequest
9090
}
9191

9292
@DeleteMapping("/config/{id}")
93-
public Mono<ResponseView<Void>> disableAuthConfig(@PathVariable("id") String id) {
94-
return authenticationApiService.disableAuthConfig(id)
93+
public Mono<ResponseView<Void>> disableAuthConfig(@PathVariable("id") String id, @RequestParam(required = false) boolean delete) {
94+
return authenticationApiService.disableAuthConfig(id, delete)
9595
.thenReturn(ResponseView.success(null));
9696
}
9797

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/authentication/service/AuthenticationApiService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface AuthenticationApiService {
1717

1818
Mono<Boolean> enableAuthConfig(AuthConfigRequest authConfigRequest);
1919

20-
Mono<Boolean> disableAuthConfig(String authId);
20+
Mono<Boolean> disableAuthConfig(String authId, boolean delete);
2121

2222
Flux<FindAuthConfig> findAuthConfigs(boolean enableOnly);
2323
}

server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/authentication/service/AuthenticationApiServiceImpl.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import javax.annotation.Nullable;
4242
import java.util.*;
4343
import java.util.function.Function;
44+
import java.util.function.Predicate;
4445
import java.util.stream.Collectors;
4546

4647
import static org.lowcoder.sdk.exception.BizError.*;
@@ -239,12 +240,12 @@ public Mono<Boolean> enableAuthConfig(AuthConfigRequest authConfigRequest) {
239240
}
240241

241242
@Override
242-
public Mono<Boolean> disableAuthConfig(String authId) {
243+
public Mono<Boolean> disableAuthConfig(String authId, boolean delete) {
243244
return checkIfAdmin()
244245
.then(checkIfOnlyEffectiveCurrentUserConnections(authId))
245246
.then(sessionUserService.getVisitorOrgMemberCache())
246247
.flatMap(orgMember -> organizationService.getById(orgMember.getOrgId()))
247-
.doOnNext(organization -> disableAuthConfig(organization, authId))
248+
.doOnNext(organization -> disableAuthConfig(organization, authId, delete))
248249
.flatMap(organization -> organizationService.update(organization.getId(), organization))
249250
.delayUntil(result -> {
250251
if (result) {
@@ -309,13 +310,28 @@ private Mono<Void> checkIfOnlyEffectiveCurrentUserConnections(String authId) {
309310
.then();
310311
}
311312

312-
private void disableAuthConfig(Organization organization, String authId) {
313-
Optional.of(organization)
314-
.map(Organization::getAuthConfigs)
315-
.orElse(Collections.emptyList())
316-
.stream()
317-
.filter(abstractAuthConfig -> Objects.equals(abstractAuthConfig.getId(), authId))
318-
.forEach(abstractAuthConfig -> abstractAuthConfig.setEnable(false));
313+
private void disableAuthConfig(Organization organization, String authId, boolean delete) {
314+
315+
Predicate<AbstractAuthConfig> authConfigPredicate = abstractAuthConfig -> Objects.equals(abstractAuthConfig.getId(), authId);
316+
317+
if(delete) {
318+
List<AbstractAuthConfig> abstractAuthConfigs = Optional.of(organization)
319+
.map(Organization::getAuthConfigs)
320+
.orElse(Collections.emptyList());
321+
322+
abstractAuthConfigs.removeIf(authConfigPredicate);
323+
324+
organization.getOrganizationDomain().setConfigs(abstractAuthConfigs);
325+
326+
} else {
327+
Optional.of(organization)
328+
.map(Organization::getAuthConfigs)
329+
.orElse(Collections.emptyList()).stream()
330+
.filter(authConfigPredicate)
331+
.forEach(abstractAuthConfig -> {
332+
abstractAuthConfig.setEnable(false);
333+
});
334+
}
319335
}
320336

321337
/**

0 commit comments

Comments
 (0)