Search in sources :

Example 26 with Sharing

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()));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Sharing(org.hisp.dhis.user.sharing.Sharing) UserAccess(org.hisp.dhis.user.sharing.UserAccess) Dashboard(org.hisp.dhis.dashboard.Dashboard) Map(org.hisp.dhis.mapping.Map) Test(org.junit.jupiter.api.Test)

Example 27 with Sharing

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;
    }
}
Also used : Sharing(org.hisp.dhis.user.sharing.Sharing) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Sharing (org.hisp.dhis.user.sharing.Sharing)27 Test (org.junit.jupiter.api.Test)21 UserAccess (org.hisp.dhis.user.sharing.UserAccess)12 User (org.hisp.dhis.user.User)10 UserGroupAccess (org.hisp.dhis.user.sharing.UserGroupAccess)8 DataElement (org.hisp.dhis.dataelement.DataElement)7 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)6 Dashboard (org.hisp.dhis.dashboard.Dashboard)5 HashMap (java.util.HashMap)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 List (java.util.List)3 UserGroup (org.hisp.dhis.user.UserGroup)3 Date (java.util.Date)2 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)2 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)2 TypeReport (org.hisp.dhis.feedback.TypeReport)2 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)2 Period (org.hisp.dhis.period.Period)2 Program (org.hisp.dhis.program.Program)2 PreparedStatement (java.sql.PreparedStatement)1