Search in sources :

Example 16 with Sharing

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

the class SharingTest method setDtoUserAccessesClearsExisting.

@Test
void setDtoUserAccessesClearsExisting() {
    Sharing actual = new Sharing();
    User user1 = new User();
    user1.setUid("id");
    actual.setDtoUserAccesses(singleton(new org.hisp.dhis.user.UserAccess(user1, "rw------")));
    User user2 = new User();
    user2.setUid("uid");
    actual.setDtoUserAccesses(singleton(new org.hisp.dhis.user.UserAccess(user2, "r-------")));
    assertEquals(1, actual.getUsers().size());
    UserAccess userAccess = actual.getUsers().values().iterator().next();
    assertEquals("r-------", userAccess.getAccess());
    assertEquals("uid", userAccess.getId());
}
Also used : User(org.hisp.dhis.user.User) Sharing(org.hisp.dhis.user.sharing.Sharing) UserAccess(org.hisp.dhis.user.sharing.UserAccess) Test(org.junit.jupiter.api.Test)

Example 17 with Sharing

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

the class SharingTest method addUserAccessIgnoresNull.

@Test
void addUserAccessIgnoresNull() {
    Sharing actual = new Sharing();
    actual.setUserAccesses(singleton(new UserAccess("rw------", "uid")));
    actual.addUserAccess(null);
    assertEquals(1, actual.getUsers().size());
}
Also used : Sharing(org.hisp.dhis.user.sharing.Sharing) UserAccess(org.hisp.dhis.user.sharing.UserAccess) Test(org.junit.jupiter.api.Test)

Example 18 with Sharing

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

the class SharingTest method withAccessAppliesToPublic.

@Test
void withAccessAppliesToPublic() {
    Sharing original = new Sharing();
    original.setPublicAccess("abcd1234");
    assertEquals("abab1234", original.withAccess(Sharing::copyMetadataToData).getPublicAccess());
}
Also used : Sharing(org.hisp.dhis.user.sharing.Sharing) Test(org.junit.jupiter.api.Test)

Example 19 with Sharing

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

the class SharingTest method setUserAccessesClearsExisting.

@Test
void setUserAccessesClearsExisting() {
    Sharing actual = new Sharing();
    actual.setUserAccesses(singleton(new UserAccess("rw------", "id")));
    actual.setUserAccesses(singleton(new UserAccess("r-------", "uid")));
    assertEquals(1, actual.getUsers().size());
    UserAccess userAccess = actual.getUsers().values().iterator().next();
    assertEquals("r-------", userAccess.getAccess());
    assertEquals("uid", userAccess.getId());
}
Also used : Sharing(org.hisp.dhis.user.sharing.Sharing) UserAccess(org.hisp.dhis.user.sharing.UserAccess) Test(org.junit.jupiter.api.Test)

Example 20 with Sharing

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

the class SharingTest method withAccessAppliesToUserGroups.

@Test
void withAccessAppliesToUserGroups() {
    Sharing original = new Sharing();
    original.setUserGroups(singletonMap("key", new UserGroupAccess("abcd1234", "uid")));
    Sharing actual = original.withAccess(Sharing::copyMetadataToData);
    Map<String, UserGroupAccess> groups = actual.getUserGroups();
    assertEquals(1, groups.size());
    assertEquals("key", groups.keySet().iterator().next());
    assertEquals("abab1234", groups.values().iterator().next().getAccess());
    assertEquals("uid", groups.values().iterator().next().getId());
}
Also used : Sharing(org.hisp.dhis.user.sharing.Sharing) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) 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