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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations