Search in sources :

Example 21 with UserGroupAccess

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

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

the class PatchServiceTest method testEmbeddedObjectEquality.

@Test
void testEmbeddedObjectEquality() {
    User adminUser = createAndInjectAdminUser();
    UserGroup userGroup = createUserGroup('A', Sets.newHashSet(adminUser));
    manager.save(userGroup);
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    deA.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, "rw------"));
    deA.getSharing().addUserAccess(new UserAccess(adminUser, "rw------"));
    deB.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, "rw------"));
    deB.getSharing().addUserAccess(new UserAccess(adminUser, "rw------"));
    patchService.diff(new PatchParams(deA, deB));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) UserAccess(org.hisp.dhis.user.sharing.UserAccess) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 23 with UserGroupAccess

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

the class PatchServiceTest method testEmbeddedObjectCollectionDiff.

@Test
void testEmbeddedObjectCollectionDiff() {
    User adminUser = createAndInjectAdminUser();
    UserGroup userGroup = createUserGroup('A', Sets.newHashSet(adminUser));
    manager.save(userGroup);
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    deA.getAggregationLevels().add(1);
    deB.getAggregationLevels().add(1);
    deB.getAggregationLevels().add(2);
    deB.getAggregationLevels().add(3);
    deB.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, "rw------"));
    deB.getSharing().addUserAccess(new UserAccess(adminUser, "rw------"));
    Patch patch = patchService.diff(new PatchParams(deA, deB));
    patchService.apply(patch, deA);
    assertEquals(deA.getName(), deB.getName());
    assertEquals(deA.getShortName(), deB.getShortName());
    assertEquals(deA.getDescription(), deB.getDescription());
    assertEquals(deA.getAggregationLevels(), deB.getAggregationLevels());
    assertEquals(deA.getUserGroupAccesses(), deB.getUserGroupAccesses());
    assertEquals(deA.getUserAccesses(), deB.getUserAccesses());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) UserAccess(org.hisp.dhis.user.sharing.UserAccess) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 24 with UserGroupAccess

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

the class AclServiceTest method testReadPrivateDataElementSharedThroughGroup.

@Test
void testReadPrivateDataElementSharedThroughGroup() {
    User user1 = createUser("user111", "F_DATAELEMENT_PRIVATE_ADD");
    User user2 = createUser("user222", "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.setPublicAccess(AccessStringHelper.DEFAULT);
    dataElement.setCreatedBy(user1);
    dataElement.getSharing().setOwner(user1);
    UserGroupAccess userGroupAccess = new UserGroupAccess(userGroup, AccessStringHelper.READ);
    dataElement.getSharing().addUserGroupAccess(userGroupAccess);
    manager.save(dataElement, false);
    assertTrue(aclService.canWrite(user1, dataElement));
    assertTrue(aclService.canUpdate(user1, dataElement));
    assertTrue(aclService.canRead(user1, dataElement));
    assertFalse(aclService.canDelete(user1, dataElement));
    assertTrue(aclService.canManage(user1, dataElement));
    Access access = aclService.getAccess(dataElement, user2);
    assertTrue(access.isRead());
    assertFalse(access.isWrite());
    assertFalse(access.isUpdate());
    assertFalse(access.isDelete());
    assertFalse(access.isManage());
    assertTrue(aclService.canRead(user2, dataElement));
    assertFalse(aclService.canWrite(user2, dataElement));
    assertFalse(aclService.canUpdate(user2, dataElement));
    assertFalse(aclService.canDelete(user2, dataElement));
    assertFalse(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 25 with UserGroupAccess

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

the class AclServiceTest method testSuperuserOverride.

@Test
void testSuperuserOverride() {
    User user1 = createUser("user11A", "F_DATAELEMENT_PRIVATE_ADD");
    User user2 = createUser("user22A", "F_DATAELEMENT_PRIVATE_ADD");
    User user3 = createUser("user33A", "ALL");
    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));
    assertTrue(aclService.canDataOrMetadataRead(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));
    access = aclService.getAccess(dataElement, user3);
    assertTrue(access.isRead());
    assertTrue(access.isWrite());
    assertTrue(access.isUpdate());
    assertTrue(access.isDelete());
    assertTrue(access.isManage());
    assertTrue(aclService.canRead(user3, dataElement));
    assertTrue(aclService.canWrite(user3, dataElement));
    assertTrue(aclService.canUpdate(user3, dataElement));
    assertTrue(aclService.canDelete(user3, dataElement));
    assertTrue(aclService.canManage(user3, 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)

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