Search in sources :

Example 56 with UserGroup

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

the class PatchServiceTest method testEmbeddedObjectEquality.

@Test
void testEmbeddedObjectEquality() {
    User adminUser = createAndInjectAdminUser();
    UserGroup userGroup = createUserGroup('A', Sets.newHashSet(adminUser));
    manager.save(userGroup);
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    deA.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, "rw------"));
    deA.getSharing().addUserAccess(new UserAccess(adminUser, "rw------"));
    deB.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, "rw------"));
    deB.getSharing().addUserAccess(new UserAccess(adminUser, "rw------"));
    patchService.diff(new PatchParams(deA, deB));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) UserAccess(org.hisp.dhis.user.sharing.UserAccess) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 57 with UserGroup

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

the class PatchServiceTest method testEmbeddedObjectCollectionDiff.

@Test
void testEmbeddedObjectCollectionDiff() {
    User adminUser = createAndInjectAdminUser();
    UserGroup userGroup = createUserGroup('A', Sets.newHashSet(adminUser));
    manager.save(userGroup);
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    deA.getAggregationLevels().add(1);
    deB.getAggregationLevels().add(1);
    deB.getAggregationLevels().add(2);
    deB.getAggregationLevels().add(3);
    deB.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, "rw------"));
    deB.getSharing().addUserAccess(new UserAccess(adminUser, "rw------"));
    Patch patch = patchService.diff(new PatchParams(deA, deB));
    patchService.apply(patch, deA);
    assertEquals(deA.getName(), deB.getName());
    assertEquals(deA.getShortName(), deB.getShortName());
    assertEquals(deA.getDescription(), deB.getDescription());
    assertEquals(deA.getAggregationLevels(), deB.getAggregationLevels());
    assertEquals(deA.getUserGroupAccesses(), deB.getUserGroupAccesses());
    assertEquals(deA.getUserAccesses(), deB.getUserAccesses());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) UserAccess(org.hisp.dhis.user.sharing.UserAccess) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 58 with UserGroup

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

the class JpaQueryUtilsTest method testGenerateSQlQueryForSharingCheck.

@Test
void testGenerateSQlQueryForSharingCheck() {
    UserGroup groupA = new UserGroup();
    groupA.setUid("aUserGroupA");
    UserGroup groupB = new UserGroup();
    groupB.setUid("aUserGroupB");
    User userA = new User();
    userA.setUid("randomUserA");
    userA.setGroups(Sets.newLinkedHashSet(Lists.newArrayList(groupA, groupB)));
    String expected = " ( x.sharing->>'owner' is null or x.sharing->>'owner' = 'randomUserA')  " + "or x.sharing->>'public' like '__r_____' or x.sharing->>'public' is null  " + "or (jsonb_has_user_id( x.sharing, 'randomUserA') = true  " + "and jsonb_check_user_access( x.sharing, 'randomUserA', '__r_____' ) = true )   " + "or ( jsonb_has_user_group_ids( x.sharing, '{aUserGroupA,aUserGroupB}') = true  " + "and jsonb_check_user_groups_access( x.sharing, '__r_____', '{aUserGroupA,aUserGroupB}') = true )";
    String actual = JpaQueryUtils.generateSQlQueryForSharingCheck("x.sharing", userA, "__r_____");
    Assertions.assertEquals(expected, actual);
}
Also used : User(org.hisp.dhis.user.User) UserGroup(org.hisp.dhis.user.UserGroup) Test(org.junit.jupiter.api.Test)

Example 59 with UserGroup

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

the class AclServiceTest method testReadPrivateDataElementSharedThroughGroup.

