Search in sources :

Example 6 with SimplePermission

use of io.lumeer.core.model.SimplePermission in project engine by Lumeer.

the class OrganizationServiceIT method testUpdateUserPermissions.

@Test
public void testUpdateUserPermissions() {
    createOrganizationWithSpecificPermissions(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 = organizationDao.getOrganizationByCode(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) Permissions(io.lumeer.api.model.Permissions) JsonPermission(io.lumeer.api.dto.JsonPermission) SimplePermission(io.lumeer.core.model.SimplePermission) Test(org.junit.Test)

Example 7 with SimplePermission

use of io.lumeer.core.model.SimplePermission in project engine by Lumeer.

the class ViewServiceIT method testUpdateGroupPermissions.

@Test
public void testUpdateGroupPermissions() {
    createView(CODE);
    SimplePermission groupPermission = new SimplePermission(GROUP, new HashSet<>(Arrays.asList(Role.SHARE, Role.READ)));
    Entity entity = Entity.json(groupPermission);
    Response response = client.target(PERMISSIONS_URL).path("groups").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), groupPermission);
    Permissions storedPermissions = viewDao.getViewByCode(CODE).getPermissions();
    assertThat(storedPermissions).isNotNull();
    assertPermissions(storedPermissions.getUserPermissions(), USER_PERMISSION);
    assertPermissions(storedPermissions.getGroupPermissions(), groupPermission);
}
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 8 with SimplePermission

use of io.lumeer.core.model.SimplePermission in project engine by Lumeer.

the class CollectionServiceIT method testUpdateUserPermissions.

@Test
public void testUpdateUserPermissions() {
    String collectionId = createCollection(CODE).getId();
    SimplePermission userPermission = new SimplePermission(USER, new HashSet<>(Arrays.asList(Role.MANAGE, Role.READ)));
    Entity entity = Entity.json(userPermission);
    Response response = client.target(COLLECTIONS_URL).path(collectionId).path("permissions").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 = collectionDao.getCollectionByCode(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) Permissions(io.lumeer.api.model.Permissions) JsonPermission(io.lumeer.api.dto.JsonPermission) SimplePermission(io.lumeer.core.model.SimplePermission) Test(org.junit.Test)

Example 9 with SimplePermission

use of io.lumeer.core.model.SimplePermission in project engine by Lumeer.

the class CollectionServiceIT method testUpdateGroupPermissions.

@Test
public void testUpdateGroupPermissions() {
    String collectionId = createCollection(CODE).getId();
    SimplePermission groupPermission = new SimplePermission(GROUP, new HashSet<>(Arrays.asList(Role.SHARE, Role.READ)));
    Entity entity = Entity.json(groupPermission);
    Response response = client.target(COLLECTIONS_URL).path(collectionId).path("permissions").path("groups").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), groupPermission);
    Permissions storedPermissions = collectionDao.getCollectionByCode(CODE).getPermissions();
    assertThat(storedPermissions).isNotNull();
    assertPermissions(storedPermissions.getUserPermissions(), USER_PERMISSION);
    assertPermissions(storedPermissions.getGroupPermissions(), groupPermission);
}
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) Permissions(io.lumeer.api.model.Permissions) JsonPermission(io.lumeer.api.dto.JsonPermission) SimplePermission(io.lumeer.core.model.SimplePermission) Test(org.junit.Test)

Example 10 with SimplePermission

use of io.lumeer.core.model.SimplePermission in project engine by Lumeer.

the class AbstractFacade method keepOnlyActualUserRoles.

protected <T extends Resource> T keepOnlyActualUserRoles(final T resource) {
    Set<Role> roles = permissionsChecker.getActualRoles(resource);
    Permission permission = new SimplePermission(authenticatedUser.getUserEmail(), roles);
    resource.getPermissions().clear();
    resource.getPermissions().updateUserPermissions(permission);
    return resource;
}
Also used : Role(io.lumeer.api.model.Role) Permission(io.lumeer.api.model.Permission) SimplePermission(io.lumeer.core.model.SimplePermission) SimplePermission(io.lumeer.core.model.SimplePermission)

Aggregations

SimplePermission (io.lumeer.core.model.SimplePermission)24 Permissions (io.lumeer.api.model.Permissions)16 LumeerAssertions.assertPermissions (io.lumeer.test.util.LumeerAssertions.assertPermissions)16 Test (org.junit.Test)16 JsonPermissions (io.lumeer.api.dto.JsonPermissions)10 JsonPermission (io.lumeer.api.dto.JsonPermission)8 MorphiaPermissions (io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)8 HashSet (java.util.HashSet)8 Set (java.util.Set)8 Entity (javax.ws.rs.client.Entity)8 Response (javax.ws.rs.core.Response)8 Permission (io.lumeer.api.model.Permission)5 Project (io.lumeer.api.model.Project)3 JsonProject (io.lumeer.api.dto.JsonProject)2 Organization (io.lumeer.api.model.Organization)2 JsonOrganization (io.lumeer.api.dto.JsonOrganization)1 Role (io.lumeer.api.model.Role)1