Search in sources :

Example 1 with UserInvitation

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);
}
Also used : User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) UserInvitation(io.lumeer.api.model.UserInvitation) Test(org.junit.Test)

Example 2 with UserInvitation

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;
}
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

User (io.lumeer.api.model.User)2 UserInvitation (io.lumeer.api.model.UserInvitation)2 Auth0Exception (com.auth0.exception.Auth0Exception)1 DefaultViewConfig (io.lumeer.api.model.DefaultViewConfig)1 DefaultWorkspace (io.lumeer.api.model.DefaultWorkspace)1 Feedback (io.lumeer.api.model.Feedback)1 InitialUserData (io.lumeer.api.model.InitialUserData)1 InvitationType (io.lumeer.api.model.InvitationType)1 Language (io.lumeer.api.model.Language)1 NotificationsSettings (io.lumeer.api.model.NotificationsSettings)1 Organization (io.lumeer.api.model.Organization)1 Permission (io.lumeer.api.model.Permission)1 Perspective (io.lumeer.api.model.Perspective)1 ProductDemo (io.lumeer.api.model.ProductDemo)1 Project (io.lumeer.api.model.Project)1 Role (io.lumeer.api.model.Role)1 RoleType (io.lumeer.api.model.RoleType)1 UserOnboarding (io.lumeer.api.model.UserOnboarding)1 Resource (io.lumeer.api.model.common.Resource)1 RoleUtils (io.lumeer.api.util.RoleUtils)1