@Test
void testReadPrivateDataElementSharedThroughGroup() {
    User user1 = createUser("user111", "F_DATAELEMENT_PRIVATE_ADD");
    User user2 = createUser("user222", "F_DATAELEMENT_PRIVATE_ADD");
    manager.save(user1);
    manager.save(user2);
    UserGroup userGroup = createUserGroup('A', Sets.newHashSet(user1, user2));
    manager.save(userGroup);
    user1.getGroups().add(userGroup);
    user2.getGroups().add(userGroup);
    DataElement dataElement = createDataElement('A');
    dataElement.setPublicAccess(AccessStringHelper.DEFAULT);
    dataElement.setCreatedBy(user1);
    dataElement.getSharing().setOwner(user1);
    UserGroupAccess userGroupAccess = new UserGroupAccess(userGroup, AccessStringHelper.READ);
    dataElement.getSharing().addUserGroupAccess(userGroupAccess);
    manager.save(dataElement, false);
    assertTrue(aclService.canWrite(user1, dataElement));
    assertTrue(aclService.canUpdate(user1, dataElement));
    assertTrue(aclService.canRead(user1, dataElement));
    assertFalse(aclService.canDelete(user1, dataElement));
    assertTrue(aclService.canManage(user1, dataElement));
    Access access = aclService.getAccess(dataElement, user2);
    assertTrue(access.isRead());
    assertFalse(access.isWrite());
    assertFalse(access.isUpdate());
    assertFalse(access.isDelete());
    assertFalse(access.isManage());
    assertTrue(aclService.canRead(user2, dataElement));
    assertFalse(aclService.canWrite(user2, dataElement));
    assertFalse(aclService.canUpdate(user2, dataElement));
    assertFalse(aclService.canDelete(user2, dataElement));
    assertFalse(aclService.canManage(user2, dataElement));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) UserAccess(org.hisp.dhis.user.sharing.UserAccess) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 60 with UserGroup

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

the class AclServiceTest method testSuperuserOverride.

@Test
void testSuperuserOverride() {
    User user1 = createUser("user11A", "F_DATAELEMENT_PRIVATE_ADD");
    User user2 = createUser("user22A", "F_DATAELEMENT_PRIVATE_ADD");
    User user3 = createUser("user33A", "ALL");
    UserGroup userGroup = createUserGroup('A', Sets.newHashSet(user1, user2));
    manager.save(userGroup);
    user1.getGroups().add(userGroup);
    user2.getGroups().add(userGroup);
    DataElement dataElement = createDataElement('A');
    dataElement.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
    dataElement.setCreatedBy(user1);
    dataElement.getSharing().setOwner(user1);
    UserGroupAccess userGroupAccess = new UserGroupAccess(userGroup, AccessStringHelper.READ_WRITE);
    dataElement.getSharing().addUserGroupAccess(userGroupAccess);
    manager.save(dataElement, false);
    assertTrue(aclService.canRead(user1, dataElement));
    assertTrue(aclService.canUpdate(user1, dataElement));
    assertFalse(aclService.canDelete(user1, dataElement));
    assertTrue(aclService.canManage(user1, dataElement));
    assertTrue(aclService.canDataOrMetadataRead(user1, dataElement));
    Access access = aclService.getAccess(dataElement, user2);
    assertTrue(access.isRead());
    assertTrue(access.isWrite());
    assertTrue(access.isUpdate());
    assertFalse(access.isDelete());
    assertTrue(access.isManage());
    assertTrue(aclService.canRead(user2, dataElement));
    assertTrue(aclService.canWrite(user2, dataElement));
    assertTrue(aclService.canUpdate(user2, dataElement));
    assertFalse(aclService.canDelete(user2, dataElement));
    assertTrue(aclService.canManage(user2, dataElement));
    access = aclService.getAccess(dataElement, user3);
    assertTrue(access.isRead());
    assertTrue(access.isWrite());
    assertTrue(access.isUpdate());
    assertTrue(access.isDelete());
    assertTrue(access.isManage());
    assertTrue(aclService.canRead(user3, dataElement));
    assertTrue(aclService.canWrite(user3, dataElement));
    assertTrue(aclService.canUpdate(user3, dataElement));
    assertTrue(aclService.canDelete(user3, dataElement));
    assertTrue(aclService.canManage(user3, dataElement));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) UserAccess(org.hisp.dhis.user.sharing.UserAccess) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

UserGroup (org.hisp.dhis.user.UserGroup)76 User (org.hisp.dhis.user.User)50 Test (org.junit.jupiter.api.Test)32 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)23 UserGroupAccess (org.hisp.dhis.user.sharing.UserGroupAccess)22 DataElement (org.hisp.dhis.dataelement.DataElement)17 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 HashSet (java.util.HashSet)11 List (java.util.List)11 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)10 UserAccess (org.hisp.dhis.user.sharing.UserAccess)10 ClassPathResource (org.springframework.core.io.ClassPathResource)9 Program (org.hisp.dhis.program.Program)6 ArrayList (java.util.ArrayList)5 CategoryOption (org.hisp.dhis.category.CategoryOption)5 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Set (java.util.Set)4 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)4 UserGroupAccess (org.hisp.dhis.user.UserGroupAccess)4