Search in sources :

Example 31 with Permissions

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

the class ProjectServiceIT method testUpdateUserPermissions.

@Test
public void testUpdateUserPermissions() {
    createProject(CODE1);
    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 = projectDao.getProjectByCode(CODE1).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 32 with Permissions

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

the class ViewServiceIT method testGetViewPermissions.

@Test
public void testGetViewPermissions() {
    createView(CODE);
    Response response = client.target(PERMISSIONS_URL).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    Permissions permissions = response.readEntity(JsonPermissions.class);
    assertPermissions(permissions.getUserPermissions(), USER_PERMISSION);
    assertPermissions(permissions.getGroupPermissions(), GROUP_PERMISSION);
}
Also used : Response(javax.ws.rs.core.Response) 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) Test(org.junit.Test)

Example 33 with Permissions

use of io.lumeer.api.model.Permissions 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 34 with Permissions

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

the class ProjectFacadeIT method testGetProjectPermissions.

@Test
public void testGetProjectPermissions() {
    createProject(CODE1);
    createProjectWithReadOnlyPermissions(CODE2);
    createProjectWithStrangerPermissions(CODE3);
    Permissions permissions = projectFacade.getProjectPermissions(CODE1);
    assertThat(permissions).isNotNull();
    assertPermissions(permissions.getUserPermissions(), USER_PERMISSION);
    assertPermissions(permissions.getGroupPermissions(), GROUP_PERMISSION);
    permissions = projectFacade.getProjectPermissions(CODE2);
    assertThat(permissions).isNotNull();
    assertPermissions(permissions.getUserPermissions(), USER_READONLY_PERMISSION);
    permissions = projectFacade.getProjectPermissions(CODE3);
    assertThat(permissions).isNotNull();
    assertThat(permissions.getUserPermissions()).hasSize(2).contains(USER_PERMISSION, STRANGER_PERMISSION);
}
Also used : LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) MorphiaPermissions(io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions) Permissions(io.lumeer.api.model.Permissions) Test(org.junit.Test)

Example 35 with Permissions

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

the class ViewFacadeIT method testUpdateGroupPermissions.

@Test
public void testUpdateGroupPermissions() {
    createView(CODE);
    SimplePermission groupPermission = new SimplePermission(GROUP, new HashSet<>(Arrays.asList(Role.SHARE, Role.READ)));
    viewFacade.updateGroupPermissions(CODE, groupPermission);
    Permissions permissions = viewDao.getViewByCode(CODE).getPermissions();
    assertThat(permissions).isNotNull();
    assertPermissions(permissions.getUserPermissions(), USER_PERMISSION);
    assertPermissions(permissions.getGroupPermissions(), groupPermission);
}
Also used : LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) MorphiaPermissions(io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions) Permissions(io.lumeer.api.model.Permissions) SimplePermission(io.lumeer.core.model.SimplePermission) Test(org.junit.Test)

Aggregations

Permissions (io.lumeer.api.model.Permissions)45 LumeerAssertions.assertPermissions (io.lumeer.test.util.LumeerAssertions.assertPermissions)44 Test (org.junit.Test)44 JsonPermissions (io.lumeer.api.dto.JsonPermissions)29 Response (javax.ws.rs.core.Response)24 MorphiaPermissions (io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)22 SimplePermission (io.lumeer.core.model.SimplePermission)20 JsonPermission (io.lumeer.api.dto.JsonPermission)12 HashSet (java.util.HashSet)12 Set (java.util.Set)12 Entity (javax.ws.rs.client.Entity)12 Permission (io.lumeer.api.model.Permission)5 Resource (io.lumeer.api.model.Resource)5 Organization (io.lumeer.api.model.Organization)4 Role (io.lumeer.api.model.Role)4 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)4 OrganizationDao (io.lumeer.storage.api.dao.OrganizationDao)4 ResourceNotFoundException (io.lumeer.storage.api.exception.ResourceNotFoundException)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4