use of org.hisp.dhis.mapping.Map in project dhis2-core by dhis2.
the class MapController method putJsonObject.
// --------------------------------------------------------------------------
// CRUD
// --------------------------------------------------------------------------
@Override
@PutMapping(value = "/{uid}", consumes = APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseBody
public WebMessage putJsonObject(@PathVariable String uid, @CurrentUser User currentUser, HttpServletRequest request) throws Exception {
Map map = mappingService.getMap(uid);
if (map == null) {
return notFound("Map does not exist: " + uid);
}
MetadataImportParams params = importService.getParamsFromMap(contextService.getParameterValuesMap());
Map newMap = deserializeJsonEntity(request);
newMap.setUid(uid);
mergeService.merge(new MergeParams<>(newMap, map).setMergeMode(params.getMergeMode()).setSkipSharing(params.isSkipSharing()).setSkipTranslation(params.isSkipTranslation()));
mappingService.updateMap(map);
return null;
}
use of org.hisp.dhis.mapping.Map in project dhis2-core by dhis2.
the class CascadeSharingTest method createMap.
protected Map createMap(String name) {
MapView mapView = createMapView("Test");
Map map = new Map();
map.setName("map" + name);
map.setMapViews(Lists.newArrayList(mapView));
map.setAutoFields();
return map;
}
use of org.hisp.dhis.mapping.Map in project dhis2-core by dhis2.
the class DashboardCascadeSharingTest method testCascadeSharePublicAccess.
/**
* Dashboard has publicAccess READ and not shared to any User or UserGroup.
* <p>
* Expected cascade sharing for PublicAccess is not supported, so user can't
* access dashboardItem's objects.
*/
@Test
void testCascadeSharePublicAccess() {
Map map = createMap("A");
map.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
objectManager.save(map, false);
Dashboard dashboard = createDashboardWithItem("dashboardA", Sharing.builder().publicAccess(READ).build());
dashboard.getItems().get(0).setMap(map);
objectManager.save(dashboard, false);
CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, new CascadeSharingParameters());
assertEquals(0, report.getErrorReports().size());
assertFalse(aclService.canRead(userA, dashboard.getItems().get(0).getMap()));
assertFalse(aclService.canRead(userB, dashboard.getItems().get(0).getMap()));
}
use of org.hisp.dhis.mapping.Map in project dhis2-core by dhis2.
the class DashboardCascadeSharingTest method testAtomicFalse.
@Test
void testAtomicFalse() {
Map mapA = createMap("A");
mapA.setSharing(sharingReadWriteForUserB);
objectManager.save(mapA, false);
Map mapB = createMap("A");
mapB.setSharing(defaultSharing());
objectManager.save(mapB, false);
DashboardItem itemB = createDashboardItem("B");
itemB.setMap(mapB);
Dashboard dashboard = createDashboardWithItem("A", sharingReadForUserA);
dashboard.getItems().get(0).setMap(mapA);
dashboard.getItems().add(itemB);
objectManager.save(dashboard, false);
CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, CascadeSharingParameters.builder().atomic(false).user(userB).build());
assertEquals(1, report.getErrorReports().size());
assertEquals(1, report.getUpdateObjects().size());
assertTrue(aclService.canRead(userA, mapA));
assertFalse(aclService.canRead(userA, mapB));
}
use of org.hisp.dhis.mapping.Map in project dhis2-core by dhis2.
the class DashboardCascadeSharingTest method testDryRunFalse.
@Test
void testDryRunFalse() {
Map map = createMap("A");
map.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
objectManager.save(map, false);
Dashboard dashboard = createDashboardWithItem("A", sharingReadForUserA);
dashboard.getItems().get(0).setMap(map);
objectManager.save(dashboard, false);
CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, CascadeSharingParameters.builder().dryRun(false).build());
assertEquals(0, report.getErrorReports().size());
assertEquals(1, report.getUpdateObjects().size());
assertTrue(aclService.canRead(userA, dashboard.getItems().get(0).getMap()));
assertFalse(aclService.canRead(userB, dashboard.getItems().get(0).getMap()));
}
Aggregations