Search in sources :

Example 26 with JsonPermission

use of io.lumeer.api.dto.JsonPermission 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 27 with JsonPermission

use of io.lumeer.api.dto.JsonPermission 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 28 with JsonPermission

use of io.lumeer.api.dto.JsonPermission 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)

Example 29 with JsonPermission

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

the class OrganizationServicePermissionsIT method testUpdateGroupPermissionNoRole.

@Test
public void testUpdateGroupPermissionNoRole() {
    String name = "testUpdateGroupPermissionNoRole";
    String code = "testUpdateGroupPermissionNoRole_code";
    Organization organization = new JsonOrganization(code, name, "a", "b", null, null);
    organizationFacade.createOrganization(organization);
    organizationFacade.removeUserPermission(code, userEmail);
    String group = "testGroup1";
    Permission newPermission = new JsonPermission(group, Role.toStringRoles(new HashSet<>(Collections.singletonList(Role.WRITE))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + code + "/permissions/groups").request(MediaType.APPLICATION_JSON).buildPut(Entity.json(newPermission)).invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
}
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 30 with JsonPermission

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

the class ProjectServicePermissionsIT method tesRemoveUserPermissionsManageRole.

@Test
public void tesRemoveUserPermissionsManageRole() {
    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)))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + projectCode + "/permissions/users/" + userEmail).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