@@ -246,9 +246,13 @@ public Mono<Boolean> enableAuthConfig(AuthConfigRequest authConfigRequest) {
246
246
.then (sessionUserService .getVisitorOrgMemberCache ())
247
247
.flatMap (orgMember ->organizationService .getById (orgMember .getOrgId ()))
248
248
.doOnNext (organization -> {
249
- boolean duplicateAuthType =addOrUpdateNewAuthConfig (organization ,authConfigFactory .build (authConfigRequest ,true ));
250
- if (duplicateAuthType ) {
251
- deferredError (DUPLICATE_AUTH_CONFIG_ADDITION ,"DUPLICATE_AUTH_CONFIG_ADDITION" );
249
+ if (authConfigRequest .getId ().equals ("EMAIL" )) {
250
+ organization .setIsEmailDisabled (false );
251
+ }else {
252
+ boolean duplicateAuthType =addOrUpdateNewAuthConfig (organization ,authConfigFactory .build (authConfigRequest ,true ));
253
+ if (duplicateAuthType ) {
254
+ deferredError (DUPLICATE_AUTH_CONFIG_ADDITION ,"DUPLICATE_AUTH_CONFIG_ADDITION" );
255
+ }
252
256
}
253
257
})
254
258
.flatMap (organization ->organizationService .update (organization .getId (),organization ));
@@ -346,22 +350,15 @@ private Mono<Void> checkIfAdmin() {
346
350
* If true, throw an exception to avoid disabling the last effective connection way.
347
351
*/
348
352
private Mono <Void >checkIfOnlyEffectiveCurrentUserConnections (String authId ) {
349
- Mono <List <String >>userConnectionAuthConfigIdListMono =sessionUserService .getVisitor ()
350
- .flatMapIterable (User ::getConnections )
351
- .filter (connection ->StringUtils .isNotBlank (connection .getAuthId ()))
352
- .map (Connection ::getAuthId )
353
- .collectList ();
354
- Mono <List <String >>orgAuthIdListMono =authenticationService .findAllAuthConfigs (null ,true )
355
- .map (FindAuthConfig ::authConfig )
356
- .map (AbstractAuthConfig ::getId )
357
- .collectList ();
358
- return Mono .zip (userConnectionAuthConfigIdListMono ,orgAuthIdListMono )
359
- .delayUntil (tuple -> {
360
- List <String >userConnectionAuthConfigIds =tuple .getT1 ();
361
- List <String >orgAuthConfigIds =tuple .getT2 ();
362
- userConnectionAuthConfigIds .retainAll (orgAuthConfigIds );
363
- userConnectionAuthConfigIds .remove (authId );
364
- if (CollectionUtils .isEmpty (userConnectionAuthConfigIds )) {
353
+ return sessionUserService .getVisitorOrgMemberCache ()
354
+ .map (OrgMember ::getOrgId )
355
+ .flatMap (orgId ->authenticationService .findAllAuthConfigs (orgId ,true )
356
+ .map (FindAuthConfig ::authConfig )
357
+ .map (AbstractAuthConfig ::getId )
358
+ .collectList ())
359
+ .delayUntil (orgAuthConfigIds -> {
360
+ orgAuthConfigIds .remove (authId );
361
+ if (CollectionUtils .isEmpty (orgAuthConfigIds )) {
365
362
return Mono .error (new BizException (DISABLE_AUTH_CONFIG_FORBIDDEN ,"DISABLE_AUTH_CONFIG_FORBIDDEN" ));
366
363
}
367
364
return Mono .empty ();
@@ -370,26 +367,29 @@ private Mono<Void> checkIfOnlyEffectiveCurrentUserConnections(String authId) {
370
367
}
371
368
372
369
private void disableAuthConfig (Organization organization ,String authId ,boolean delete ) {
373
-
374
- Predicate <AbstractAuthConfig >authConfigPredicate =abstractAuthConfig ->Objects .equals (abstractAuthConfig .getId (),authId );
375
-
376
- if (delete ) {
377
- List <AbstractAuthConfig >abstractAuthConfigs =Optional .of (organization )
378
- .map (Organization ::getAuthConfigs )
379
- .orElse (Collections .emptyList ());
380
-
381
- abstractAuthConfigs .removeIf (authConfigPredicate );
382
-
383
- organization .getOrganizationDomain ().setConfigs (abstractAuthConfigs );
384
-
370
+ if (authId .equals ("EMAIL" )) {
371
+ organization .setIsEmailDisabled (true );
385
372
}else {
386
- Optional .of (organization )
387
- .map (Organization ::getAuthConfigs )
388
- .orElse (Collections .emptyList ()).stream ()
389
- .filter (authConfigPredicate )
390
- .forEach (abstractAuthConfig -> {
391
- abstractAuthConfig .setEnable (false );
392
- });
373
+ Predicate <AbstractAuthConfig >authConfigPredicate =abstractAuthConfig ->Objects .equals (abstractAuthConfig .getId (),authId );
374
+
375
+ if (delete ) {
376
+ List <AbstractAuthConfig >abstractAuthConfigs =Optional .of (organization )
377
+ .map (Organization ::getAuthConfigs )
378
+ .orElse (Collections .emptyList ());
379
+
380
+ abstractAuthConfigs .removeIf (authConfigPredicate );
381
+
382
+ organization .getOrganizationDomain ().setConfigs (abstractAuthConfigs );
383
+
384
+ }else {
385
+ Optional .of (organization )
386
+ .map (Organization ::getAuthConfigs )
387
+ .orElse (Collections .emptyList ()).stream ()
388
+ .filter (authConfigPredicate )
389
+ .forEach (abstractAuthConfig -> {
390
+ abstractAuthConfig .setEnable (false );
391
+ });
392
+ }
393
393
}
394
394
}
395
395