Search in sources :

Example 16 with UserGroupAccess

use of org.hisp.dhis.user.sharing.UserGroupAccess 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)

Example 17 with UserGroupAccess

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

the class DefaultAclStoreTest method getAccessibleProgramsReturnsNoneIfNoneIsPublicAndUserHasNoAccess.

@Test
void getAccessibleProgramsReturnsNoneIfNoneIsPublicAndUserHasNoAccess() {
    // a private program
    Program programA = createProgram('A');
    programA.setPublicAccess("--------");
    programA.getSharing().setOwner(owner);
    manager.save(programA, false);
    // a private program readable by a user group of which the user is NOT
    // part of
    Program programB = createProgram('B');
    programB.setPublicAccess("--------");
    programB.getSharing().setOwner(owner);
    UserGroup g = createUserGroup('B', Set.of(owner));
    UserGroupAccess a = new UserGroupAccess();
    a.setUserGroup(g);
    a.setAccess("--r-----");
    programB.getSharing().addUserGroupAccess(a);
    manager.save(programB, false);
    List<Long> programIds = aclStore.getAccessiblePrograms(user.getUid(), Collections.emptyList());
    assertThat(programIds, hasSize(0));
}
Also used : Program(org.hisp.dhis.program.Program) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) Test(org.junit.jupiter.api.Test)

Example 18 with UserGroupAccess

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

the class DashboardCascadeSharingTest method setUpTest.

@Override
public void setUpTest() {
    userService = _userService;
    userGroupA = createUserGroup('A', Collections.EMPTY_SET);
    objectManager.save(userGroupA);
    userA = createUser('A');
    userA.getGroups().add(userGroupA);
    userService.addUser(userA);
    userB = createUser('B');
    userService.addUser(userB);
    sharingReadForUserA = new Sharing(DEFAULT, new UserAccess(userA, READ));
    sharingReadWriteForUserB = new Sharing(DEFAULT, new UserAccess(userB, READ_WRITE));
    sharingReadForUserAB = new Sharing(DEFAULT, new UserAccess(userA, READ), new UserAccess(userB, READ));
    sharingUserGroupA = new Sharing(DEFAULT, new UserGroupAccess(userGroupA, READ));
    programA = createProgram('A');
    programA.setSharing(defaultSharing());
    objectManager.save(programA, false);
    createAndInjectAdminUser();
}
Also used : Sharing(org.hisp.dhis.user.sharing.Sharing) UserAccess(org.hisp.dhis.user.sharing.UserAccess) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess)

Example 19 with UserGroupAccess

use of org.hisp.dhis.user.sharing.UserGroupAccess 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 20 with UserGroupAccess

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

the class DataApprovalStoreIntegrationTest method testApprovalStatusWithUserGroupSharing.

@Test
void testApprovalStatusWithUserGroupSharing() {
    transactionTemplate.execute(status -> {
        categoryOptionA.getSharing().addUserGroupAccess(new UserGroupAccess(userGroupA, "r-r-----"));
        categoryOptionB.getSharing().addUserGroupAccess(new UserGroupAccess(userGroupA, "r-r-----"));
        sharingTest(1);
        return null;
    });
}
Also used : UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

UserGroupAccess (org.hisp.dhis.user.sharing.UserGroupAccess)29 UserGroup (org.hisp.dhis.user.UserGroup)22 Test (org.junit.jupiter.api.Test)21 User (org.hisp.dhis.user.User)14 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)13 UserAccess (org.hisp.dhis.user.sharing.UserAccess)13 DataElement (org.hisp.dhis.dataelement.DataElement)10 Sharing (org.hisp.dhis.user.sharing.Sharing)8 HashMap (java.util.HashMap)3 Schema (org.hisp.dhis.schema.Schema)3 ArrayList (java.util.ArrayList)2 DhisSpringTest (org.hisp.dhis.DhisSpringTest)2 CategoryOption (org.hisp.dhis.category.CategoryOption)2 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)2 SystemDefaultMetadataObject (org.hisp.dhis.common.SystemDefaultMetadataObject)2 ErrorReport (org.hisp.dhis.feedback.ErrorReport)2 Program (org.hisp.dhis.program.Program)2 Date (java.util.Date)1 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)1 Dashboard (org.hisp.dhis.dashboard.Dashboard)1