Search in sources :

Example 6 with DatabaseQuery

use of io.lumeer.storage.api.query.DatabaseQuery in project engine by Lumeer.

the class OrganizationFacade method getOrganizations.

public List<Organization> getOrganizations() {
    String userEmail = authenticatedUser.getUserEmail();
    DatabaseQuery query = DatabaseQuery.createBuilder(userEmail).build();
    return organizationDao.getOrganizations(query).stream().map(this::keepOnlyActualUserRoles).collect(Collectors.toList());
}
Also used : DatabaseQuery(io.lumeer.storage.api.query.DatabaseQuery)

Example 7 with DatabaseQuery

use of io.lumeer.storage.api.query.DatabaseQuery in project engine by Lumeer.

the class MorphiaProjectDaoTest method testGetProjectsNoReadRole.

@Test
public void testGetProjectsNoReadRole() {
    MorphiaProject project = prepareProject(CODE1);
    Permission userPermission = new MorphiaPermission(USER2, Collections.singleton(Role.CLONE.toString()));
    project.getPermissions().updateUserPermissions(userPermission);
    datastore.save(projectDao.databaseCollection(), project);
    MorphiaProject project2 = prepareProject(CODE2);
    Permission groupPermission = new MorphiaPermission(GROUP2, Collections.singleton(Role.SHARE.toString()));
    project2.getPermissions().updateGroupPermissions(groupPermission);
    datastore.save(projectDao.databaseCollection(), project2);
    DatabaseQuery query = DatabaseQuery.createBuilder(USER2).groups(Collections.singleton(GROUP2)).build();
    List<Project> projects = projectDao.getProjects(query);
    assertThat(projects).isEmpty();
}
Also used : MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Project(io.lumeer.api.model.Project) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) DatabaseQuery(io.lumeer.storage.api.query.DatabaseQuery) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Permission(io.lumeer.api.model.Permission) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) Test(org.junit.Test)

Example 8 with DatabaseQuery

use of io.lumeer.storage.api.query.DatabaseQuery in project engine by Lumeer.

the class MorphiaOrganizationDaoTest method testGetOrganizationsGroupRole.

@Test
public void testGetOrganizationsGroupRole() {
    Organization organization = prepareOrganization(CODE1);
    datastore.save(organization);
    Organization organization2 = prepareOrganization(CODE2);
    datastore.save(organization2);
    DatabaseQuery query = DatabaseQuery.createBuilder(USER2).groups(Collections.singleton(GROUP)).build();
    List<Organization> organizations = organizationDao.getOrganizations(query);
    assertThat(organizations).extracting(Organization::getCode).containsOnly(CODE1, CODE2);
}
Also used : MorphiaOrganization(io.lumeer.storage.mongodb.model.MorphiaOrganization) Organization(io.lumeer.api.model.Organization) DatabaseQuery(io.lumeer.storage.api.query.DatabaseQuery) Test(org.junit.Test)

Aggregations

DatabaseQuery (io.lumeer.storage.api.query.DatabaseQuery)8 Test (org.junit.Test)6 Organization (io.lumeer.api.model.Organization)3 MorphiaOrganization (io.lumeer.storage.mongodb.model.MorphiaOrganization)3 MorphiaProject (io.lumeer.storage.mongodb.model.MorphiaProject)3 Permission (io.lumeer.api.model.Permission)2 Project (io.lumeer.api.model.Project)2 MorphiaPermission (io.lumeer.storage.mongodb.model.embedded.MorphiaPermission)2 User (io.lumeer.api.model.User)1 List (java.util.List)1