Search in sources :

Example 21 with QueryStem

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

the class ViewServiceIT method configureProject.

@Before
public void configureProject() {
    User user = new User(USER);
    this.user = userDao.createUser(user);
    userPermission = Permission.buildWithRoles(this.user.getId(), USER_ROLES);
    Organization organization = new Organization();
    organization.setCode(ORGANIZATION_CODE);
    organization.setPermissions(new Permissions());
    Organization storedOrganization = organizationDao.createOrganization(organization);
    this.organization = storedOrganization;
    Permissions organizationPermissions = new Permissions();
    Permission userPermission = Permission.buildWithRoles(this.user.getId(), Organization.ROLES);
    organizationPermissions.updateUserPermissions(userPermission);
    storedOrganization.setPermissions(organizationPermissions);
    organizationDao.updateOrganization(storedOrganization.getId(), storedOrganization);
    projectDao.setOrganization(storedOrganization);
    groupDao.setOrganization(storedOrganization);
    group = groupDao.createGroup(new Group(GROUP, Collections.singletonList(user.getId())));
    groupPermission = Permission.buildWithRoles(group.getId(), GROUP_ROLES);
    Project project = new Project();
    project.setCode(PROJECT_CODE);
    project.setPermissions(new Permissions());
    Project storedProject = projectDao.createProject(project);
    this.project = storedProject;
    Permissions projectPermissions = new Permissions();
    Permission userProjectPermission = Permission.buildWithRoles(this.user.getId(), Project.ROLES);
    projectPermissions.updateUserPermissions(userProjectPermission);
    storedProject.setPermissions(projectPermissions);
    storedProject = projectDao.updateProject(storedProject.getId(), storedProject);
    workspaceKeeper.setWorkspaceIds(storedOrganization.getId(), storedProject.getId());
    viewDao.setProject(storedProject);
    Collection collection = collectionFacade.createCollection(new Collection("abc", "abc random", ICON, COLOR, projectPermissions));
    collectionFacade.updateUserPermissions(collection.getId(), Set.of(Permission.buildWithRoles(this.user.getId(), Collections.singleton(new Role(RoleType.Read)))));
    query = new Query(new QueryStem(collection.getId()));
    viewsUrl = projectPath(storedOrganization, storedProject) + "views";
    PermissionCheckerUtil.allowGroups();
}
Also used : Role(io.lumeer.api.model.Role) Group(io.lumeer.api.model.Group) Project(io.lumeer.api.model.Project) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) Organization(io.lumeer.api.model.Organization) Query(io.lumeer.api.model.Query) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) Permissions(io.lumeer.api.model.Permissions) Permission(io.lumeer.api.model.Permission) Collection(io.lumeer.api.model.Collection) QueryStem(io.lumeer.api.model.QueryStem) Before(org.junit.Before)

Example 22 with QueryStem

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

the class ViewServiceIT method testGetViewWithAuthorRights.

@Test
@SuppressWarnings("unchecked")
public void testGetViewWithAuthorRights() {
    // non-existing author
    final String USER = "aaaaa4444400000000111112";
    Permission workspacePermission = new Permission(USER, Collections.singleton(new Role(RoleType.Read)));
    organizationFacade.updateUserPermissions(organization.getId(), Set.of(workspacePermission));
    projectFacade.updateUserPermissions(project.getId(), Set.of(workspacePermission));
    Permission permission = new Permission(USER, Collections.singleton(new Role(RoleType.DataWrite)));
    Collection collection = collectionFacade.createCollection(new Collection("cdefg", "abcefg random", ICON, COLOR, new Permissions(new HashSet<>(Collections.singletonList(permission)), Collections.emptySet())));
    collectionFacade.updateUserPermissions(collection.getId(), Set.of(Permission.buildWithRoles(USER, Set.of(new Role(RoleType.DataWrite)))));
    View view = prepareView(CODE + "3");
    view.setQuery(new Query(new QueryStem(collection.getId())));
    view.getPermissions().updateUserPermissions(userPermission);
    view.getPermissions().updateGroupPermissions(groupPermission);
    view.setAuthorId(USER);
    view.getPermissions().updateUserPermissions(permission);
    viewDao.createView(view);
    Response response = client.target(viewsUrl).path(view.getId()).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    View returnedView = response.readEntity(View.class);
    SoftAssertions assertions = new SoftAssertions();
    assertions.assertThat(returnedView.getAuthorCollectionsRights()).containsOnly(new HashMap.SimpleEntry<>(collection.getId(), Set.of(RoleType.DataWrite)));
    assertions.assertAll();
}
Also used : Query(io.lumeer.api.model.Query) HashMap(java.util.HashMap) SoftAssertions(org.assertj.core.api.SoftAssertions) View(io.lumeer.api.model.View) QueryStem(io.lumeer.api.model.QueryStem) Role(io.lumeer.api.model.Role) Response(javax.ws.rs.core.Response) Permission(io.lumeer.api.model.Permission) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) Permissions(io.lumeer.api.model.Permissions) Collection(io.lumeer.api.model.Collection) Test(org.junit.Test)

Aggregations

Query (io.lumeer.api.model.Query)22 QueryStem (io.lumeer.api.model.QueryStem)22 Test (org.junit.Test)14 Collection (io.lumeer.api.model.Collection)8 Document (io.lumeer.api.model.Document)8 Role (io.lumeer.api.model.Role)8 DataDocument (io.lumeer.engine.api.data.DataDocument)8 Permission (io.lumeer.api.model.Permission)7 Permissions (io.lumeer.api.model.Permissions)7 Project (io.lumeer.api.model.Project)6 View (io.lumeer.api.model.View)6 ArrayList (java.util.ArrayList)6 CollectionAttributeFilter (io.lumeer.api.model.CollectionAttributeFilter)5 LinkInstance (io.lumeer.api.model.LinkInstance)5 LinkType (io.lumeer.api.model.LinkType)5 Organization (io.lumeer.api.model.Organization)5 User (io.lumeer.api.model.User)5 AuthenticatedUser (io.lumeer.core.auth.AuthenticatedUser)5 Before (org.junit.Before)5 LumeerAssertions.assertPermissions (io.lumeer.test.util.LumeerAssertions.assertPermissions)4