Search in sources :

Example 1 with InvitationType

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;
}
Also used : Permission(io.lumeer.api.model.Permission) RoleUtils(io.lumeer.api.util.RoleUtils) RoleType(io.lumeer.api.model.RoleType) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) Set(java.util.Set) InvitationType(io.lumeer.api.model.InvitationType) Collectors(java.util.stream.Collectors) GroupDao(io.lumeer.storage.api.dao.GroupDao) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Group(io.lumeer.api.model.Group) Project(io.lumeer.api.model.Project) List(java.util.List) Role(io.lumeer.api.model.Role) ResourceType(io.lumeer.api.model.ResourceType) Resource(io.lumeer.api.model.common.Resource) RequestScoped(javax.enterprise.context.RequestScoped) Organization(io.lumeer.api.model.Organization) Project(io.lumeer.api.model.Project) Group(io.lumeer.api.model.Group) Organization(io.lumeer.api.model.Organization)

Example 2 with InvitationType

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;
}
Also used : RoleUtils(io.lumeer.api.util.RoleUtils) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) ZonedDateTime(java.time.ZonedDateTime) User(io.lumeer.api.model.User) UpdateDefaultWorkspace(io.lumeer.engine.api.event.UpdateDefaultWorkspace) InvitationType(io.lumeer.api.model.InvitationType) StringUtils(org.apache.commons.lang3.StringUtils) DefaultViewConfigDao(io.lumeer.storage.api.dao.DefaultViewConfigDao) Resource(io.lumeer.api.model.common.Resource) Map(java.util.Map) UserAuth0Utils(io.lumeer.core.auth.UserAuth0Utils) Permission(io.lumeer.api.model.Permission) RoleType(io.lumeer.api.model.RoleType) DataDocument(io.lumeer.engine.api.data.DataDocument) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) TimeZone(java.util.TimeZone) Auth0Exception(com.auth0.exception.Auth0Exception) Set(java.util.Set) Feedback(io.lumeer.api.model.Feedback) Collectors(java.util.stream.Collectors) UpdateCurrentUser(io.lumeer.engine.api.event.UpdateCurrentUser) UserLoginDao(io.lumeer.storage.api.dao.UserLoginDao) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) CreateOrUpdateUser(io.lumeer.engine.api.event.CreateOrUpdateUser) List(java.util.List) Optional(java.util.Optional) ReloadGroups(io.lumeer.engine.api.event.ReloadGroups) Utils(io.lumeer.core.util.Utils) UserDao(io.lumeer.storage.api.dao.UserDao) HashMap(java.util.HashMap) Perspective(io.lumeer.api.model.Perspective) DefaultViewConfig(io.lumeer.api.model.DefaultViewConfig) GroupDao(io.lumeer.storage.api.dao.GroupDao) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) Language(io.lumeer.api.model.Language) Role(io.lumeer.api.model.Role) FeedbackDao(io.lumeer.storage.api.dao.FeedbackDao) UserInvitation(io.lumeer.api.model.UserInvitation) UserOnboarding(io.lumeer.api.model.UserOnboarding) Organization(io.lumeer.api.model.Organization) Event(javax.enterprise.event.Event) RemoveUser(io.lumeer.engine.api.event.RemoveUser) UserUtil(io.lumeer.api.util.UserUtil) InitialUserData(io.lumeer.api.model.InitialUserData) ProductDemo(io.lumeer.api.model.ProductDemo) DefaultWorkspace(io.lumeer.api.model.DefaultWorkspace) Project(io.lumeer.api.model.Project) UnsuccessfulOperationException(io.lumeer.engine.api.exception.UnsuccessfulOperationException) InitialUserDataDao(io.lumeer.storage.api.dao.InitialUserDataDao) RequestScoped(javax.enterprise.context.RequestScoped) NotificationsSettings(io.lumeer.api.model.NotificationsSettings) Collections(java.util.Collections) BadFormatException(io.lumeer.core.exception.BadFormatException) User(io.lumeer.api.model.User) UpdateCurrentUser(io.lumeer.engine.api.event.UpdateCurrentUser) CreateOrUpdateUser(io.lumeer.engine.api.event.CreateOrUpdateUser) RemoveUser(io.lumeer.engine.api.event.RemoveUser) Organization(io.lumeer.api.model.Organization) InvitationType(io.lumeer.api.model.InvitationType) ArrayList(java.util.ArrayList) UserInvitation(io.lumeer.api.model.UserInvitation)

Aggregations

InvitationType (io.lumeer.api.model.InvitationType)2 Organization (io.lumeer.api.model.Organization)2 Permission (io.lumeer.api.model.Permission)2 Project (io.lumeer.api.model.Project)2 Role (io.lumeer.api.model.Role)2 RoleType (io.lumeer.api.model.RoleType)2 Resource (io.lumeer.api.model.common.Resource)2 RoleUtils (io.lumeer.api.util.RoleUtils)2 GroupDao (io.lumeer.storage.api.dao.GroupDao)2 ProjectDao (io.lumeer.storage.api.dao.ProjectDao)2 ResourceNotFoundException (io.lumeer.storage.api.exception.ResourceNotFoundException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 RequestScoped (javax.enterprise.context.RequestScoped)2 Inject (javax.inject.Inject)2 Auth0Exception (com.auth0.exception.Auth0Exception)1 DefaultViewConfig (io.lumeer.api.model.DefaultViewConfig)1