use of io.lumeer.api.model.InvitationType in project engine by Lumeer.
the class GroupFacade method addGroupsToWorkspace.
public List<Group> addGroupsToWorkspace(final String organizationId, final String projectId, final List<Group> groups, final InvitationType invitationType) {
permissionsChecker.checkGroupsHandle();
// we need at least project management rights
Project project = checkProjectPermissions(organizationId, projectId);
Organization organization = organizationFacade.getOrganizationById(organizationId);
Set<String> organizationGroupsIds = groupDao.getAllGroups(organizationId).stream().map(Group::getId).collect(Collectors.toSet());
List<Group> validGroups = groups.stream().filter(group -> organizationGroupsIds.contains(group.getId())).collect(Collectors.toList());
// we need to filter only group who can't read organization, otherwise organization permissions will be unnecessarily checked
List<Group> organizationGroups = validGroups.stream().filter(group -> !permissionsChecker.hasRole(organization, RoleType.Read, group)).collect(Collectors.toList());
addGroupsToOrganization(organization, organizationGroups);
addGroupsToProject(organization, project, validGroups, invitationType);
return validGroups;
}
use of io.lumeer.api.model.InvitationType 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