Search in sources :

Example 26 with UserGroup

use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.

the class AclServiceTest method testDataElementSharingPrivateRW.

@Test
void testDataElementSharingPrivateRW() {
    User user1 = createUser("user1A9", "F_DATAELEMENT_PRIVATE_ADD");
    User user2 = createUser("user2A9", "F_DATAELEMENT_PRIVATE_ADD");
    DataElement dataElement = createDataElement('A');
    dataElement.setCreatedBy(user1);
    dataElement.getSharing().setOwner(user1);
    manager.save(dataElement);
    assertFalse(aclService.canUpdate(user2, dataElement));
    assertEquals(AccessStringHelper.DEFAULT, dataElement.getPublicAccess());
    UserGroup userGroup = createUserGroup('A', new HashSet<>());
    userGroup.getMembers().add(user1);
    userGroup.getMembers().add(user2);
    manager.save(userGroup);
    user1.getGroups().add(userGroup);
    user2.getGroups().add(userGroup);
    dataElement.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, "rw------"));
    manager.update(dataElement);
    assertTrue(aclService.canUpdate(user2, dataElement));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 27 with UserGroup

use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.

the class AclServiceTest method testCategoryOptionSharingPrivateRW.

@Test
void testCategoryOptionSharingPrivateRW() {
    User user1 = createUser("user11", "F_CATEGORY_OPTION_PRIVATE_ADD");
    User user2 = createUser("user22", "F_CATEGORY_OPTION_PRIVATE_ADD");
    CategoryOption categoryOption = createCategoryOption('A');
    categoryOption.setCreatedBy(user1);
    categoryOption.getSharing().setOwner(user1);
    manager.save(categoryOption);
    assertFalse(aclService.canUpdate(user2, categoryOption));
    assertEquals(AccessStringHelper.DEFAULT, categoryOption.getPublicAccess());
    UserGroup userGroup = createUserGroup('A', new HashSet<>());
    userGroup.getMembers().add(user1);
    userGroup.getMembers().add(user2);
    manager.save(userGroup);
    user2.getGroups().add(userGroup);
    user1.getGroups().add(userGroup);
    categoryOption.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, "rw------"));
    manager.update(categoryOption);
    assertTrue(aclService.canUpdate(user2, categoryOption));
}
Also used : User(org.hisp.dhis.user.User) CategoryOption(org.hisp.dhis.category.CategoryOption) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 28 with UserGroup

use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.

the class AclServiceTest method testUpdatePrivateDataElementSharedThroughGroup.

@Test
void testUpdatePrivateDataElementSharedThroughGroup() {
    User user1 = createUser("user1A", "F_DATAELEMENT_PRIVATE_ADD");
    User user2 = createUser("user2A", "F_DATAELEMENT_PRIVATE_ADD");
    manager.save(user1);
    manager.save(user2);
    UserGroup userGroup = createUserGroup('A', Sets.newHashSet(user1, user2));
    manager.save(userGroup);
    user1.getGroups().add(userGroup);
    user2.getGroups().add(userGroup);
    DataElement dataElement = createDataElement('A');
    dataElement.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
    dataElement.setCreatedBy(user1);
    dataElement.getSharing().setOwner(user1);
    UserGroupAccess userGroupAccess = new UserGroupAccess(userGroup, AccessStringHelper.READ_WRITE);
    dataElement.getSharing().addUserGroupAccess(userGroupAccess);
    manager.save(dataElement, false);
    assertTrue(aclService.canRead(user1, dataElement));
    assertTrue(aclService.canUpdate(user1, dataElement));
    assertFalse(aclService.canDelete(user1, dataElement));
    assertTrue(aclService.canManage(user1, dataElement));
    Access access = aclService.getAccess(dataElement, user2);
    assertTrue(access.isRead());
    assertTrue(access.isWrite());
    assertTrue(access.isUpdate());
    assertFalse(access.isDelete());
    assertTrue(access.isManage());
    assertTrue(aclService.canRead(user2, dataElement));
    assertTrue(aclService.canWrite(user2, dataElement));
    assertTrue(aclService.canUpdate(user2, dataElement));
    assertFalse(aclService.canDelete(user2, dataElement));
    assertTrue(aclService.canManage(user2, dataElement));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) UserAccess(org.hisp.dhis.user.sharing.UserAccess) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 29 with UserGroup

use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.

the class ValidationResultStoreTest 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(2017, 2, 1), getDate(2017, 2, 28));
    periodService.addPeriod(periodA);
    periodService.addPeriod(periodB);
    sourceA = createOrganisationUnit('A');
    sourceB = createOrganisationUnit('B', sourceA);
    sourceC = createOrganisationUnit('C');
    organisationUnitService.addOrganisationUnit(sourceA);
    organisationUnitService.addOrganisationUnit(sourceB);
    organisationUnitService.addOrganisationUnit(sourceC);
    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 = createUserGroup('A', Sets.newHashSet(userCService.getCurrentUser()));
    UserGroup userGroupD = createUserGroup('B', Sets.newHashSet(userDService.getCurrentUser()));
    userGroupService.addUserGroup(userGroupC);
    userGroupService.addUserGroup(userGroupD);
    userCService.getCurrentUser().getGroups().add(userGroupC);
    userService.updateUser(userCService.getCurrentUser());
    userDService.getCurrentUser().getGroups().add(userGroupD);
    userService.updateUser(userDService.getCurrentUser());
    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);
    expressionA = new Expression("expressionA", "descriptionA");
    expressionB = new Expression("expressionB", "descriptionB");
    validationRuleA = createValidationRule('A', equal_to, expressionA, expressionB, periodType);
    validationRuleB = createValidationRule('B', equal_to, expressionB, expressionA, periodType);
    validationRuleStore.save(validationRuleA);
    validationRuleStore.save(validationRuleB);
    validationResultAA = new ValidationResult(validationRuleA, periodA, sourceA, optionComboA, 1.0, 2.0, 3);
    validationResultAB = new ValidationResult(validationRuleA, periodA, sourceA, optionComboB, 1.0, 2.0, 3);
    validationResultAC = new ValidationResult(validationRuleA, periodA, sourceA, optionComboC, 1.0, 2.0, 3);
    validationResultBA = new ValidationResult(validationRuleB, periodB, sourceB, optionComboA, 1.0, 2.0, 3);
    validationResultBB = new ValidationResult(validationRuleB, periodB, sourceB, optionComboB, 1.0, 2.0, 3);
    validationResultBC = new ValidationResult(validationRuleB, periodB, sourceB, optionComboC, 1.0, 2.0, 3);
    validationResultCA = new ValidationResult(validationRuleB, periodB, sourceC, optionComboA, 1.0, 2.0, 3);
    validationResultAB.setNotificationSent(true);
}
Also used : MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) PeriodType(org.hisp.dhis.period.PeriodType) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) Expression(org.hisp.dhis.expression.Expression) CategoryOptionGroupSet(org.hisp.dhis.category.CategoryOptionGroupSet) CategoryOption(org.hisp.dhis.category.CategoryOption) UserGroup(org.hisp.dhis.user.UserGroup)

Example 30 with UserGroup

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

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