Search in sources :

Example 26 with JsonOrganization

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

the class OrganizationServicePermissionsIT method testGetOrganizationsSomeReadRoles.

@Test
public void testGetOrganizationsSomeReadRoles() {
    String name1 = "testGetOrganizationsSomeReadRoles1";
    String name2 = "testGetOrganizationsSomeReadRoles2";
    String code1 = "testGetOrganizationsSomeReadRoles1_code";
    String code2 = "testGetOrganizationsSomeReadRoles2_code";
    String name3 = "testGetOrganizationsSomeReadRoles3";
    String name4 = "testGetOrganizationsSomeReadRoles4";
    String code3 = "testGetOrganizationsSomeReadRoles3_code";
    String code4 = "testGetOrganizationsSomeReadRoles4_code";
    List<String> names = Arrays.asList(name1, name2, name3, name4);
    List<String> codes = Arrays.asList(code1, code2, code3, code4);
    for (int i = 0; i < codes.size(); i++) {
        organizationFacade.createOrganization(new JsonOrganization(codes.get(i), names.get(i), "a", "b", null, null));
        if (i % 2 == 0) {
            organizationFacade.removeUserPermission(codes.get(i), userEmail);
        } else {
            organizationFacade.updateUserPermissions(codes.get(i), new JsonPermission(userEmail, Role.toStringRoles(Collections.singleton(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<Organization> organizations = response.readEntity(new GenericType<List<Organization>>(List.class) {
    });
    assertThat(organizations).extracting("code").containsOnly(code2, code4);
    assertThat(organizations).extracting("name").containsOnly(name2, name4);
}
Also used : Response(javax.ws.rs.core.Response) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) List(java.util.List) JsonPermission(io.lumeer.api.dto.JsonPermission) Test(org.junit.Test)

Example 27 with JsonOrganization

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

the class OrganizationServicePermissionsIT method testGetOrganizationPermissionsManageRole.

@Test
public void testGetOrganizationPermissionsManageRole() {
    String name = "testGetOrganizationPermissionsManageRole";
    String code = "testGetOrganizationPermissionsManageRole_code";
    Organization organization = new JsonOrganization(code, name, "a", "b", null, null);
    organizationFacade.createOrganization(organization);
    organizationFacade.updateUserPermissions(code, new JsonPermission(userEmail, Role.toStringRoles(new HashSet<Role>(Arrays.asList(Role.READ, Role.MANAGE)))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + code + "/permissions").request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
}
Also used : Role(io.lumeer.api.model.Role) Response(javax.ws.rs.core.Response) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Test(org.junit.Test)

Example 28 with JsonOrganization

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

the class OrganizationServicePermissionsIT method testGetOrganizationReadRole.

@Test
public void testGetOrganizationReadRole() {
    String name = "TestGetOrganizationReadRole";
    String code = "TestGetOrganizationReadRole_id";
    Organization organization = new JsonOrganization(code, name, "a", "b", null, null);
    organizationFacade.createOrganization(organization);
    Permission newPermission = new JsonPermission(userEmail, Role.toStringRoles(Collections.singleton(Role.READ)));
    organizationFacade.updateUserPermissions(code, newPermission);
    Set<Permission> perm = organizationDao.getOrganizationByCode(code).getPermissions().getUserPermissions();
    LumeerAssertions.assertPermissions(perm, newPermission);
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + code).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
}
Also used : Response(javax.ws.rs.core.Response) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Permission(io.lumeer.api.model.Permission) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Test(org.junit.Test)

Example 29 with JsonOrganization

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

the class OrganizationServicePermissionsIT method testRemoveUserPermissionManageRole.

@Test
public void testRemoveUserPermissionManageRole() {
    String name = "testRemoveUserPermissionNoRole";
    String code = "testRemoveUserPermissionNoRole_code";
    Organization organization = new JsonOrganization(code, name, "a", "b", null, null);
    organizationFacade.createOrganization(organization);
    organizationFacade.updateUserPermissions(code, new JsonPermission(userEmail, Role.toStringRoles(new HashSet<Role>(Arrays.asList(Role.READ, Role.MANAGE)))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + code + "/permissions/users/" + userEmail).request(MediaType.APPLICATION_JSON).buildDelete().invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
}
Also used : Role(io.lumeer.api.model.Role) Response(javax.ws.rs.core.Response) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Test(org.junit.Test)

Example 30 with JsonOrganization

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

the class OrganizationServicePermissionsIT method testUpdateOrganizationManageRole.

@Test
public void testUpdateOrganizationManageRole() {
    String name = "TestUpdateOrganizationManageRole";
    String code = "TestUpdateOrganizationManageRole_code";
    String newName = "NewTestUpdateOrganizationManageRole";
    Organization organization = new JsonOrganization(code, name, "a", "b", null, null);
    organizationFacade.createOrganization(organization);
    organizationFacade.updateUserPermissions(code, new JsonPermission(userEmail, Role.toStringRoles(new HashSet<Role>(Arrays.asList(Role.READ, Role.MANAGE)))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + code).request(MediaType.APPLICATION_JSON).buildPut(Entity.json(new JsonOrganization(code, newName, "c", "d", null, null))).invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    Organization org = response.readEntity(JsonOrganization.class);
    assertThat(org.getName()).isEqualTo(newName);
    assertThat(org.getCode()).isEqualTo(code);
}
Also used : Role(io.lumeer.api.model.Role) Response(javax.ws.rs.core.Response) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Test(org.junit.Test)

Aggregations

JsonOrganization (io.lumeer.api.dto.JsonOrganization)45 Organization (io.lumeer.api.model.Organization)40 JsonPermission (io.lumeer.api.dto.JsonPermission)28 Test (org.junit.Test)23 Response (javax.ws.rs.core.Response)21 JsonPermissions (io.lumeer.api.dto.JsonPermissions)18 Before (org.junit.Before)16 JsonProject (io.lumeer.api.dto.JsonProject)14 Project (io.lumeer.api.model.Project)13 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)13 User (io.lumeer.api.model.User)12 JsonCollection (io.lumeer.api.dto.JsonCollection)8 Permission (io.lumeer.api.model.Permission)6 Role (io.lumeer.api.model.Role)4 SoftAssertions (org.assertj.core.api.SoftAssertions)4 Entity (javax.ws.rs.client.Entity)3 LinkType (io.lumeer.api.model.LinkType)2 SimplePermission (io.lumeer.core.model.SimplePermission)2 List (java.util.List)2 CompanyContact (io.lumeer.api.model.CompanyContact)1