Search in sources :

Example 21 with JsonPermission

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

the class UserServiceIT method configure.

@Before
public void configure() {
    JsonOrganization organization1 = new JsonOrganization();
    organization1.setCode("LMR");
    organization1.setPermissions(new JsonPermissions());
    organization1.getPermissions().updateUserPermissions(new JsonPermission(USER, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.WRITE, Role.READ, Role.MANAGE)))));
    organizationId1 = organizationDao.createOrganization(organization1).getId();
    JsonOrganization organization2 = new JsonOrganization();
    organization2.setCode("MRL");
    organization2.setPermissions(new JsonPermissions());
    organization2.getPermissions().updateUserPermissions(new JsonPermission(USER, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.WRITE, Role.READ, Role.MANAGE)))));
    organizationId2 = organizationDao.createOrganization(organization2).getId();
}
Also used : JsonPermissions(io.lumeer.api.dto.JsonPermissions) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Before(org.junit.Before)

Example 22 with JsonPermission

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

the class ViewServiceIT method testUpdateUserPermissions.

@Test
public void testUpdateUserPermissions() {
    createView(CODE);
    SimplePermission userPermission = new SimplePermission(USER, new HashSet<>(Arrays.asList(Role.MANAGE, Role.READ)));
    Entity entity = Entity.json(userPermission);
    Response response = client.target(PERMISSIONS_URL).path("users").request(MediaType.APPLICATION_JSON).buildPut(entity).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    Set<JsonPermission> returnedPermissions = response.readEntity(new GenericType<Set<JsonPermission>>() {
    });
    assertThat(returnedPermissions).isNotNull().hasSize(1);
    assertPermissions(Collections.unmodifiableSet(returnedPermissions), userPermission);
    Permissions storedPermissions = viewDao.getViewByCode(CODE).getPermissions();
    assertThat(storedPermissions).isNotNull();
    assertPermissions(storedPermissions.getUserPermissions(), userPermission);
    assertPermissions(storedPermissions.getGroupPermissions(), GROUP_PERMISSION);
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) HashSet(java.util.HashSet) Set(java.util.Set) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) MorphiaPermissions(io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions) Permissions(io.lumeer.api.model.Permissions) JsonPermission(io.lumeer.api.dto.JsonPermission) SimplePermission(io.lumeer.core.model.SimplePermission) Test(org.junit.Test)

Example 23 with JsonPermission

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

the class OrganizationServicePermissionsIT method testUpdateGroupPermissionManageRole.

@Test
public void testUpdateGroupPermissionManageRole() {
    String name = "testUpdateGroupPermissionNoRole";
    String code = "testUpdateGroupPermissionNoRole_code";
    Organization organization = new JsonOrganization(code, name, "a", "b", null, null);
    organizationFacade.createOrganization(organization);
    organizationFacade.updateUserPermissions(code, new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.READ, Role.MANAGE)))));
    String group = "testGroup2";
    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.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 24 with JsonPermission

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

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

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