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));
}
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());
}
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);
}
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));
}
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));
}
Aggregations