From 6d76a65907d0219de8ee16effcab0b42c2500182 Mon Sep 17 00:00:00 2001 From: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com> Date: Wed, 26 Mar 2025 14:57:25 +0530 Subject: [PATCH] refactor the creation of workspace and application on signup --- .../ce/AuthenticationSuccessHandlerCE.java | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/handlers/ce/AuthenticationSuccessHandlerCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/handlers/ce/AuthenticationSuccessHandlerCE.java index 78076db7ab2c..3b9645ad6569 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/handlers/ce/AuthenticationSuccessHandlerCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/authentication/handlers/ce/AuthenticationSuccessHandlerCE.java @@ -349,15 +349,15 @@ public Mono onAuthenticationSuccess( } protected Mono createDefaultApplication(String defaultWorkspaceId, Authentication authentication) { - // need to create default application - Application application = new Application(); - application.setWorkspaceId(defaultWorkspaceId); - application.setName("My first application"); - Mono applicationMono = Mono.just(application); - if (defaultWorkspaceId == null) { + return createWorkspaceIfNotExistsAndGetId(defaultWorkspaceId, authentication) + .flatMap(this::createFirstApplication); + } - applicationMono = workspaceRepository + protected Mono createWorkspaceIfNotExistsAndGetId( + String defaultWorkspaceId, Authentication authentication) { + if (defaultWorkspaceId == null) { + return workspaceRepository .findAll(workspacePermission.getEditPermission()) .take(1, true) .collectList() @@ -366,8 +366,7 @@ protected Mono createDefaultApplication(String defaultWorkspaceId, // workspace user has access to, and would be user's default workspace. Hence, we use this // workspace to create the application. if (workspaces.size() == 1) { - application.setWorkspaceId(workspaces.get(0).getId()); - return Mono.just(application); + return Mono.just(workspaces.get(0)); } // In case no workspaces are found for the user, create a new default workspace @@ -376,15 +375,20 @@ protected Mono createDefaultApplication(String defaultWorkspaceId, return organizationService .getCurrentUserOrganizationId() .flatMap(orgId -> userRepository.findByEmailAndOrganizationId(email, orgId)) - .flatMap(user -> workspaceService.createDefault(new Workspace(), user)) - .map(workspace -> { - application.setWorkspaceId(workspace.getId()); - return application; - }); - }); + .flatMap(user -> workspaceService.createDefault(new Workspace(), user)); + }) + .map(Workspace::getId); } - return applicationMono.flatMap(applicationPageService::createApplication); + return Mono.just(defaultWorkspaceId); + } + + protected Mono createFirstApplication(String workspaceId) { + // need to create default application + Application application = new Application(); + application.setWorkspaceId(workspaceId); + application.setName("My first application"); + return applicationPageService.createApplication(application); } /**