fix: Creating default workspace for SSO signed up users before creating first application (#16579)
This commit is contained in:
parent
ee35760097
commit
70bb40d5c5
|
|
@ -2,12 +2,12 @@ package com.appsmith.server.authentication.handlers;
|
||||||
|
|
||||||
import com.appsmith.server.authentication.handlers.ce.AuthenticationSuccessHandlerCE;
|
import com.appsmith.server.authentication.handlers.ce.AuthenticationSuccessHandlerCE;
|
||||||
import com.appsmith.server.helpers.RedirectHelper;
|
import com.appsmith.server.helpers.RedirectHelper;
|
||||||
import com.appsmith.server.repositories.WorkspaceRepository;
|
|
||||||
import com.appsmith.server.repositories.UserRepository;
|
import com.appsmith.server.repositories.UserRepository;
|
||||||
import com.appsmith.server.services.AnalyticsService;
|
import com.appsmith.server.services.AnalyticsService;
|
||||||
import com.appsmith.server.services.ApplicationPageService;
|
import com.appsmith.server.services.ApplicationPageService;
|
||||||
import com.appsmith.server.services.SessionUserService;
|
import com.appsmith.server.services.SessionUserService;
|
||||||
import com.appsmith.server.services.UserDataService;
|
import com.appsmith.server.services.UserDataService;
|
||||||
|
import com.appsmith.server.services.WorkspaceService;
|
||||||
import com.appsmith.server.solutions.ExamplesWorkspaceCloner;
|
import com.appsmith.server.solutions.ExamplesWorkspaceCloner;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
@ -22,9 +22,10 @@ public class AuthenticationSuccessHandler extends AuthenticationSuccessHandlerCE
|
||||||
AnalyticsService analyticsService,
|
AnalyticsService analyticsService,
|
||||||
UserDataService userDataService,
|
UserDataService userDataService,
|
||||||
UserRepository userRepository,
|
UserRepository userRepository,
|
||||||
WorkspaceRepository workspaceRepository,
|
WorkspaceService workspaceService,
|
||||||
ApplicationPageService applicationPageService) {
|
ApplicationPageService applicationPageService) {
|
||||||
|
|
||||||
super(examplesWorkspaceCloner, redirectHelper, sessionUserService, analyticsService, userDataService,
|
super(examplesWorkspaceCloner, redirectHelper, sessionUserService, analyticsService, userDataService,
|
||||||
userRepository, workspaceRepository, applicationPageService);
|
userRepository, workspaceService, applicationPageService);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,20 @@
|
||||||
package com.appsmith.server.authentication.handlers.ce;
|
package com.appsmith.server.authentication.handlers.ce;
|
||||||
|
|
||||||
import com.appsmith.server.authentication.handlers.CustomServerOAuth2AuthorizationRequestResolver;
|
|
||||||
import com.appsmith.external.constants.AnalyticsEvents;
|
import com.appsmith.external.constants.AnalyticsEvents;
|
||||||
|
import com.appsmith.server.authentication.handlers.CustomServerOAuth2AuthorizationRequestResolver;
|
||||||
import com.appsmith.server.constants.FieldName;
|
import com.appsmith.server.constants.FieldName;
|
||||||
import com.appsmith.server.constants.Security;
|
import com.appsmith.server.constants.Security;
|
||||||
import com.appsmith.server.domains.Application;
|
import com.appsmith.server.domains.Application;
|
||||||
import com.appsmith.server.domains.LoginSource;
|
import com.appsmith.server.domains.LoginSource;
|
||||||
import com.appsmith.server.domains.User;
|
import com.appsmith.server.domains.User;
|
||||||
|
import com.appsmith.server.domains.Workspace;
|
||||||
import com.appsmith.server.helpers.RedirectHelper;
|
import com.appsmith.server.helpers.RedirectHelper;
|
||||||
import com.appsmith.server.repositories.WorkspaceRepository;
|
|
||||||
import com.appsmith.server.repositories.UserRepository;
|
import com.appsmith.server.repositories.UserRepository;
|
||||||
import com.appsmith.server.services.AnalyticsService;
|
import com.appsmith.server.services.AnalyticsService;
|
||||||
import com.appsmith.server.services.ApplicationPageService;
|
import com.appsmith.server.services.ApplicationPageService;
|
||||||
import com.appsmith.server.services.SessionUserService;
|
import com.appsmith.server.services.SessionUserService;
|
||||||
import com.appsmith.server.services.UserDataService;
|
import com.appsmith.server.services.UserDataService;
|
||||||
|
import com.appsmith.server.services.WorkspaceService;
|
||||||
import com.appsmith.server.solutions.ExamplesWorkspaceCloner;
|
import com.appsmith.server.solutions.ExamplesWorkspaceCloner;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -52,7 +53,7 @@ public class AuthenticationSuccessHandlerCE implements ServerAuthenticationSucce
|
||||||
private final AnalyticsService analyticsService;
|
private final AnalyticsService analyticsService;
|
||||||
private final UserDataService userDataService;
|
private final UserDataService userDataService;
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
private final WorkspaceRepository workspaceRepository;
|
private final WorkspaceService workspaceService;
|
||||||
private final ApplicationPageService applicationPageService;
|
private final ApplicationPageService applicationPageService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -103,7 +104,7 @@ public class AuthenticationSuccessHandlerCE implements ServerAuthenticationSucce
|
||||||
}
|
}
|
||||||
if(isFromSignup) {
|
if(isFromSignup) {
|
||||||
boolean finalIsFromSignup = isFromSignup;
|
boolean finalIsFromSignup = isFromSignup;
|
||||||
redirectionMono = createDefaultApplication(defaultWorkspaceId)
|
redirectionMono = createDefaultApplication(defaultWorkspaceId, authentication)
|
||||||
.flatMap(defaultApplication->handleOAuth2Redirect(webFilterExchange, defaultApplication, finalIsFromSignup));
|
.flatMap(defaultApplication->handleOAuth2Redirect(webFilterExchange, defaultApplication, finalIsFromSignup));
|
||||||
} else {
|
} else {
|
||||||
redirectionMono = handleOAuth2Redirect(webFilterExchange, null, isFromSignup);
|
redirectionMono = handleOAuth2Redirect(webFilterExchange, null, isFromSignup);
|
||||||
|
|
@ -111,7 +112,7 @@ public class AuthenticationSuccessHandlerCE implements ServerAuthenticationSucce
|
||||||
} else {
|
} else {
|
||||||
boolean finalIsFromSignup = isFromSignup;
|
boolean finalIsFromSignup = isFromSignup;
|
||||||
if(createDefaultApplication && isFromSignup) {
|
if(createDefaultApplication && isFromSignup) {
|
||||||
redirectionMono = createDefaultApplication(defaultWorkspaceId).flatMap(
|
redirectionMono = createDefaultApplication(defaultWorkspaceId, authentication).flatMap(
|
||||||
defaultApplication->handleRedirect(webFilterExchange, defaultApplication, finalIsFromSignup)
|
defaultApplication->handleRedirect(webFilterExchange, defaultApplication, finalIsFromSignup)
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -167,12 +168,28 @@ public class AuthenticationSuccessHandlerCE implements ServerAuthenticationSucce
|
||||||
.then(redirectionMono);
|
.then(redirectionMono);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mono<Application> createDefaultApplication(String defaultWorkspaceId) {
|
protected Mono<Application> createDefaultApplication(String defaultWorkspaceId, Authentication authentication) {
|
||||||
|
|
||||||
// need to create default application
|
// need to create default application
|
||||||
Application application = new Application();
|
Application application = new Application();
|
||||||
application.setWorkspaceId(defaultWorkspaceId);
|
application.setWorkspaceId(defaultWorkspaceId);
|
||||||
application.setName("My first application");
|
application.setName("My first application");
|
||||||
return applicationPageService.createApplication(application);
|
Mono<Application> applicationMono = Mono.just(application);
|
||||||
|
if (defaultWorkspaceId == null) {
|
||||||
|
String email = ((User) authentication.getPrincipal()).getEmail();
|
||||||
|
// This could happen if the user is signing up via SSO methods
|
||||||
|
log.debug("Creating blank default workspace for user '{}'.", email);
|
||||||
|
|
||||||
|
applicationMono = userRepository.findByEmail(email)
|
||||||
|
.flatMap(user -> workspaceService.createDefault(new Workspace(), user))
|
||||||
|
.map(workspace -> {
|
||||||
|
application.setWorkspaceId(workspace.getId());
|
||||||
|
return application;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return applicationMono
|
||||||
|
.flatMap(application1 -> applicationPageService.createApplication(application1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user