Search in sources :

Example 31 with JsonPermission

use of io.lumeer.api.dto.JsonPermission in project engine by Lumeer.

the class ProjectServicePermissionsIT method testGetProjectReadRole.

@Test
public void testGetProjectReadRole() {
    String projectCode = "testGetProjectReadRole_code";
    String projectName = "testGetProjectReadRole";
    createProject(projectCode, projectName);
    projectFacade.updateUserPermissions(projectCode, new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.READ)))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + projectCode).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    JsonOrganization fetchedProject = response.readEntity(JsonOrganization.class);
    assertThat(fetchedProject.getCode()).isEqualTo(projectCode);
    assertThat(fetchedProject.getName()).isEqualTo(projectName);
}
Also used : Response(javax.ws.rs.core.Response) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Test(org.junit.Test)

Example 32 with JsonPermission

use of io.lumeer.api.dto.JsonPermission in project engine by Lumeer.

the class ProjectServicePermissionsIT method testGetProjectsSomeReadRoles.

@Test
public void testGetProjectsSomeReadRoles() {
    String projectCode1 = "ProjectServiceTestProject_code1";
    String projectName1 = "ProjectServiceTestProject1";
    String projectCode2 = "ProjectServiceTestProject_code2";
    String projectName2 = "ProjectServiceTestProject2";
    String projectCode3 = "ProjectServiceTestProject_code3";
    String projectName3 = "ProjectServiceTestProject3";
    String projectCode4 = "ProjectServiceTestProject_code4";
    String projectName4 = "ProjectServiceTestProject4";
    List<String> projectCodes = Arrays.asList(projectCode1, projectCode2, projectCode3, projectCode4);
    List<String> projectNames = Arrays.asList(projectName1, projectName2, projectName3, projectName4);
    for (int i = 0; i < projectCodes.size(); i++) {
        createProject(projectCodes.get(i), projectNames.get(i));
        if (i % 2 == 0) {
            projectFacade.removeUserPermission(projectCodes.get(i), userEmail);
        } else {
            projectFacade.updateUserPermissions(projectCodes.get(i), new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.READ)))));
        }
    }
    Response response = client.target(TARGET_URI).path(PATH_PREFIX).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<Project> projects = response.readEntity(new GenericType<List<Project>>(List.class) {
    });
    assertThat(projects).extracting("code").containsOnly(projectCode2, projectCode4);
    assertThat(projects).extracting("name").containsOnly(projectName2, projectName4);
}
Also used : Response(javax.ws.rs.core.Response) JsonProject(io.lumeer.api.dto.JsonProject) Project(io.lumeer.api.model.Project) List(java.util.List) JsonPermission(io.lumeer.api.dto.JsonPermission) Test(org.junit.Test)

Example 33 with JsonPermission

use of io.lumeer.api.dto.JsonPermission in project engine by Lumeer.

the class ProjectServicePermissionsIT method testUpdateUserPermissionsManageRole.

@Test
public void testUpdateUserPermissionsManageRole() {
    String projectCode = "testGetProjectPermissionsNoRole_code1";
    String projectName = "testGetProjectPermissionsNoRole";
    createProject(projectCode, projectName);
    projectFacade.updateUserPermissions(projectCode, new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.READ, Role.MANAGE)))));
    Permission newPermission = new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.WRITE))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + projectCode + "/permissions/users").request(MediaType.APPLICATION_JSON).buildPut(Entity.json(newPermission)).invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
}
Also used : Response(javax.ws.rs.core.Response) JsonPermission(io.lumeer.api.dto.JsonPermission) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) SimplePermission(io.lumeer.core.model.SimplePermission) Permission(io.lumeer.api.model.Permission) JsonPermission(io.lumeer.api.dto.JsonPermission) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 34 with JsonPermission

use of io.lumeer.api.dto.JsonPermission in project engine by Lumeer.

the class ProjectServicePermissionsIT method testUpdateGroupPermissionsManageRole.

@Test
public void testUpdateGroupPermissionsManageRole() {
    String projectCode = "testGetProjectPermissionsNoRole_code1";
    String projectName = "testGetProjectPermissionsNoRole";
    createProject(projectCode, projectName);
    projectFacade.updateUserPermissions(projectCode, new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.READ, Role.MANAGE)))));
    String group = "testGroup5";
    Permission newPermission = new JsonPermission(group, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.WRITE))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + projectCode + "/permissions/groups").request(MediaType.APPLICATION_JSON).buildPut(Entity.json(newPermission)).invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
}
Also used : Response(javax.ws.rs.core.Response) JsonPermission(io.lumeer.api.dto.JsonPermission) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) SimplePermission(io.lumeer.core.model.SimplePermission) Permission(io.lumeer.api.model.Permission) JsonPermission(io.lumeer.api.dto.JsonPermission) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 35 with JsonPermission

use of io.lumeer.api.dto.JsonPermission in project engine by Lumeer.

the class ProjectServicePermissionsIT method testRemoveGroupPermissionsManageRole.

@Test
public void testRemoveGroupPermissionsManageRole() {
    String projectCode = "testGetProjectPermissionsNoRole_code1";
    String projectName = "testGetProjectPermissionsNoRole";
    createProject(projectCode, projectName);
    projectFacade.updateUserPermissions(projectCode, new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.READ, Role.MANAGE)))));
    String group = "testGroup7";
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + projectCode + "/permissions/groups/" + group).request(MediaType.APPLICATION_JSON).buildDelete().invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
}
Also used : Response(javax.ws.rs.core.Response) JsonPermission(io.lumeer.api.dto.JsonPermission) Test(org.junit.Test)

Aggregations

JsonPermission (io.lumeer.api.dto.JsonPermission)45 Response (javax.ws.rs.core.Response)29 Test (org.junit.Test)29 JsonOrganization (io.lumeer.api.dto.JsonOrganization)27 JsonPermissions (io.lumeer.api.dto.JsonPermissions)24 Organization (io.lumeer.api.model.Organization)22 Before (org.junit.Before)16 JsonProject (io.lumeer.api.dto.JsonProject)14 Project (io.lumeer.api.model.Project)13 User (io.lumeer.api.model.User)12 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)12 SimplePermission (io.lumeer.core.model.SimplePermission)12 HashSet (java.util.HashSet)12 Permission (io.lumeer.api.model.Permission)9 JsonCollection (io.lumeer.api.dto.JsonCollection)8 Permissions (io.lumeer.api.model.Permissions)8 LumeerAssertions.assertPermissions (io.lumeer.test.util.LumeerAssertions.assertPermissions)8 Set (java.util.Set)8 Entity (javax.ws.rs.client.Entity)8 MorphiaPermission (io.lumeer.storage.mongodb.model.embedded.MorphiaPermission)4