Renamed UserOrganizationServiceCE to UserWorkspaceService
This commit is contained in:
parent
6c5134ca42
commit
50082fcd14
|
|
@ -105,13 +105,13 @@ public class UserControllerCE extends BaseController<UserService, User, String>
|
||||||
|
|
||||||
@PutMapping("/addOrganization/{orgId}")
|
@PutMapping("/addOrganization/{orgId}")
|
||||||
public Mono<ResponseDTO<User>> addUserToOrganization(@PathVariable String orgId) {
|
public Mono<ResponseDTO<User>> addUserToOrganization(@PathVariable String orgId) {
|
||||||
return userOrganizationService.addUserToOrganization(orgId, null)
|
return userOrganizationService.addUserToWorkspace(orgId, null)
|
||||||
.map(user -> new ResponseDTO<>(HttpStatus.OK.value(), user, null));
|
.map(user -> new ResponseDTO<>(HttpStatus.OK.value(), user, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PutMapping("/leaveOrganization/{orgId}")
|
@PutMapping("/leaveOrganization/{orgId}")
|
||||||
public Mono<ResponseDTO<User>> leaveOrganization(@PathVariable String orgId) {
|
public Mono<ResponseDTO<User>> leaveOrganization(@PathVariable String orgId) {
|
||||||
return userOrganizationService.leaveOrganization(orgId)
|
return userOrganizationService.leaveWorkspace(orgId)
|
||||||
.map(user -> new ResponseDTO<>(HttpStatus.OK.value(), user, null));
|
.map(user -> new ResponseDTO<>(HttpStatus.OK.value(), user, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.appsmith.server.services;
|
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 {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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<User> addUserToOrganization(String orgId, User user);
|
|
||||||
|
|
||||||
Mono<Workspace> addUserRoleToOrganization(String orgId, UserRole userRole);
|
|
||||||
|
|
||||||
Mono<Workspace> addUserToOrganizationGivenUserObject(Workspace organization, User user, UserRole userRole);
|
|
||||||
|
|
||||||
Mono<User> leaveOrganization(String orgId);
|
|
||||||
|
|
||||||
Mono<UserRole> updateRoleForMember(String orgId, UserRole userRole, String originHeader);
|
|
||||||
|
|
||||||
Mono<Workspace> bulkAddUsersToOrganization(Workspace organization, List<User> users, String roleName);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -42,7 +42,7 @@ import static com.appsmith.server.acl.AclPermission.MANAGE_ORGANIZATIONS;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class UserOrganizationServiceCEImpl implements UserOrganizationServiceCE {
|
public class UserOrganizationServiceCEImpl implements UserWorkspaceServiceCE {
|
||||||
private final SessionUserService sessionUserService;
|
private final SessionUserService sessionUserService;
|
||||||
private final WorkspaceRepository organizationRepository;
|
private final WorkspaceRepository organizationRepository;
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
|
@ -79,7 +79,7 @@ public class UserOrganizationServiceCEImpl implements UserOrganizationServiceCE
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Mono<User> addUserToOrganization(String orgId, User user) {
|
public Mono<User> addUserToWorkspace(String orgId, User user) {
|
||||||
|
|
||||||
Mono<User> currentUserMono;
|
Mono<User> currentUserMono;
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
|
|
@ -127,7 +127,7 @@ public class UserOrganizationServiceCEImpl implements UserOrganizationServiceCE
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Workspace> addUserRoleToOrganization(String orgId, UserRole userRole) {
|
public Mono<Workspace> addUserRoleToWorkspace(String orgId, UserRole userRole) {
|
||||||
Mono<Workspace> organizationMono = organizationRepository.findById(orgId, MANAGE_ORGANIZATIONS)
|
Mono<Workspace> organizationMono = organizationRepository.findById(orgId, MANAGE_ORGANIZATIONS)
|
||||||
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, orgId)));
|
.switchIfEmpty(Mono.error(new AppsmithException(AppsmithError.NO_RESOURCE_FOUND, FieldName.ORGANIZATION, orgId)));
|
||||||
Mono<User> userMono = userRepository.findByEmail(userRole.getUsername())
|
Mono<User> userMono = userRepository.findByEmail(userRole.getUsername())
|
||||||
|
|
@ -137,12 +137,12 @@ public class UserOrganizationServiceCEImpl implements UserOrganizationServiceCE
|
||||||
.flatMap(tuple -> {
|
.flatMap(tuple -> {
|
||||||
Workspace organization = tuple.getT1();
|
Workspace organization = tuple.getT1();
|
||||||
User user = tuple.getT2();
|
User user = tuple.getT2();
|
||||||
return addUserToOrganizationGivenUserObject(organization, user, userRole);
|
return addUserToWorkspaceGivenUserObject(organization, user, userRole);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Workspace> addUserToOrganizationGivenUserObject(Workspace organization, User user, UserRole userRole) {
|
public Mono<Workspace> addUserToWorkspaceGivenUserObject(Workspace organization, User user, UserRole userRole) {
|
||||||
List<UserRole> userRoles = organization.getUserRoles();
|
List<UserRole> userRoles = organization.getUserRoles();
|
||||||
if (userRoles == null) {
|
if (userRoles == null) {
|
||||||
userRoles = new ArrayList<>();
|
userRoles = new ArrayList<>();
|
||||||
|
|
@ -213,7 +213,7 @@ public class UserOrganizationServiceCEImpl implements UserOrganizationServiceCE
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<User> leaveOrganization(String orgId) {
|
public Mono<User> leaveWorkspace(String orgId) {
|
||||||
Mono<Workspace> organizationMono = organizationRepository.findById(orgId);
|
Mono<Workspace> organizationMono = organizationRepository.findById(orgId);
|
||||||
Mono<User> userMono = sessionUserService.getCurrentUser()
|
Mono<User> userMono = sessionUserService.getCurrentUser()
|
||||||
.flatMap(user1 -> userRepository.findByEmail(user1.getUsername()));
|
.flatMap(user1 -> userRepository.findByEmail(user1.getUsername()));
|
||||||
|
|
@ -336,7 +336,7 @@ public class UserOrganizationServiceCEImpl implements UserOrganizationServiceCE
|
||||||
if (userRole.getRoleName() != null) {
|
if (userRole.getRoleName() != null) {
|
||||||
// If a userRole name has been specified, then it means that the user's role has been modified.
|
// If a userRole name has been specified, then it means that the user's role has been modified.
|
||||||
Mono<Workspace> userAddedToOrganizationMono = userRemovedOrganizationMono
|
Mono<Workspace> userAddedToOrganizationMono = userRemovedOrganizationMono
|
||||||
.flatMap(organization1 -> this.addUserToOrganizationGivenUserObject(organization1, user, userRole));
|
.flatMap(organization1 -> this.addUserToWorkspaceGivenUserObject(organization1, user, userRole));
|
||||||
finalUpdatedOrganizationMono = userAddedToOrganizationMono.flatMap(addedOrganization -> {
|
finalUpdatedOrganizationMono = userAddedToOrganizationMono.flatMap(addedOrganization -> {
|
||||||
|
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
|
|
@ -407,7 +407,7 @@ public class UserOrganizationServiceCEImpl implements UserOrganizationServiceCE
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Workspace> bulkAddUsersToOrganization(Workspace organization, List<User> users, String roleName) {
|
public Mono<Workspace> bulkAddUsersToWorkspace(Workspace organization, List<User> users, String roleName) {
|
||||||
List<UserRole> userRoles = organization.getUserRoles();
|
List<UserRole> userRoles = organization.getUserRoles();
|
||||||
if (userRoles == null) {
|
if (userRoles == null) {
|
||||||
userRoles = new ArrayList<>();
|
userRoles = new ArrayList<>();
|
||||||
|
|
|
||||||
|
|
@ -723,7 +723,7 @@ public class UserServiceCEImpl extends BaseService<UserRepository, User, String>
|
||||||
.flatMap(tuple -> {
|
.flatMap(tuple -> {
|
||||||
List<User> invitedUsers = tuple.getT1();
|
List<User> invitedUsers = tuple.getT1();
|
||||||
Workspace organization = tuple.getT2();
|
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
|
// Add organization id to each invited user
|
||||||
|
|
|
||||||
|
|
@ -194,11 +194,11 @@ public class WorkspaceServiceCEImpl extends BaseService<WorkspaceRepository, Wor
|
||||||
userRole.setUserId(user.getId());
|
userRole.setUserId(user.getId());
|
||||||
userRole.setName(user.getName());
|
userRole.setName(user.getName());
|
||||||
userRole.setRoleName(AppsmithRole.ORGANIZATION_ADMIN.getName());
|
userRole.setRoleName(AppsmithRole.ORGANIZATION_ADMIN.getName());
|
||||||
return userOrganizationService.addUserToOrganizationGivenUserObject(createdOrg, user, userRole);
|
return userOrganizationService.addUserToWorkspaceGivenUserObject(createdOrg, user, userRole);
|
||||||
})
|
})
|
||||||
// Now add the org id to the user object and then return the saved org
|
// Now add the org id to the user object and then return the saved org
|
||||||
.flatMap(savedOrganization -> userOrganizationService
|
.flatMap(savedOrganization -> userOrganizationService
|
||||||
.addUserToOrganization(savedOrganization.getId(), user)
|
.addUserToWorkspace(savedOrganization.getId(), user)
|
||||||
.thenReturn(savedOrganization));
|
.thenReturn(savedOrganization));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ public class ActionCollectionServiceTest {
|
||||||
userRole.setRoleName(AppsmithRole.ORGANIZATION_ADMIN.getName());
|
userRole.setRoleName(AppsmithRole.ORGANIZATION_ADMIN.getName());
|
||||||
userRole.setUsername("usertest@usertest.com");
|
userRole.setUsername("usertest@usertest.com");
|
||||||
|
|
||||||
userOrganizationService.addUserRoleToOrganization(testApp.getOrganizationId(), userRole).block();
|
userOrganizationService.addUserRoleToWorkspace(testApp.getOrganizationId(), userRole).block();
|
||||||
|
|
||||||
assert actionCollection != null;
|
assert actionCollection != null;
|
||||||
Mono<ActionCollection> readActionCollectionMono =
|
Mono<ActionCollection> readActionCollectionMono =
|
||||||
|
|
|
||||||
|
|
@ -635,8 +635,8 @@ public class CommentServiceTest {
|
||||||
userRole.setRole(AppsmithRole.ORGANIZATION_ADMIN);
|
userRole.setRole(AppsmithRole.ORGANIZATION_ADMIN);
|
||||||
|
|
||||||
return userService.create(user)
|
return userService.create(user)
|
||||||
.then(userOrganizationService.addUserRoleToOrganization(application.getOrganizationId(), userRole))
|
.then(userOrganizationService.addUserRoleToWorkspace(application.getOrganizationId(), userRole))
|
||||||
.then(userOrganizationService.leaveOrganization(application.getOrganizationId()))
|
.then(userOrganizationService.leaveWorkspace(application.getOrganizationId()))
|
||||||
.thenReturn(application);
|
.thenReturn(application);
|
||||||
}).flatMap(application -> {
|
}).flatMap(application -> {
|
||||||
String pageId = application.getPublishedPages().get(0).getId();
|
String pageId = application.getPublishedPages().get(0).getId();
|
||||||
|
|
|
||||||
|
|
@ -145,9 +145,9 @@ class UserOrganizationServiceTest {
|
||||||
UserRole userRole = createUserRole(currentUser.getUsername(), currentUser.getId(), ORGANIZATION_DEVELOPER);
|
UserRole userRole = createUserRole(currentUser.getUsername(), currentUser.getId(), ORGANIZATION_DEVELOPER);
|
||||||
|
|
||||||
Mono<User> userMono = userOrganizationService
|
Mono<User> userMono = userOrganizationService
|
||||||
.addUserToOrganizationGivenUserObject(this.organization, currentUser, userRole)
|
.addUserToWorkspaceGivenUserObject(this.organization, currentUser, userRole)
|
||||||
.then(saveUserDataMono)
|
.then(saveUserDataMono)
|
||||||
.then(userOrganizationService.leaveOrganization(this.organization.getId()));
|
.then(userOrganizationService.leaveWorkspace(this.organization.getId()));
|
||||||
|
|
||||||
StepVerifier.create(userMono).assertNext(user -> {
|
StepVerifier.create(userMono).assertNext(user -> {
|
||||||
assertEquals("api_user", user.getEmail());
|
assertEquals("api_user", user.getEmail());
|
||||||
|
|
@ -174,7 +174,7 @@ class UserOrganizationServiceTest {
|
||||||
@Test
|
@Test
|
||||||
@WithUserDetails(value = "api_user")
|
@WithUserDetails(value = "api_user")
|
||||||
void leaveOrganization_WhenUserDoesNotExistInOrg_ThrowsException() {
|
void leaveOrganization_WhenUserDoesNotExistInOrg_ThrowsException() {
|
||||||
Mono<User> userMono = userOrganizationService.leaveOrganization(this.organization.getId());
|
Mono<User> userMono = userOrganizationService.leaveWorkspace(this.organization.getId());
|
||||||
StepVerifier.create(userMono).expectErrorMessage(
|
StepVerifier.create(userMono).expectErrorMessage(
|
||||||
AppsmithError.NO_RESOURCE_FOUND.getMessage(FieldName.USER + " api_user in the organization", organization.getName())
|
AppsmithError.NO_RESOURCE_FOUND.getMessage(FieldName.USER + " api_user in the organization", organization.getName())
|
||||||
).verify();
|
).verify();
|
||||||
|
|
@ -187,7 +187,7 @@ class UserOrganizationServiceTest {
|
||||||
User currentUser = userRepository.findByEmail("api_user").block();
|
User currentUser = userRepository.findByEmail("api_user").block();
|
||||||
UserRole userRole = createUserRole(currentUser.getUsername(), currentUser.getId(), ORGANIZATION_ADMIN);
|
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
|
// try to remove the user from org
|
||||||
UserRole updatedRole = new UserRole();
|
UserRole updatedRole = new UserRole();
|
||||||
|
|
@ -210,7 +210,7 @@ class UserOrganizationServiceTest {
|
||||||
// add the current user as an admin to the organization
|
// add the current user as an admin to the organization
|
||||||
User currentUser = userRepository.findByEmail("api_user").block();
|
User currentUser = userRepository.findByEmail("api_user").block();
|
||||||
UserRole userRole = createUserRole(currentUser.getUsername(), currentUser.getId(), ORGANIZATION_ADMIN);
|
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
|
// try to remove the user from org
|
||||||
UserRole updatedRole = new UserRole();
|
UserRole updatedRole = new UserRole();
|
||||||
|
|
@ -337,7 +337,7 @@ class UserOrganizationServiceTest {
|
||||||
List<User> users = new ArrayList<>(1);
|
List<User> users = new ArrayList<>(1);
|
||||||
users.add(user);
|
users.add(user);
|
||||||
return userOrganizationService
|
return userOrganizationService
|
||||||
.bulkAddUsersToOrganization(organization, users, ORGANIZATION_DEVELOPER.getName())
|
.bulkAddUsersToWorkspace(organization, users, ORGANIZATION_DEVELOPER.getName())
|
||||||
.thenReturn(commentThread);
|
.thenReturn(commentThread);
|
||||||
}).flatMap(commentThread ->
|
}).flatMap(commentThread ->
|
||||||
commentThreadRepository.findById(commentThread.getId())
|
commentThreadRepository.findById(commentThread.getId())
|
||||||
|
|
|
||||||
|
|
@ -626,7 +626,7 @@ public class WorkspaceServiceTest {
|
||||||
UserRole userRole = new UserRole();
|
UserRole userRole = new UserRole();
|
||||||
userRole.setRoleName(AppsmithRole.ORGANIZATION_ADMIN.getName());
|
userRole.setRoleName(AppsmithRole.ORGANIZATION_ADMIN.getName());
|
||||||
userRole.setUsername("usertest@usertest.com");
|
userRole.setUsername("usertest@usertest.com");
|
||||||
return userOrganizationService.addUserRoleToOrganization(organization1.getId(), userRole);
|
return userOrganizationService.addUserRoleToWorkspace(organization1.getId(), userRole);
|
||||||
})
|
})
|
||||||
.map(organization1 -> {
|
.map(organization1 -> {
|
||||||
log.debug("Organization policies after adding user is : {}", organization1.getPolicies());
|
log.debug("Organization policies after adding user is : {}", organization1.getPolicies());
|
||||||
|
|
@ -724,7 +724,7 @@ public class WorkspaceServiceTest {
|
||||||
UserRole userRole = new UserRole();
|
UserRole userRole = new UserRole();
|
||||||
userRole.setRoleName(AppsmithRole.ORGANIZATION_VIEWER.getName());
|
userRole.setRoleName(AppsmithRole.ORGANIZATION_VIEWER.getName());
|
||||||
userRole.setUsername("usertest@usertest.com");
|
userRole.setUsername("usertest@usertest.com");
|
||||||
return userOrganizationService.addUserRoleToOrganization(organization1.getId(), userRole);
|
return userOrganizationService.addUserRoleToWorkspace(organization1.getId(), userRole);
|
||||||
});
|
});
|
||||||
|
|
||||||
Mono<Application> readApplicationByNameMono = applicationService.findByName("User Management Viewer Test Application",
|
Mono<Application> readApplicationByNameMono = applicationService.findByName("User Management Viewer Test Application",
|
||||||
|
|
@ -792,7 +792,7 @@ public class WorkspaceServiceTest {
|
||||||
UserRole userRole = new UserRole();
|
UserRole userRole = new UserRole();
|
||||||
userRole.setRoleName(AppsmithRole.ORGANIZATION_ADMIN.getName());
|
userRole.setRoleName(AppsmithRole.ORGANIZATION_ADMIN.getName());
|
||||||
userRole.setUsername("usertest@usertest.com");
|
userRole.setUsername("usertest@usertest.com");
|
||||||
return userOrganizationService.addUserRoleToOrganization(organization1.getId(), userRole);
|
return userOrganizationService.addUserRoleToWorkspace(organization1.getId(), userRole);
|
||||||
});
|
});
|
||||||
|
|
||||||
Mono<Application> readApplicationByNameMono = applicationService.findByName("User Management Test Application",
|
Mono<Application> readApplicationByNameMono = applicationService.findByName("User Management Test Application",
|
||||||
|
|
@ -860,7 +860,7 @@ public class WorkspaceServiceTest {
|
||||||
UserRole userRole = new UserRole();
|
UserRole userRole = new UserRole();
|
||||||
userRole.setRoleName(AppsmithRole.ORGANIZATION_ADMIN.getName());
|
userRole.setRoleName(AppsmithRole.ORGANIZATION_ADMIN.getName());
|
||||||
userRole.setUsername("usertest@usertest.com");
|
userRole.setUsername("usertest@usertest.com");
|
||||||
return userOrganizationService.addUserRoleToOrganization(organization1.getId(), userRole);
|
return userOrganizationService.addUserRoleToWorkspace(organization1.getId(), userRole);
|
||||||
});
|
});
|
||||||
|
|
||||||
Mono<Application> readApplicationByNameMono = applicationService.findByName("User Management Delete Test Application",
|
Mono<Application> readApplicationByNameMono = applicationService.findByName("User Management Delete Test Application",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user