From 50082fcd142c76d9dd505fad2ef8da2c84dfd2b5 Mon Sep 17 00:00:00 2001 From: Sidhant Goel Date: Fri, 6 May 2022 22:36:23 +0530 Subject: [PATCH] Renamed UserOrganizationServiceCE to UserWorkspaceService --- .../controllers/ce/UserControllerCE.java | 4 ++-- .../services/UserOrganizationService.java | 4 ++-- .../ce/UserOrganizationServiceCE.java | 24 ------------------- .../ce/UserOrganizationServiceCEImpl.java | 16 ++++++------- .../server/services/ce/UserServiceCEImpl.java | 2 +- .../services/ce/WorkspaceServiceCEImpl.java | 4 ++-- .../services/ActionCollectionServiceTest.java | 2 +- .../server/services/CommentServiceTest.java | 4 ++-- .../services/UserOrganizationServiceTest.java | 12 +++++----- .../server/services/WorkspaceServiceTest.java | 8 +++---- 10 files changed, 28 insertions(+), 52 deletions(-) delete mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserOrganizationServiceCE.java diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/UserControllerCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/UserControllerCE.java index 42bde452eb..d49e919248 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/UserControllerCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/UserControllerCE.java @@ -105,13 +105,13 @@ public class UserControllerCE extends BaseController @PutMapping("/addOrganization/{orgId}") public Mono> addUserToOrganization(@PathVariable String orgId) { - return userOrganizationService.addUserToOrganization(orgId, null) + return userOrganizationService.addUserToWorkspace(orgId, null) .map(user -> new ResponseDTO<>(HttpStatus.OK.value(), user, null)); } @PutMapping("/leaveOrganization/{orgId}") public Mono> leaveOrganization(@PathVariable String orgId) { - return userOrganizationService.leaveOrganization(orgId) + return userOrganizationService.leaveWorkspace(orgId) .map(user -> new ResponseDTO<>(HttpStatus.OK.value(), user, null)); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/UserOrganizationService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/UserOrganizationService.java index 49d9bec3c8..ab1495273c 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/UserOrganizationService.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/UserOrganizationService.java @@ -1,7 +1,7 @@ package com.appsmith.server.services; -import com.appsmith.server.services.ce.UserOrganizationServiceCE; +import com.appsmith.server.services.ce.UserWorkspaceServiceCE; -public interface UserOrganizationService extends UserOrganizationServiceCE { +public interface UserOrganizationService extends UserWorkspaceServiceCE { } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserOrganizationServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserOrganizationServiceCE.java deleted file mode 100644 index f7ed6835cc..0000000000 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserOrganizationServiceCE.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.appsmith.server.services.ce; - -import com.appsmith.server.domains.Workspace; -import com.appsmith.server.domains.User; -import com.appsmith.server.domains.UserRole; -import reactor.core.publisher.Mono; - -import java.util.List; - -public interface UserOrganizationServiceCE { - - Mono addUserToOrganization(String orgId, User user); - - Mono addUserRoleToOrganization(String orgId, UserRole userRole); - - Mono addUserToOrganizationGivenUserObject(Workspace organization, User user, UserRole userRole); - - Mono leaveOrganization(String orgId); - - Mono updateRoleForMember(String orgId, UserRole userRole, String originHeader); - - Mono bulkAddUsersToOrganization(Workspace organization, List users, String roleName); - -} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserOrganizationServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserOrganizationServiceCEImpl.java index 32bc368650..22cf618d59 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserOrganizationServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserOrganizationServiceCEImpl.java @@ -42,7 +42,7 @@ import static com.appsmith.server.acl.AclPermission.MANAGE_ORGANIZATIONS; @Slf4j -public class UserOrganizationServiceCEImpl implements UserOrganizationServiceCE { +public class UserOrganizationServiceCEImpl implements UserWorkspaceServiceCE { private final SessionUserService sessionUserService; private final WorkspaceRepository organizationRepository; private final UserRepository userRepository; @@ -79,7 +79,7 @@ public class UserOrganizationServiceCEImpl implements UserOrganizationServiceCE * @return */ @Override - public Mono addUserToOrganization(String orgId, User user) { + public Mono addUserToWorkspace(String orgId, User user) { Mono currentUserMono; if (user == null) { @@ -127,7 +127,7 @@ public class UserOrganizationServiceCEImpl implements UserOrganizationServiceCE } @Override - public Mono addUserRoleToOrganization(String orgId, UserRole userRole) { + public Mono addUserRoleToWorkspace(String orgId, UserRole userRole) { Mono organizationMono = organizationRepository.findById(orgId, MANAGE_ORGANIZATIONS) .switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, orgId))); Mono userMono = userRepository.findByEmail(userRole.getUsername()) @@ -137,12 +137,12 @@ public class UserOrganizationServiceCEImpl implements UserOrganizationServiceCE .flatMap(tuple -> { Workspace organization = tuple.getT1(); User user = tuple.getT2(); - return addUserToOrganizationGivenUserObject(organization, user, userRole); + return addUserToWorkspaceGivenUserObject(organization, user, userRole); }); } @Override - public Mono addUserToOrganizationGivenUserObject(Workspace organization, User user, UserRole userRole) { + public Mono addUserToWorkspaceGivenUserObject(Workspace organization, User user, UserRole userRole) { List userRoles = organization.getUserRoles(); if (userRoles == null) { userRoles = new ArrayList<>(); @@ -213,7 +213,7 @@ public class UserOrganizationServiceCEImpl implements UserOrganizationServiceCE } @Override - public Mono leaveOrganization(String orgId) { + public Mono leaveWorkspace(String orgId) { Mono organizationMono = organizationRepository.findById(orgId); Mono userMono = sessionUserService.getCurrentUser() .flatMap(user1 -> userRepository.findByEmail(user1.getUsername())); @@ -336,7 +336,7 @@ public class UserOrganizationServiceCEImpl implements UserOrganizationServiceCE if (userRole.getRoleName() != null) { // If a userRole name has been specified, then it means that the user's role has been modified. Mono userAddedToOrganizationMono = userRemovedOrganizationMono - .flatMap(organization1 -> this.addUserToOrganizationGivenUserObject(organization1, user, userRole)); + .flatMap(organization1 -> this.addUserToWorkspaceGivenUserObject(organization1, user, userRole)); finalUpdatedOrganizationMono = userAddedToOrganizationMono.flatMap(addedOrganization -> { Map params = new HashMap<>(); @@ -407,7 +407,7 @@ public class UserOrganizationServiceCEImpl implements UserOrganizationServiceCE } @Override - public Mono bulkAddUsersToOrganization(Workspace organization, List users, String roleName) { + public Mono bulkAddUsersToWorkspace(Workspace organization, List users, String roleName) { List userRoles = organization.getUserRoles(); if (userRoles == null) { userRoles = new ArrayList<>(); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserServiceCEImpl.java index 7008a00f5b..37bc11d123 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserServiceCEImpl.java @@ -723,7 +723,7 @@ public class UserServiceCEImpl extends BaseService .flatMap(tuple -> { List invitedUsers = tuple.getT1(); Workspace organization = tuple.getT2(); - return userOrganizationService.bulkAddUsersToOrganization(organization, invitedUsers, inviteUsersDTO.getRoleName()); + return userOrganizationService.bulkAddUsersToWorkspace(organization, invitedUsers, inviteUsersDTO.getRoleName()); }); // Add organization id to each invited user diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/WorkspaceServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/WorkspaceServiceCEImpl.java index ce4a686cdb..8eb20c14cc 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/WorkspaceServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/WorkspaceServiceCEImpl.java @@ -194,11 +194,11 @@ public class WorkspaceServiceCEImpl extends BaseService userOrganizationService - .addUserToOrganization(savedOrganization.getId(), user) + .addUserToWorkspace(savedOrganization.getId(), user) .thenReturn(savedOrganization)); } diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java index 015cb53408..1137213488 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ActionCollectionServiceTest.java @@ -227,7 +227,7 @@ public class ActionCollectionServiceTest { userRole.setRoleName(AppsmithRole.ORGANIZATION_ADMIN.getName()); userRole.setUsername("usertest@usertest.com"); - userOrganizationService.addUserRoleToOrganization(testApp.getOrganizationId(), userRole).block(); + userOrganizationService.addUserRoleToWorkspace(testApp.getOrganizationId(), userRole).block(); assert actionCollection != null; Mono readActionCollectionMono = diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/CommentServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/CommentServiceTest.java index f3623774c7..2d7ee31280 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/CommentServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/CommentServiceTest.java @@ -635,8 +635,8 @@ public class CommentServiceTest { userRole.setRole(AppsmithRole.ORGANIZATION_ADMIN); return userService.create(user) - .then(userOrganizationService.addUserRoleToOrganization(application.getOrganizationId(), userRole)) - .then(userOrganizationService.leaveOrganization(application.getOrganizationId())) + .then(userOrganizationService.addUserRoleToWorkspace(application.getOrganizationId(), userRole)) + .then(userOrganizationService.leaveWorkspace(application.getOrganizationId())) .thenReturn(application); }).flatMap(application -> { String pageId = application.getPublishedPages().get(0).getId(); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserOrganizationServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserOrganizationServiceTest.java index 7f5cb9c1a3..3a3cb5a48f 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserOrganizationServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserOrganizationServiceTest.java @@ -145,9 +145,9 @@ class UserOrganizationServiceTest { UserRole userRole = createUserRole(currentUser.getUsername(), currentUser.getId(), ORGANIZATION_DEVELOPER); Mono userMono = userOrganizationService - .addUserToOrganizationGivenUserObject(this.organization, currentUser, userRole) + .addUserToWorkspaceGivenUserObject(this.organization, currentUser, userRole) .then(saveUserDataMono) - .then(userOrganizationService.leaveOrganization(this.organization.getId())); + .then(userOrganizationService.leaveWorkspace(this.organization.getId())); StepVerifier.create(userMono).assertNext(user -> { assertEquals("api_user", user.getEmail()); @@ -174,7 +174,7 @@ class UserOrganizationServiceTest { @Test @WithUserDetails(value = "api_user") void leaveOrganization_WhenUserDoesNotExistInOrg_ThrowsException() { - Mono userMono = userOrganizationService.leaveOrganization(this.organization.getId()); + Mono userMono = userOrganizationService.leaveWorkspace(this.organization.getId()); StepVerifier.create(userMono).expectErrorMessage( AppsmithError.NO_RESOURCE_FOUND.getMessage(FieldName.USER + " api_user in the organization", organization.getName()) ).verify(); @@ -187,7 +187,7 @@ class UserOrganizationServiceTest { User currentUser = userRepository.findByEmail("api_user").block(); UserRole userRole = createUserRole(currentUser.getUsername(), currentUser.getId(), ORGANIZATION_ADMIN); - userOrganizationService.addUserToOrganizationGivenUserObject(organization, currentUser, userRole).block(); + userOrganizationService.addUserToWorkspaceGivenUserObject(organization, currentUser, userRole).block(); // try to remove the user from org UserRole updatedRole = new UserRole(); @@ -210,7 +210,7 @@ class UserOrganizationServiceTest { // add the current user as an admin to the organization User currentUser = userRepository.findByEmail("api_user").block(); UserRole userRole = createUserRole(currentUser.getUsername(), currentUser.getId(), ORGANIZATION_ADMIN); - userOrganizationService.addUserToOrganizationGivenUserObject(organization, currentUser, userRole).block(); + userOrganizationService.addUserToWorkspaceGivenUserObject(organization, currentUser, userRole).block(); // try to remove the user from org UserRole updatedRole = new UserRole(); @@ -337,7 +337,7 @@ class UserOrganizationServiceTest { List users = new ArrayList<>(1); users.add(user); return userOrganizationService - .bulkAddUsersToOrganization(organization, users, ORGANIZATION_DEVELOPER.getName()) + .bulkAddUsersToWorkspace(organization, users, ORGANIZATION_DEVELOPER.getName()) .thenReturn(commentThread); }).flatMap(commentThread -> commentThreadRepository.findById(commentThread.getId()) diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/WorkspaceServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/WorkspaceServiceTest.java index d6c378f122..33e375b025 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/WorkspaceServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/WorkspaceServiceTest.java @@ -626,7 +626,7 @@ public class WorkspaceServiceTest { UserRole userRole = new UserRole(); userRole.setRoleName(AppsmithRole.ORGANIZATION_ADMIN.getName()); userRole.setUsername("usertest@usertest.com"); - return userOrganizationService.addUserRoleToOrganization(organization1.getId(), userRole); + return userOrganizationService.addUserRoleToWorkspace(organization1.getId(), userRole); }) .map(organization1 -> { log.debug("Organization policies after adding user is : {}", organization1.getPolicies()); @@ -724,7 +724,7 @@ public class WorkspaceServiceTest { UserRole userRole = new UserRole(); userRole.setRoleName(AppsmithRole.ORGANIZATION_VIEWER.getName()); userRole.setUsername("usertest@usertest.com"); - return userOrganizationService.addUserRoleToOrganization(organization1.getId(), userRole); + return userOrganizationService.addUserRoleToWorkspace(organization1.getId(), userRole); }); Mono readApplicationByNameMono = applicationService.findByName("User Management Viewer Test Application", @@ -792,7 +792,7 @@ public class WorkspaceServiceTest { UserRole userRole = new UserRole(); userRole.setRoleName(AppsmithRole.ORGANIZATION_ADMIN.getName()); userRole.setUsername("usertest@usertest.com"); - return userOrganizationService.addUserRoleToOrganization(organization1.getId(), userRole); + return userOrganizationService.addUserRoleToWorkspace(organization1.getId(), userRole); }); Mono readApplicationByNameMono = applicationService.findByName("User Management Test Application", @@ -860,7 +860,7 @@ public class WorkspaceServiceTest { UserRole userRole = new UserRole(); userRole.setRoleName(AppsmithRole.ORGANIZATION_ADMIN.getName()); userRole.setUsername("usertest@usertest.com"); - return userOrganizationService.addUserRoleToOrganization(organization1.getId(), userRole); + return userOrganizationService.addUserRoleToWorkspace(organization1.getId(), userRole); }); Mono readApplicationByNameMono = applicationService.findByName("User Management Delete Test Application",