use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class InterpretationServiceTest method testCreateChartAndInterpretationSyncSharing.
// TODO enable
@Test
@Disabled
void testCreateChartAndInterpretationSyncSharing() throws IOException {
UserGroup userGroup = createUserGroup('A', Sets.newHashSet(userA, userB));
userGroupService.addUserGroup(userGroup);
Visualization visualization = createVisualization('A');
manager.save(visualization);
visualization.setPublicAccess(AccessStringHelper.READ_WRITE);
visualization.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, AccessStringHelper.READ));
assertEquals(1, visualization.getUserGroupAccesses().size());
manager.update(visualization);
assertEquals(AccessStringHelper.READ_WRITE, visualization.getPublicAccess());
assertEquals(1, visualization.getUserGroupAccesses().size());
Interpretation interpretation = new Interpretation(visualization, null, "test");
interpretationService.saveInterpretation(interpretation);
interpretationService.updateInterpretation(interpretation);
assertEquals(AccessStringHelper.READ_WRITE, interpretation.getPublicAccess());
assertEquals(interpretation.getUserGroupAccesses().size(), visualization.getUserGroupAccesses().size());
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class DeduplicationServiceMergeIntegrationTest method getUserSharing.
private Sharing getUserSharing(User user, String accessStringHelper) {
UserGroup userGroup = new UserGroup();
userGroup.setName("UserGroupA");
user.getGroups().add(userGroup);
Map<String, org.hisp.dhis.user.sharing.UserAccess> userSharing = new HashMap<>();
userSharing.put(user.getUid(), new org.hisp.dhis.user.sharing.UserAccess(user, AccessStringHelper.DEFAULT));
Map<String, UserGroupAccess> userGroupSharing = new HashMap<>();
userGroupSharing.put(userGroup.getUid(), new UserGroupAccess(userGroup, accessStringHelper));
return Sharing.builder().external(false).publicAccess(AccessStringHelper.DEFAULT).owner("testOwner").userGroups(userGroupSharing).users(userSharing).build();
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class DefaultProgramNotificationService method resolveDhisMessageRecipients.
private Set<User> resolveDhisMessageRecipients(ProgramNotificationTemplate template, @Nullable ProgramInstance programInstance, @Nullable ProgramStageInstance programStageInstance) {
if (programInstance == null && programStageInstance == null) {
throw new IllegalArgumentException("Either of the arguments [programInstance, programStageInstance] must be non-null");
}
Set<User> recipients = Sets.newHashSet();
OrganisationUnit eventOrgUnit = programInstance != null ? programInstance.getOrganisationUnit() : programStageInstance.getOrganisationUnit();
Set<OrganisationUnit> orgUnitInHierarchy = Sets.newHashSet();
ProgramNotificationRecipient recipientType = template.getNotificationRecipient();
if (recipientType == ProgramNotificationRecipient.USER_GROUP) {
recipients = Optional.ofNullable(template).map(ProgramNotificationTemplate::getRecipientUserGroup).map(UserGroup::getMembers).orElse(recipients);
final boolean limitToHierarchy = BooleanUtils.toBoolean(template.getNotifyUsersInHierarchyOnly());
final boolean parentOrgUnitOnly = BooleanUtils.toBoolean(template.getNotifyParentOrganisationUnitOnly());
if (limitToHierarchy) {
orgUnitInHierarchy.add(eventOrgUnit);
orgUnitInHierarchy.addAll(eventOrgUnit.getAncestors());
recipients = recipients.stream().filter(r -> orgUnitInHierarchy.contains(r.getOrganisationUnit())).collect(Collectors.toSet());
return recipients;
} else if (parentOrgUnitOnly) {
Set<User> parents = Sets.newHashSet();
recipients.forEach(r -> parents.addAll(r.getOrganisationUnit().getParent().getUsers()));
return parents;
}
recipients.addAll(template.getRecipientUserGroup().getMembers());
} else if (recipientType == ProgramNotificationRecipient.USERS_AT_ORGANISATION_UNIT) {
recipients.addAll(eventOrgUnit.getUsers());
}
return recipients;
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class DataApprovalServiceCategoryOptionGroupTest method setUpTest.
// -------------------------------------------------------------------------
// Set up/tear down
// -------------------------------------------------------------------------
@Override
public void setUpTest() throws Exception {
userService = _userService;
// ---------------------------------------------------------------------
// Add supporting data
// ---------------------------------------------------------------------
global = createOrganisationUnit("Global");
americas = createOrganisationUnit("Americas", global);
asia = createOrganisationUnit("Asia", global);
brazil = createOrganisationUnit("Brazil", americas);
china = createOrganisationUnit("China", asia);
india = createOrganisationUnit("India", asia);
organisationUnitService.addOrganisationUnit(global);
organisationUnitService.addOrganisationUnit(americas);
organisationUnitService.addOrganisationUnit(asia);
organisationUnitService.addOrganisationUnit(brazil);
organisationUnitService.addOrganisationUnit(china);
organisationUnitService.addOrganisationUnit(india);
userA = createUser('A');
userService.addUser(userA);
dateA = new Date();
superUser = mockUser("SuperUser", global, AUTHORITY_ALL);
superUser.setSuperUserFlag(true);
globalConsultant = mockUser("GlobalConsultant", global, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS, AUTH_APPROVE_LOWER_LEVELS);
globalUser = mockUser("GlobalUser", global, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
globalApproveOnly = mockUser("GlobalApproveOnly", global, AUTH_APPROVE);
globalAcceptOnly = mockUser("GlobalAcceptOnly", global, AUTH_ACCEPT_LOWER_LEVELS);
globalReadAll = mockUser("GlobalReadEverything", global, AUTH_VIEW_UNAPPROVED_DATA);
globalAgencyAUser = mockUser("GlobalAgencyAUser", global, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
globalAgencyBUser = mockUser("GlobalAgencyBUser", global, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
brazilInteragencyUser = mockUser("BrazilInteragencyUser", brazil, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
chinaInteragencyUser = mockUser("ChinaInteragencyUser", china, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
chinaInteragencyApproveOnly = mockUser("ChinaInteragencyApproveOnly", china, AUTH_APPROVE);
chinalInteragencyAcceptOnly = mockUser("ChinalInteragencyAcceptOnly", china, AUTH_ACCEPT_LOWER_LEVELS);
indiaInteragencyUser = mockUser("IndiaInteragencyUser", india, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
brazilAgencyAUser = mockUser("BrazilAgencyAUser", brazil, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
chinaAgencyAUser = mockUser("ChinaAgencyAUser", china, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
chinaAgencyAApproveOnly = mockUser("ChinaAgencyAApproveOnly", china, AUTH_APPROVE);
chinaAgencyAAcceptOnly = mockUser("ChinaAgencyAAcceptOnly", china, AUTH_ACCEPT_LOWER_LEVELS);
chinaAgencyBUser = mockUser("ChinaAgencyBUser", china, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
indiaAgencyAUser = mockUser("IndiaAgencyAUser", india, AUTH_APPROVE, AUTH_ACCEPT_LOWER_LEVELS);
brazilPartner1User = mockUser("BrazilPartner1User", brazil, AUTH_APPROVE);
chinaPartner1User = mockUser("ChinaPartner1User", china, AUTH_APPROVE);
chinaPartner2User = mockUser("ChinaPartner2User", china, AUTH_APPROVE);
indiaPartner1User = mockUser("IndiaPartner1User", india, AUTH_APPROVE);
currentMockUserService = null;
UserGroup globalUsers = getUserGroup("GlobalUsers", userSet(globalUser, globalApproveOnly, globalAcceptOnly, globalConsultant, globalReadAll));
UserGroup globalAgencyAUsers = getUserGroup("GlobalAgencyAUsers", userSet(globalAgencyAUser));
UserGroup globalAgencyBUsers = getUserGroup("GlobalAgencyBUsers", userSet(globalAgencyBUser));
UserGroup brazilInteragencyUsers = getUserGroup("BrazilInteragencyUsers", userSet(brazilInteragencyUser));
UserGroup chinaInteragencyUsers = getUserGroup("ChinaInteragencyUsers", userSet(chinaInteragencyUser, chinaInteragencyApproveOnly, chinalInteragencyAcceptOnly));
UserGroup indiaInteragencyUsers = getUserGroup("IndiaInteragencyUsers", userSet(indiaInteragencyUser));
UserGroup brazilAgencyAUsers = getUserGroup("BrazilAgencyAUsers", userSet(brazilAgencyAUser));
UserGroup chinaAgencyAUsers = getUserGroup("ChinaAgencyAUsers", userSet(chinaAgencyAUser, chinaAgencyAApproveOnly, chinaAgencyAAcceptOnly));
UserGroup chinaAgencyBUsers = getUserGroup("ChinaAgencyBUsers", userSet(chinaAgencyBUser));
UserGroup indiaAgencyAUsers = getUserGroup("IndiaAgencyAUsers", userSet(indiaAgencyAUser));
UserGroup brazilPartner1Users = getUserGroup("BrazilPartner1Users", userSet(brazilPartner1User));
UserGroup chinaPartner1Users = getUserGroup("ChinaPartner1Users", userSet(chinaPartner1User));
UserGroup chinaPartner2Users = getUserGroup("ChinaPartner2Users", userSet(chinaPartner2User));
UserGroup indiaPartner1Users = getUserGroup("IndiaPartner1Users", userSet(indiaPartner1User));
brazilA1 = new CategoryOption("BrazilA1");
chinaA1_1 = new CategoryOption("ChinaA1_1");
chinaA1_2 = new CategoryOption("ChinaA1_2");
chinaA2 = new CategoryOption("ChinaA2");
chinaB2 = new CategoryOption("ChinaB2");
indiaA1 = new CategoryOption("IndiaA1");
brazilA1.setOrganisationUnits(Sets.newHashSet(brazil));
chinaA1_1.setOrganisationUnits(Sets.newHashSet(china));
chinaA1_2.setOrganisationUnits(Sets.newHashSet(china));
chinaA2.setOrganisationUnits(Sets.newHashSet(china));
chinaB2.setOrganisationUnits(Sets.newHashSet(china));
indiaA1.setOrganisationUnits(Sets.newHashSet(india));
categoryService.addCategoryOption(brazilA1);
categoryService.addCategoryOption(chinaA1_1);
categoryService.addCategoryOption(chinaA1_2);
categoryService.addCategoryOption(chinaA2);
categoryService.addCategoryOption(chinaB2);
categoryService.addCategoryOption(indiaA1);
setAccess(brazilA1, globalUsers, globalAgencyAUsers, brazilInteragencyUsers, brazilAgencyAUsers, brazilPartner1Users);
setAccess(chinaA1_1, globalUsers, globalAgencyAUsers, chinaInteragencyUsers, chinaAgencyAUsers, chinaPartner1Users);
setAccess(chinaA1_2, globalUsers, globalAgencyAUsers, chinaInteragencyUsers, chinaAgencyAUsers, chinaPartner1Users);
setAccess(chinaA2, globalUsers, globalAgencyAUsers, chinaInteragencyUsers, chinaAgencyAUsers, chinaPartner2Users);
setAccess(chinaB2, globalUsers, globalAgencyBUsers, chinaInteragencyUsers, chinaAgencyBUsers, chinaPartner2Users);
setAccess(indiaA1, globalUsers, globalAgencyAUsers, indiaInteragencyUsers, indiaAgencyAUsers, indiaPartner1Users);
mechanismCategory = createCategory('A', brazilA1, chinaA1_1, chinaA1_2, chinaA2, chinaB2, indiaA1);
categoryService.addCategory(mechanismCategory);
mechanismCategoryCombo = createCategoryCombo('A', mechanismCategory);
categoryService.addCategoryCombo(mechanismCategoryCombo);
constrainByMechanism(globalAgencyAUser);
constrainByMechanism(globalAgencyBUser);
constrainByMechanism(brazilAgencyAUser);
constrainByMechanism(chinaAgencyAUser);
constrainByMechanism(chinaAgencyAApproveOnly);
constrainByMechanism(chinaAgencyAAcceptOnly);
constrainByMechanism(chinaAgencyBUser);
constrainByMechanism(indiaAgencyAUser);
constrainByMechanism(brazilPartner1User);
constrainByMechanism(chinaPartner1User);
constrainByMechanism(chinaPartner2User);
constrainByMechanism(indiaPartner1User);
userService.updateUser(globalAgencyAUser.getCurrentUser());
userService.updateUser(globalAgencyBUser.getCurrentUser());
userService.updateUser(brazilAgencyAUser.getCurrentUser());
userService.updateUser(chinaAgencyAUser.getCurrentUser());
userService.updateUser(chinaAgencyAApproveOnly.getCurrentUser());
userService.updateUser(chinaAgencyAAcceptOnly.getCurrentUser());
userService.updateUser(chinaAgencyBUser.getCurrentUser());
userService.updateUser(indiaAgencyAUser.getCurrentUser());
userService.updateUser(brazilPartner1User.getCurrentUser());
userService.updateUser(chinaPartner1User.getCurrentUser());
userService.updateUser(chinaPartner2User.getCurrentUser());
userService.updateUser(indiaPartner1User.getCurrentUser());
brazilA1Combo = createCategoryOptionCombo(mechanismCategoryCombo, brazilA1);
chinaA1_1Combo = createCategoryOptionCombo(mechanismCategoryCombo, chinaA1_1);
chinaA1_2Combo = createCategoryOptionCombo(mechanismCategoryCombo, chinaA1_2);
chinaA2Combo = createCategoryOptionCombo(mechanismCategoryCombo, chinaA2);
chinaB2Combo = createCategoryOptionCombo(mechanismCategoryCombo, chinaB2);
indiaA1Combo = createCategoryOptionCombo(mechanismCategoryCombo, indiaA1);
categoryService.addCategoryOptionCombo(brazilA1Combo);
categoryService.addCategoryOptionCombo(chinaA1_1Combo);
categoryService.addCategoryOptionCombo(chinaA1_2Combo);
categoryService.addCategoryOptionCombo(chinaA2Combo);
categoryService.addCategoryOptionCombo(chinaB2Combo);
categoryService.addCategoryOptionCombo(indiaA1Combo);
mechanismCategoryCombo.getOptionCombos().add(brazilA1Combo);
mechanismCategoryCombo.getOptionCombos().add(chinaA1_1Combo);
mechanismCategoryCombo.getOptionCombos().add(chinaA1_2Combo);
mechanismCategoryCombo.getOptionCombos().add(chinaA2Combo);
mechanismCategoryCombo.getOptionCombos().add(chinaB2Combo);
mechanismCategoryCombo.getOptionCombos().add(indiaA1Combo);
categoryService.updateCategoryCombo(mechanismCategoryCombo);
agencyA = createCategoryOptionGroup('A', brazilA1, chinaA1_1, chinaA1_2, chinaA2, indiaA1);
agencyB = createCategoryOptionGroup('B', chinaB2);
partner1 = createCategoryOptionGroup('1', brazilA1, chinaA1_1, chinaA1_2, indiaA1);
partner2 = createCategoryOptionGroup('2', chinaA2, chinaB2);
categoryService.saveCategoryOptionGroup(agencyA);
categoryService.saveCategoryOptionGroup(agencyB);
categoryService.saveCategoryOptionGroup(partner1);
categoryService.saveCategoryOptionGroup(partner2);
setAccess(agencyA, globalUsers, globalAgencyAUsers, brazilInteragencyUsers, chinaInteragencyUsers, indiaInteragencyUsers, brazilAgencyAUsers, chinaAgencyAUsers, indiaAgencyAUsers);
setAccess(agencyB, globalUsers, globalAgencyBUsers, chinaInteragencyUsers, chinaAgencyBUsers);
setAccess(partner1, globalUsers, brazilInteragencyUsers, chinaInteragencyUsers, indiaInteragencyUsers, brazilAgencyAUsers, chinaAgencyAUsers, indiaAgencyAUsers, brazilPartner1Users, chinaPartner1Users, indiaPartner1Users);
setAccess(partner2, globalUsers, chinaInteragencyUsers, chinaAgencyAUsers, chinaPartner2Users);
agencies = new CategoryOptionGroupSet("Agencies");
partners = new CategoryOptionGroupSet("Partners");
categoryService.saveCategoryOptionGroupSet(partners);
categoryService.saveCategoryOptionGroupSet(agencies);
setAccess(agencies, globalUsers, globalAgencyAUsers, globalAgencyBUsers, brazilInteragencyUsers, chinaInteragencyUsers, indiaInteragencyUsers, brazilAgencyAUsers, chinaAgencyAUsers, chinaAgencyBUsers, chinaAgencyBUsers, indiaAgencyAUsers);
setAccess(partners, globalUsers, brazilInteragencyUsers, chinaInteragencyUsers, indiaInteragencyUsers, brazilAgencyAUsers, chinaAgencyAUsers, chinaAgencyBUsers, chinaAgencyBUsers, indiaAgencyAUsers, brazilPartner1Users, chinaPartner1Users, chinaPartner2Users, indiaPartner1Users);
agencies.addCategoryOptionGroup(agencyA);
agencies.addCategoryOptionGroup(agencyB);
partners.addCategoryOptionGroup(partner1);
partners.addCategoryOptionGroup(partner2);
agencyA.getGroupSets().add(agencies);
agencyB.getGroupSets().add(agencies);
partner1.getGroupSets().add(partners);
partner2.getGroupSets().add(partners);
categoryService.updateCategoryOptionGroupSet(partners);
categoryService.updateCategoryOptionGroupSet(agencies);
categoryService.updateCategoryOptionGroup(agencyA);
categoryService.updateCategoryOptionGroup(agencyB);
categoryService.updateCategoryOptionGroup(partner1);
categoryService.updateCategoryOptionGroup(partner2);
globalLevel1 = new DataApprovalLevel("GlobalLevel1", 1, null);
globalAgencyLevel2 = new DataApprovalLevel("GlobalAgencyLevel2", 1, agencies);
countryLevel3 = new DataApprovalLevel("CountryLevel3", 3, null);
agencyLevel4 = new DataApprovalLevel("AgencyLevel4", 3, agencies);
partnerLevel5 = new DataApprovalLevel("PartnerLevel5", 3, partners);
dataApprovalLevelService.addDataApprovalLevel(globalLevel1, 1);
dataApprovalLevelService.addDataApprovalLevel(globalAgencyLevel2, 2);
dataApprovalLevelService.addDataApprovalLevel(countryLevel3, 3);
dataApprovalLevelService.addDataApprovalLevel(agencyLevel4, 4);
dataApprovalLevelService.addDataApprovalLevel(partnerLevel5, 5);
periodType = periodService.reloadPeriodType(PeriodType.getPeriodTypeByName("Monthly"));
periodA = createPeriod("201801");
periodService.addPeriod(periodA);
workflow1 = new DataApprovalWorkflow("workflow1", periodType, newHashSet(globalLevel1, countryLevel3, agencyLevel4, partnerLevel5));
workflow2 = new DataApprovalWorkflow("workflow2", periodType, newHashSet(globalLevel1, globalAgencyLevel2, agencyLevel4, partnerLevel5));
dataApprovalService.addWorkflow(workflow1);
dataApprovalService.addWorkflow(workflow2);
dataSetA = createDataSet('A', periodType, mechanismCategoryCombo);
dataSetB = createDataSet('B', periodType, mechanismCategoryCombo);
dataSetA.assignWorkflow(workflow1);
dataSetB.assignWorkflow(workflow2);
dataSetA.addOrganisationUnit(global);
dataSetA.addOrganisationUnit(americas);
dataSetA.addOrganisationUnit(asia);
dataSetA.addOrganisationUnit(brazil);
dataSetA.addOrganisationUnit(china);
dataSetA.addOrganisationUnit(india);
dataSetB.addOrganisationUnit(global);
dataSetB.addOrganisationUnit(americas);
dataSetB.addOrganisationUnit(asia);
dataSetB.addOrganisationUnit(brazil);
dataSetB.addOrganisationUnit(china);
dataSetB.addOrganisationUnit(india);
dataSetService.addDataSet(dataSetA);
dataSetService.addDataSet(dataSetB);
systemSettingManager.saveSystemSetting(SettingKey.IGNORE_ANALYTICS_APPROVAL_YEAR_THRESHOLD, 0);
systemSettingManager.saveSystemSetting(SettingKey.ACCEPTANCE_REQUIRED_FOR_APPROVAL, true);
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class IdentifiableObjectManagerTest method readUserGroupSharedObjects.
@Test
void readUserGroupSharedObjects() {
User loginUser = createUserAndInjectSecurityContext(false, "F_DATAELEMENT_PUBLIC_ADD", "F_USER_ADD", "F_USERGROUP_PUBLIC_ADD");
User user = createUser('B');
identifiableObjectManager.save(user);
UserGroup userGroup = createUserGroup('A', Sets.newHashSet(loginUser));
identifiableObjectManager.save(userGroup);
user.getGroups().add(userGroup);
loginUser.getGroups().add(userGroup);
identifiableObjectManager.save(loginUser);
identifiableObjectManager.save(user);
identifiableObjectManager.save(createDataElement('A'));
identifiableObjectManager.save(createDataElement('B'));
identifiableObjectManager.save(createDataElement('C'));
identifiableObjectManager.save(createDataElement('D'));
assertEquals(4, identifiableObjectManager.getCount(DataElement.class));
assertEquals(4, identifiableObjectManager.getAll(DataElement.class).size());
List<DataElement> dataElements = new ArrayList<>(identifiableObjectManager.getAll(DataElement.class));
for (DataElement dataElement : dataElements) {
dataElement.getSharing().setOwner(user);
dataElement.getSharing().setPublicAccess(AccessStringHelper.newInstance().build());
dataElement.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, AccessStringHelper.READ));
sessionFactory.getCurrentSession().update(dataElement);
}
identifiableObjectManager.flush();
assertEquals(4, identifiableObjectManager.getCount(DataElement.class));
assertEquals(4, identifiableObjectManager.getAll(DataElement.class).size());
}
Aggregations