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));
}
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));
}
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));
}
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);
}
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);
}
Aggregations