Search in sources :

Example 1 with User

use of io.lumeer.api.model.User in project engine by Lumeer.

the class ProjectFacade method getProjects.

public List<Project> getProjects() {
    User user = authenticatedUser.getCurrentUser();
    Set<String> groups = authenticatedUser.getCurrentUserGroups();
    DatabaseQuery query = DatabaseQuery.createBuilder(user.getEmail()).groups(groups).build();
    return projectDao.getProjects(query).stream().map(this::keepOnlyActualUserRoles).collect(Collectors.toList());
}
Also used : User(io.lumeer.api.model.User) DatabaseQuery(io.lumeer.storage.api.query.DatabaseQuery)

Example 2 with User

use of io.lumeer.api.model.User in project engine by Lumeer.

the class UserFacade method updateUser.

public User updateUser(String organizationId, String userId, User user) {
    checkOrganizationInUser(organizationId, user);
    checkPermissions(organizationId);
    User storedUser = userDao.getUserById(userId);
    return updateStoredUserGroups(organizationId, storedUser, user);
}
Also used : User(io.lumeer.api.model.User)

Example 3 with User

use of io.lumeer.api.model.User in project engine by Lumeer.

the class UserFacade method createUser.

public User createUser(String organizationId, User user) {
    checkOrganizationInUser(organizationId, user);
    checkPermissions(organizationId);
    User storedUser = userDao.getUserByEmail(user.getEmail());
    if (storedUser == null) {
        return userDao.createUser(user);
    }
    return updateStoredUserGroups(organizationId, storedUser, user);
}
Also used : User(io.lumeer.api.model.User)

Example 4 with User

use of io.lumeer.api.model.User in project engine by Lumeer.

the class PermissionsCheckerTest method preparePermissionsChecker.

@Before
public void preparePermissionsChecker() {
    User user = Mockito.mock(User.class);
    Mockito.when(user.getGroups()).thenReturn(Collections.singletonMap("LMR", Collections.singleton(GROUP)));
    UserCache userCache = Mockito.mock(UserCache.class);
    Mockito.when(userCache.getUser(USER)).thenReturn(user);
    AuthenticatedUser authenticatedUser = Mockito.mock(AuthenticatedUser.class);
    Mockito.when(authenticatedUser.getCurrentUsername()).thenReturn(USER);
    Mockito.when(authenticatedUser.getUserEmail()).thenReturn(USER);
    Mockito.when(authenticatedUser.getCurrentUserGroups()).thenReturn(Collections.singleton(GROUP));
    permissionsChecker = new PermissionsChecker(userCache, authenticatedUser);
}
Also used : User(io.lumeer.api.model.User) UserCache(io.lumeer.core.cache.UserCache) Before(org.junit.Before)

Example 5 with User

use of io.lumeer.api.model.User in project engine by Lumeer.

the class MongoUserDaoTest method testCreateUserAnotherOrganization.

@Test
public void testCreateUserAnotherOrganization() {
    User user = prepareUser();
    User stored = mongoUserDao.createUser(user);
    Map<String, Set<String>> groups = new HashMap<>(stored.getGroups());
    groups.put(organization2.getId(), GROUPS);
    user.setGroups(groups);
    mongoUserDao.updateUser(stored.getId(), user);
    User storedUser = mongoUserDao.databaseCollection().find(MongoFilters.idFilter(stored.getId())).first();
    assertThat(storedUser).isNotNull();
    assertThat(storedUser.getEmail()).isEqualTo(user.getEmail());
    assertThat(storedUser.getName()).isEqualTo(user.getName());
    assertThat(storedUser.getGroups()).containsKeys(organization.getId(), organization2.getId());
    assertThat(storedUser.getGroups().get(organization.getId())).containsOnlyElementsOf(GROUPS);
    assertThat(storedUser.getGroups().get(organization2.getId())).containsOnlyElementsOf(GROUPS);
}
Also used : User(io.lumeer.api.model.User) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

User (io.lumeer.api.model.User)50 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)29 Test (org.junit.Test)21 Before (org.junit.Before)18 Organization (io.lumeer.api.model.Organization)17 JsonOrganization (io.lumeer.api.dto.JsonOrganization)13 Project (io.lumeer.api.model.Project)13 JsonPermission (io.lumeer.api.dto.JsonPermission)12 JsonPermissions (io.lumeer.api.dto.JsonPermissions)12 JsonProject (io.lumeer.api.dto.JsonProject)12 JsonCollection (io.lumeer.api.dto.JsonCollection)8 HashSet (java.util.HashSet)7 MorphiaOrganization (io.lumeer.storage.mongodb.model.MorphiaOrganization)5 MorphiaPermissions (io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)5 Set (java.util.Set)5 Response (javax.ws.rs.core.Response)4 MorphiaPermission (io.lumeer.storage.mongodb.model.embedded.MorphiaPermission)3 HashMap (java.util.HashMap)3 LinkType (io.lumeer.api.model.LinkType)2 MorphiaProject (io.lumeer.storage.mongodb.model.MorphiaProject)2