use of org.hisp.dhis.user.UserGroup 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.UserGroup in project dhis2-core by dhis2.
the class ConfigurationServiceTest method testConfiguration.
@Test
void testConfiguration() {
User userA = createUser('A');
User userB = createUser('B');
UserGroup group = new UserGroup("UserGroupA");
group.getMembers().add(userA);
group.getMembers().add(userB);
userService.addUser(userA);
userService.addUser(userB);
userGroupService.addUserGroup(group);
OrganisationUnitGroupSet groupSet = createOrganisationUnitGroupSet('A');
idObjectManager.save(groupSet);
Configuration config = configurationService.getConfiguration();
assertNull(config.getFeedbackRecipients());
assertNull(config.getFacilityOrgUnitGroupSet());
config.setFeedbackRecipients(group);
config.setFacilityOrgUnitGroupSet(groupSet);
configurationService.setConfiguration(config);
config = configurationService.getConfiguration();
assertNotNull(config.getFeedbackRecipients());
assertNotNull(config.getFacilityOrgUnitGroupSet());
assertEquals(group, config.getFeedbackRecipients());
assertEquals(groupSet, config.getFacilityOrgUnitGroupSet());
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class DataApprovalAuditServiceTest method setUpTest.
@Override
public void setUpTest() throws Exception {
// ---------------------------------------------------------------------
// Add supporting data
// ---------------------------------------------------------------------
PeriodType periodType = PeriodType.getPeriodTypeByName("Monthly");
periodA = createPeriod(new MonthlyPeriodType(), getDate(2017, 1, 1), getDate(2017, 1, 31));
periodB = createPeriod(new MonthlyPeriodType(), getDate(2018, 1, 1), getDate(2018, 1, 31));
periodService.addPeriod(periodA);
periodService.addPeriod(periodB);
sourceA = createOrganisationUnit('A');
sourceB = createOrganisationUnit('B', sourceA);
organisationUnitService.addOrganisationUnit(sourceA);
organisationUnitService.addOrganisationUnit(sourceB);
superUserService = getMockCurrentUserService("SuperUser", true, sourceA, UserAuthorityGroup.AUTHORITY_ALL);
userAService = getMockCurrentUserService("UserA", false, sourceA);
userBService = getMockCurrentUserService("UserB", false, sourceB);
userCService = getMockCurrentUserService("UserC", false, sourceB);
userDService = getMockCurrentUserService("UserD", false, sourceB);
userZ = createUser('Z');
userService.addUser(userZ);
UserGroup userGroupC = getUserGroup("UserGroupA", Sets.newHashSet(userCService.getCurrentUser()));
UserGroup userGroupD = getUserGroup("UserGroupB", Sets.newHashSet(userDService.getCurrentUser()));
userCService.getCurrentUser().getGroups().add(userGroupC);
userDService.getCurrentUser().getGroups().add(userGroupD);
optionA = new CategoryOption("CategoryOptionA");
optionB = new CategoryOption("CategoryOptionB");
categoryService.addCategoryOption(optionA);
categoryService.addCategoryOption(optionB);
categoryA = createCategory('A', optionA, optionB);
categoryService.addCategory(categoryA);
categoryComboA = createCategoryCombo('A', categoryA);
categoryService.addCategoryCombo(categoryComboA);
optionComboA = createCategoryOptionCombo(categoryComboA, optionA);
optionComboB = createCategoryOptionCombo(categoryComboA, optionB);
optionComboC = createCategoryOptionCombo(categoryComboA, optionA, optionB);
categoryService.addCategoryOptionCombo(optionComboA);
categoryService.addCategoryOptionCombo(optionComboB);
categoryService.addCategoryOptionCombo(optionComboC);
optionGroupA = createCategoryOptionGroup('A', optionA);
optionGroupB = createCategoryOptionGroup('B', optionB);
categoryService.saveCategoryOptionGroup(optionGroupA);
categoryService.saveCategoryOptionGroup(optionGroupB);
optionGroupSetB = new CategoryOptionGroupSet("OptionGroupSetB");
categoryService.saveCategoryOptionGroupSet(optionGroupSetB);
optionGroupSetB.addCategoryOptionGroup(optionGroupA);
optionGroupSetB.addCategoryOptionGroup(optionGroupB);
optionGroupA.getGroupSets().add(optionGroupSetB);
optionGroupB.getGroupSets().add(optionGroupSetB);
setPrivateAccess(optionA, userGroupC);
setPrivateAccess(optionB);
setPrivateAccess(optionGroupA);
setPrivateAccess(optionGroupB, userGroupD);
categoryService.updateCategoryOptionGroupSet(optionGroupSetB);
categoryService.updateCategoryOptionGroup(optionGroupA);
categoryService.updateCategoryOptionGroup(optionGroupB);
userCService.getCurrentUser().getCatDimensionConstraints().add(categoryA);
userDService.getCurrentUser().getCogsDimensionConstraints().add(optionGroupSetB);
dateA = getDate(2017, 1, 1);
dateB = getDate(2018, 1, 1);
level1 = new DataApprovalLevel("01", 1, null);
level2 = new DataApprovalLevel("02", 2, null);
level3 = new DataApprovalLevel("03", 2, optionGroupSetB);
dataApprovalLevelService.addDataApprovalLevel(level1);
dataApprovalLevelService.addDataApprovalLevel(level2);
dataApprovalLevelService.addDataApprovalLevel(level3);
workflowA = new DataApprovalWorkflow("workflowA", periodType, newHashSet(level1));
workflowB = new DataApprovalWorkflow("workflowB", periodType, newHashSet(level1, level2, level3));
dataApprovalService.addWorkflow(workflowA);
dataApprovalService.addWorkflow(workflowB);
DataApproval approvalAA1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboA, false, dateA, userZ);
DataApproval approvalAB1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboB, false, dateA, userZ);
DataApproval approvalAC1 = new DataApproval(level1, workflowA, periodA, sourceA, optionComboC, false, dateA, userZ);
DataApproval approvalBA2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboA, false, dateB, userZ);
DataApproval approvalBB2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboB, false, dateB, userZ);
DataApproval approvalBC2 = new DataApproval(level2, workflowB, periodB, sourceB, optionComboC, false, dateB, userZ);
DataApproval approvalBA3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboA, false, dateB, userZ);
DataApproval approvalBB3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboB, false, dateB, userZ);
DataApproval approvalBC3 = new DataApproval(level3, workflowB, periodB, sourceB, optionComboC, false, dateB, userZ);
auditAA1 = new DataApprovalAudit(approvalAA1, APPROVE);
auditAB1 = new DataApprovalAudit(approvalAB1, UNAPPROVE);
auditAC1 = new DataApprovalAudit(approvalAC1, ACCEPT);
auditBA2 = new DataApprovalAudit(approvalBA2, UNACCEPT);
auditBB2 = new DataApprovalAudit(approvalBB2, APPROVE);
auditBC2 = new DataApprovalAudit(approvalBC2, UNAPPROVE);
auditBA3 = new DataApprovalAudit(approvalBA3, ACCEPT);
auditBB3 = new DataApprovalAudit(approvalBB3, UNACCEPT);
auditBC3 = new DataApprovalAudit(approvalBC3, APPROVE);
dataApprovalAuditStore.save(auditAA1);
dataApprovalAuditStore.save(auditAB1);
dataApprovalAuditStore.save(auditAC1);
dataApprovalAuditStore.save(auditBA2);
dataApprovalAuditStore.save(auditBB2);
dataApprovalAuditStore.save(auditBC2);
dataApprovalAuditStore.save(auditBA3);
dataApprovalAuditStore.save(auditBB3);
dataApprovalAuditStore.save(auditBC3);
}
use of org.hisp.dhis.user.UserGroup 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.UserGroup in project dhis2-core by dhis2.
the class DataApprovalServiceCategoryOptionGroupTest method getUserGroup.
private UserGroup getUserGroup(String userGroupName, Set<User> users) {
UserGroup userGroup = new UserGroup();
userGroup.setAutoFields();
userGroup.setName(userGroupName);
userGroup.setMembers(users);
userGroupService.addUserGroup(userGroup);
for (User user : users) {
user.getGroups().add(userGroup);
userService.updateUser(user);
}
return userGroup;
}
Aggregations