use of org.hisp.dhis.user.sharing.UserGroupAccess in project dhis2-core by dhis2.
the class ValidationResultStoreTest method setPrivateAccess.
private void setPrivateAccess(BaseIdentifiableObject object, UserGroup... userGroups) {
object.getSharing().setOwner(userZ);
object.getSharing().setPublicAccess(ACCESS_NONE);
for (UserGroup group : userGroups) {
UserGroupAccess userGroupAccess = new UserGroupAccess();
userGroupAccess.setAccess(ACCESS_READ);
userGroupAccess.setUserGroup(group);
object.getSharing().addUserGroupAccess(userGroupAccess);
}
identifiableObjectManager.updateNoAcl(object);
}
use of org.hisp.dhis.user.sharing.UserGroupAccess in project dhis2-core by dhis2.
the class DefaultAclStoreTest method getAccessibleProgramsReturnsNoneIfNoneIsPublicAndUserHasNoAccess.
@Test
void getAccessibleProgramsReturnsNoneIfNoneIsPublicAndUserHasNoAccess() {
// a private program
Program programA = createProgram('A');
programA.setPublicAccess("--------");
programA.getSharing().setOwner(owner);
manager.save(programA, false);
// a private program readable by a user group of which the user is NOT
// part of
Program programB = createProgram('B');
programB.setPublicAccess("--------");
programB.getSharing().setOwner(owner);
UserGroup g = createUserGroup('B', Set.of(owner));
UserGroupAccess a = new UserGroupAccess();
a.setUserGroup(g);
a.setAccess("--r-----");
programB.getSharing().addUserGroupAccess(a);
manager.save(programB, false);
List<Long> programIds = aclStore.getAccessiblePrograms(user.getUid(), Collections.emptyList());
assertThat(programIds, hasSize(0));
}
use of org.hisp.dhis.user.sharing.UserGroupAccess in project dhis2-core by dhis2.
the class DashboardCascadeSharingTest method setUpTest.
@Override
public void setUpTest() {
userService = _userService;
userGroupA = createUserGroup('A', Collections.EMPTY_SET);
objectManager.save(userGroupA);
userA = createUser('A');
userA.getGroups().add(userGroupA);
userService.addUser(userA);
userB = createUser('B');
userService.addUser(userB);
sharingReadForUserA = new Sharing(DEFAULT, new UserAccess(userA, READ));
sharingReadWriteForUserB = new Sharing(DEFAULT, new UserAccess(userB, READ_WRITE));
sharingReadForUserAB = new Sharing(DEFAULT, new UserAccess(userA, READ), new UserAccess(userB, READ));
sharingUserGroupA = new Sharing(DEFAULT, new UserGroupAccess(userGroupA, READ));
programA = createProgram('A');
programA.setSharing(defaultSharing());
objectManager.save(programA, false);
createAndInjectAdminUser();
}
use of org.hisp.dhis.user.sharing.UserGroupAccess in project dhis2-core by dhis2.
the class HibernateIdentifiableObjectStoreTest method testDataRead.
@Test
void testDataRead() {
User user1 = createUser("user1", "DATA_READ");
User user2 = createUser("user2", "DATA_READ");
User user3 = createUser("user3", "DATA_READ");
User user4 = createUser("user4", "DATA_READ");
UserGroup userGroup1 = createUserGroup('A', Sets.newHashSet(user1));
manager.save(userGroup1);
UserGroup userGroup2 = createUserGroup('B', Sets.newHashSet(user1, user4));
manager.save(userGroup2);
user1.getGroups().add(userGroup1);
user1.getGroups().add(userGroup2);
user4.getGroups().add(userGroup2);
Map<String, UserAccess> userSharing = new HashMap<>();
userSharing.put(user1.getUid(), new UserAccess(user1, AccessStringHelper.DEFAULT));
userSharing.put(user2.getUid(), new UserAccess(user2, AccessStringHelper.DATA_READ));
userSharing.put(user3.getUid(), new UserAccess(user3, AccessStringHelper.DEFAULT));
userSharing.put(user4.getUid(), new UserAccess(user4, AccessStringHelper.DEFAULT));
Map<String, UserGroupAccess> userGroupSharing = new HashMap<>();
userGroupSharing.put(userGroup1.getUid(), new UserGroupAccess(userGroup1, AccessStringHelper.DATA_READ_WRITE));
userGroupSharing.put(userGroup2.getUid(), new UserGroupAccess(userGroup2, AccessStringHelper.DEFAULT));
Sharing sharing = Sharing.builder().external(false).publicAccess(AccessStringHelper.DEFAULT).owner("testOwner").userGroups(userGroupSharing).users(userSharing).build();
DataElement dataElement = createDataElement('A');
dataElement.setValueType(ValueType.TEXT);
CategoryOptionCombo defaultCategoryOptionCombo = createCategoryOptionCombo('D');
OrganisationUnit organisationUnitA = createOrganisationUnit('A');
Period period = createPeriod(new Date(), new Date());
period.setPeriodType(PeriodType.getPeriodTypeByName(MonthlyPeriodType.NAME));
manager.save(dataElement);
manager.save(organisationUnitA);
manager.save(period);
manager.save(defaultCategoryOptionCombo);
CategoryOption categoryOption = createCategoryOption('A');
categoryOption.setSharing(sharing);
categoryOption.setCategoryOptionCombos(Sets.newHashSet(defaultCategoryOptionCombo));
manager.save(categoryOption, false);
defaultCategoryOptionCombo.getCategoryOptions().add(categoryOption);
DataValue dataValue = createDataValue(dataElement, period, organisationUnitA, "test", defaultCategoryOptionCombo);
dataValueStore.addDataValue(dataValue);
// User1 can't access but it belongs to UserGroup1 which has access
assertEquals(0, accessManager.canRead(user1, dataValue).size());
// User2 has access to DEA
assertEquals(0, accessManager.canRead(user2, dataValue).size());
// User3 doesn't have access and also doesn't belong to any groups
assertEquals(1, accessManager.canRead(user3, dataValue).size());
// User4 doesn't have access and it belong to UserGroup2 which also
// doesn't have access
assertEquals(1, accessManager.canRead(user4, dataValue).size());
}
use of org.hisp.dhis.user.sharing.UserGroupAccess in project dhis2-core by dhis2.
the class DataApprovalStoreIntegrationTest method testApprovalStatusWithUserGroupSharing.
@Test
void testApprovalStatusWithUserGroupSharing() {
transactionTemplate.execute(status -> {
categoryOptionA.getSharing().addUserGroupAccess(new UserGroupAccess(userGroupA, "r-r-----"));
categoryOptionB.getSharing().addUserGroupAccess(new UserGroupAccess(userGroupA, "r-r-----"));
sharingTest(1);
return null;
});
}
Aggregations