use of org.hisp.dhis.user.sharing.UserGroupAccess in project dhis2-core by dhis2.
the class DataApprovalServiceCategoryOptionGroupTest method setAccess.
private void setAccess(BaseIdentifiableObject object, UserGroup... userGroups) {
object.getSharing().setPublicAccess(ACCESS_NONE);
// Needed for sharing to work
object.getSharing().setOwner(userA);
object.setUser(userA);
object.getSharing().resetUserGroupAccesses();
object.getSharing().resetUserAccesses();
for (UserGroup group : userGroups) {
object.getSharing().addUserGroupAccess(new UserGroupAccess(group, ACCESS_READ));
}
identifiableObjectManager.updateNoAcl(object);
}
use of org.hisp.dhis.user.sharing.UserGroupAccess 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.sharing.UserGroupAccess 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.sharing.UserGroupAccess 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.sharing.UserGroupAccess 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