Search in sources :

Example 21 with Sharing

use of org.hisp.dhis.user.sharing.Sharing in project dhis2-core by dhis2.

the class SharingTest method withAccessKeepsExternal.

@Test
void withAccessKeepsExternal() {
    Sharing original = new Sharing();
    original.setExternal(true);
    assertTrue(original.withAccess(Sharing::copyMetadataToData).isExternal());
}
Also used : Sharing(org.hisp.dhis.user.sharing.Sharing) Test(org.junit.jupiter.api.Test)

Example 22 with Sharing

use of org.hisp.dhis.user.sharing.Sharing in project dhis2-core by dhis2.

the class SharingTest method withAccessKeepsOwner.

@Test
void withAccessKeepsOwner() {
    Sharing original = new Sharing();
    original.setOwner("userid");
    assertEquals("userid", original.withAccess(Sharing::copyMetadataToData).getOwner());
}
Also used : Sharing(org.hisp.dhis.user.sharing.Sharing) Test(org.junit.jupiter.api.Test)

Example 23 with Sharing

use of org.hisp.dhis.user.sharing.Sharing in project dhis2-core by dhis2.

the class SharingTest method addUserGroupAccessCreatesMapWhenNeeded.

@Test
void addUserGroupAccessCreatesMapWhenNeeded() {
    Sharing actual = new Sharing();
    actual.addUserGroupAccess(new UserGroupAccess("rw------", "uid"));
    assertEquals(1, actual.getUserGroups().size());
}
Also used : Sharing(org.hisp.dhis.user.sharing.Sharing) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) Test(org.junit.jupiter.api.Test)

Example 24 with Sharing

use of org.hisp.dhis.user.sharing.Sharing in project dhis2-core by dhis2.

the class DashboardCascadeSharingTest method testCascadeShareEventVisualizationError.

@Test
void testCascadeShareEventVisualizationError() {
    DataElement dataElementA = createDataElement('A');
    dataElementA.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
    objectManager.save(dataElementA, false);
    Program program = createProgram('Y', null, null);
    objectManager.save(program);
    EventVisualization eventVisualizationA = createEventVisualization('A', program);
    eventVisualizationA.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
    eventVisualizationA.addDataDimensionItem(dataElementA);
    objectManager.save(eventVisualizationA, false);
    Sharing sharing = new Sharing();
    sharing.setPublicAccess(DEFAULT);
    sharing.addUserAccess(new UserAccess(userB, DEFAULT));
    Dashboard dashboard = createDashboardWithItem("A", sharing);
    dashboard.getItems().get(0).setEventVisualization(eventVisualizationA);
    objectManager.save(dashboard, false);
    CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, new CascadeSharingParameters());
    assertEquals(0, report.getUpdateObjects().size());
    assertFalse(aclService.canRead(userB, eventVisualizationA));
    assertFalse(aclService.canRead(userB, dataElementA));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Program(org.hisp.dhis.program.Program) Sharing(org.hisp.dhis.user.sharing.Sharing) UserAccess(org.hisp.dhis.user.sharing.UserAccess) Dashboard(org.hisp.dhis.dashboard.Dashboard) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Test(org.junit.jupiter.api.Test)

Example 25 with Sharing

use of org.hisp.dhis.user.sharing.Sharing in project dhis2-core by dhis2.

the class DashboardCascadeSharingTest method testCascadeShareVisualizationError.

@Test
void testCascadeShareVisualizationError() {
    DataElement dataElementA = createDataElement('A');
    dataElementA.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
    objectManager.save(dataElementA, false);
    Visualization vzA = createVisualization('A');
    vzA.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
    vzA.addDataDimensionItem(dataElementA);
    objectManager.save(vzA, false);
    Sharing sharing = new Sharing();
    sharing.setPublicAccess(DEFAULT);
    sharing.addUserAccess(new UserAccess(userB, DEFAULT));
    Dashboard dashboard = createDashboardWithItem("A", sharing);
    dashboard.getItems().get(0).setVisualization(vzA);
    objectManager.save(dashboard, false);
    CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, new CascadeSharingParameters());
    assertEquals(0, report.getUpdateObjects().size());
    assertFalse(aclService.canRead(userB, vzA));
    assertFalse(aclService.canRead(userB, dataElementA));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Sharing(org.hisp.dhis.user.sharing.Sharing) UserAccess(org.hisp.dhis.user.sharing.UserAccess) Dashboard(org.hisp.dhis.dashboard.Dashboard) Test(org.junit.jupiter.api.Test)

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