use of io.lumeer.api.model.UserInvitation in project engine by Lumeer.
the class UserFacadeIT method testCreateUsersToWorkspace.
@Test
public void testCreateUsersToWorkspace() {
List<UserInvitation> users = Arrays.asList(new UserInvitation(USER1, InvitationType.JOIN_ONLY), new UserInvitation(USER2, InvitationType.JOIN_ONLY));
userFacade.createUsersInWorkspace(organizationId1, project.getId(), users);
Arrays.asList(USER1, USER2).forEach(user -> {
User stored = getUser(organizationId1, user);
assertThat(stored).isNotNull();
assertThat(stored.getEmail()).isEqualTo(user);
assertThat(stored.getOrganizations()).containsOnly(organizationId1);
});
var organization = organizationDao.getOrganizationById(organizationId1);
assertThat(organization.getPermissions().getUserPermissions().size()).isEqualTo(3);
var project = projectDao.getProjectById(this.project.getId());
assertThat(project.getPermissions().getUserPermissions().size()).isEqualTo(3);
}
use of io.lumeer.api.model.UserInvitation in project engine by Lumeer.
the class UserFacade method createUsersInWorkspace.
public List<User> createUsersInWorkspace(final String organizationId, final String projectId, final List<UserInvitation> invitations) {
// we need at least project management rights
checkProjectPermissions(organizationId, projectId, RoleType.UserConfig);
// check if the users are already in the organization
final List<User> usersInOrganization = getUsers(organizationId);
final List<String> orgUserEmails = usersInOrganization.stream().map(User::getEmail).collect(Collectors.toList());
final List<UserInvitation> validInvitations = invitations.stream().filter(inv -> !inv.getEmail().isEmpty()).collect(Collectors.toList());
final List<String> usersInRequest = validInvitations.stream().map(UserInvitation::getEmail).collect(Collectors.toList());
final Map<String, InvitationType> invitationTypeMap = validInvitations.stream().collect(Collectors.toMap(UserInvitation::getEmail, UserInvitation::getInvitationType));
final List<User> newUsers;
final Organization organization;
var userEmailsToAdd = new ArrayList<>(usersInRequest);
userEmailsToAdd.removeAll(orgUserEmails);
// we need to add new users in the organization
if (userEmailsToAdd.size() > 0) {
organization = checkOrganizationPermissions(organizationId, RoleType.UserConfig);
checkUsersCreate(organizationId, userEmailsToAdd.size());
newUsers = createUsersByInvitationsInOrganization(organizationId, projectId, validInvitations);
} else {
// we will just amend the rights at the project level
organization = organizationFacade.getOrganizationById(organizationId);
newUsers = usersInOrganization.stream().filter(user -> usersInRequest.contains(user.getEmail())).collect(Collectors.toList());
}
// we need to filter only users who can't read organization, otherwise organization permissions will be unnecessarily checked
var organizationUsers = newUsers.stream().filter(user -> !permissionsChecker.hasRole(organization, RoleType.Read, user.getId())).collect(Collectors.toList());
addUsersToOrganization(organization, organizationUsers);
addUsersToProject(organization, projectId, newUsers, invitationTypeMap);
logUsersInvitation(newUsers, organization);
return newUsers;
}
Aggregations