use of org.hisp.dhis.user.sharing.Sharing in project dhis2-core by dhis2.
the class DashboardCascadeSharingTest method testCascadeShareMapError.
/**
* Dashboard is shared to userB.
* <p>
* But userB's access is DEFAULT('--------')
* <p>
* Expected: no objects being updated.
*/
@Test
void testCascadeShareMapError() {
DataElement dataElementB = createDataElement('B');
dataElementB.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
objectManager.save(dataElementB, false);
Map map = createMap("A");
map.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
objectManager.save(map, false);
objectManager.flush();
Sharing sharing = new Sharing();
sharing.setPublicAccess(DEFAULT);
sharing.addUserAccess(new UserAccess(userB, DEFAULT));
Dashboard dashboard = createDashboardWithItem("dashboardA", sharing);
dashboard.getItems().get(0).setMap(map);
objectManager.save(dashboard, false);
CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, new CascadeSharingParameters());
assertEquals(0, report.getUpdateObjects().size());
assertFalse(aclService.canRead(userB, dashboard.getItems().get(0).getMap()));
}
use of org.hisp.dhis.user.sharing.Sharing in project dhis2-core by dhis2.
the class V2_36_24__Add_data_sharing_to_sqlview method updateRow.
private void updateRow(Context context, long sqlviewid, String sharing) throws SQLException, JsonProcessingException {
String updatedSharing = SharingUtils.withAccess(sharing, Sharing::copyMetadataToData);
try (PreparedStatement statement = context.getConnection().prepareStatement("update sqlview set sharing = ?::json where sqlviewid = ?")) {
statement.setLong(2, sqlviewid);
statement.setString(1, updatedSharing);
log.info("Executing sharing migration query: [" + statement + "]");
statement.executeUpdate();
} catch (SQLException e) {
log.error(e.getMessage());
throw e;
}
}
Aggregations