Search in sources :

Example 51 with UserGroup

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());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) User(org.hisp.dhis.user.User) UserAccess(org.hisp.dhis.user.sharing.UserAccess) HashMap(java.util.HashMap) DataValue(org.hisp.dhis.datavalue.DataValue) Period(org.hisp.dhis.period.Period) Date(java.util.Date) UserGroup(org.hisp.dhis.user.UserGroup) DataElement(org.hisp.dhis.dataelement.DataElement) Sharing(org.hisp.dhis.user.sharing.Sharing) CategoryOption(org.hisp.dhis.category.CategoryOption) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 52 with UserGroup

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());
}
Also used : User(org.hisp.dhis.user.User) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) UserGroup(org.hisp.dhis.user.UserGroup) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 53 with UserGroup

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

Example 54 with UserGroup

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

Example 55 with UserGroup

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;
}
Also used : User(org.hisp.dhis.user.User) UserGroup(org.hisp.dhis.user.UserGroup)

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