|
41 | 41 | import javax.annotation.Nullable;
|
42 | 42 | import java.util.*;
|
43 | 43 | import java.util.function.Function;
|
| 44 | +import java.util.function.Predicate; |
44 | 45 | import java.util.stream.Collectors;
|
45 | 46 |
|
46 | 47 | import static org.lowcoder.sdk.exception.BizError.*;
|
@@ -239,12 +240,12 @@ public Mono<Boolean> enableAuthConfig(AuthConfigRequest authConfigRequest) {
|
239 | 240 | }
|
240 | 241 |
|
241 | 242 | @Override
|
242 |
| - public Mono<Boolean> disableAuthConfig(String authId) { |
| 243 | + public Mono<Boolean> disableAuthConfig(String authId, boolean delete) { |
243 | 244 | return checkIfAdmin()
|
244 | 245 | .then(checkIfOnlyEffectiveCurrentUserConnections(authId))
|
245 | 246 | .then(sessionUserService.getVisitorOrgMemberCache())
|
246 | 247 | .flatMap(orgMember -> organizationService.getById(orgMember.getOrgId()))
|
247 |
| - .doOnNext(organization -> disableAuthConfig(organization, authId)) |
| 248 | + .doOnNext(organization -> disableAuthConfig(organization, authId, delete)) |
248 | 249 | .flatMap(organization -> organizationService.update(organization.getId(), organization))
|
249 | 250 | .delayUntil(result -> {
|
250 | 251 | if (result) {
|
@@ -309,13 +310,28 @@ private Mono<Void> checkIfOnlyEffectiveCurrentUserConnections(String authId) {
|
309 | 310 | .then();
|
310 | 311 | }
|
311 | 312 |
|
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 | + } |
319 | 335 | }
|
320 | 336 |
|
321 | 337 | /**
|
|
0 commit comments