Search in sources :

Example 16 with UserGroup

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());
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 17 with UserGroup

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();
}
Also used : HashMap(java.util.HashMap) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess)

Example 18 with UserGroup

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;
}
Also used : ProgramMessageService(org.hisp.dhis.program.message.ProgramMessageService) NotificationMessageRenderer(org.hisp.dhis.notification.NotificationMessageRenderer) Date(java.util.Date) MessageConversationParams(org.hisp.dhis.message.MessageConversationParams) RequiredArgsConstructor(lombok.RequiredArgsConstructor) BatchResponseStatus(org.hisp.dhis.outboundmessage.BatchResponseStatus) ProgramMessage(org.hisp.dhis.program.message.ProgramMessage) BooleanUtils(org.apache.commons.lang3.BooleanUtils) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TrackedEntityAttributeValue(org.hisp.dhis.trackedentityattributevalue.TrackedEntityAttributeValue) MessageService(org.hisp.dhis.message.MessageService) StringUtils(org.apache.commons.lang3.StringUtils) ProgramMessageRecipients(org.hisp.dhis.program.message.ProgramMessageRecipients) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) Service(org.springframework.stereotype.Service) EventDataValue(org.hisp.dhis.eventdatavalue.EventDataValue) ProgramInstance(org.hisp.dhis.program.ProgramInstance) User(org.hisp.dhis.user.User) Nullable(javax.annotation.Nullable) NotificationTemplateMapper(org.hisp.dhis.program.notification.template.snapshot.NotificationTemplateMapper) MessageType(org.hisp.dhis.message.MessageType) Predicate(java.util.function.Predicate) NonNull(lombok.NonNull) ProgramInstanceStore(org.hisp.dhis.program.ProgramInstanceStore) UserGroup(org.hisp.dhis.user.UserGroup) TrackedEntityInstance(org.hisp.dhis.trackedentity.TrackedEntityInstance) Set(java.util.Set) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Clock(org.hisp.dhis.system.util.Clock) Builder(lombok.Builder) PROGRAM_RULE(org.hisp.dhis.program.notification.NotificationTrigger.PROGRAM_RULE) DeliveryChannel(org.hisp.dhis.common.DeliveryChannel) Data(lombok.Data) Optional(java.util.Optional) ProgramStageInstanceStore(org.hisp.dhis.program.ProgramStageInstanceStore) Collections(java.util.Collections) NotificationMessage(org.hisp.dhis.notification.NotificationMessage) DateUtils(org.hisp.dhis.util.DateUtils) Transactional(org.springframework.transaction.annotation.Transactional) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) Set(java.util.Set) UserGroup(org.hisp.dhis.user.UserGroup)

Example 19 with UserGroup

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);
}
Also used : CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) CategoryOption(org.hisp.dhis.category.CategoryOption) Date(java.util.Date) UserGroup(org.hisp.dhis.user.UserGroup)

Example 20 with UserGroup

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());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) ArrayList(java.util.ArrayList) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

UserGroup (org.hisp.dhis.user.UserGroup)76 User (org.hisp.dhis.user.User)50 Test (org.junit.jupiter.api.Test)32 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)23 UserGroupAccess (org.hisp.dhis.user.sharing.UserGroupAccess)22 DataElement (org.hisp.dhis.dataelement.DataElement)17 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 HashSet (java.util.HashSet)11 List (java.util.List)11 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)10 UserAccess (org.hisp.dhis.user.sharing.UserAccess)10 ClassPathResource (org.springframework.core.io.ClassPathResource)9 Program (org.hisp.dhis.program.Program)6 ArrayList (java.util.ArrayList)5 CategoryOption (org.hisp.dhis.category.CategoryOption)5 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Set (java.util.Set)4 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)4 UserGroupAccess (org.hisp.dhis.user.UserGroupAccess)4