Search in sources :

Example 11 with CurrentUserServiceTarget

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

the class DataApprovalLevelServiceTest method testGetUserDataApprovalLevelsAcceptLower.

@Test
void testGetUserDataApprovalLevelsAcceptLower() {
    dataApprovalLevelService.addDataApprovalLevel(level4B);
    dataApprovalLevelService.addDataApprovalLevel(level4A);
    dataApprovalLevelService.addDataApprovalLevel(level4);
    dataApprovalLevelService.addDataApprovalLevel(level3B);
    dataApprovalLevelService.addDataApprovalLevel(level3A);
    dataApprovalLevelService.addDataApprovalLevel(level3);
    dataApprovalLevelService.addDataApprovalLevel(level2B);
    dataApprovalLevelService.addDataApprovalLevel(level2A);
    dataApprovalLevelService.addDataApprovalLevel(level2);
    dataApprovalLevelService.addDataApprovalLevel(level1B);
    dataApprovalLevelService.addDataApprovalLevel(level1A);
    dataApprovalLevelService.addDataApprovalLevel(level1);
    Set<OrganisationUnit> assignedOrgUnits = new HashSet<>();
    assignedOrgUnits.add(organisationUnitB);
    Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>();
    dataViewOrgUnits.add(organisationUnitB);
    CurrentUserService currentUserService = new MockCurrentUserService(assignedOrgUnits, dataViewOrgUnits, DataApproval.AUTH_ACCEPT_LOWER_LEVELS);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataApprovalLevelService);
    List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels(currentUserService.getCurrentUser());
    assertEquals("02 2A 2B 03 3A 3B 04 4A 4B", levelNames(levels));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 12 with CurrentUserServiceTarget

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

the class DataApprovalLevelServiceTest method testGetUserReadApprovalLevels_1A.

@Test
void testGetUserReadApprovalLevels_1A() {
    // 
    // Test 1: Like when a user may capture data within their own district
    // but view data in other districts within their province.
    // 
    // Variation A: User does *not* have approval at lower levels authority.
    // 
    organisationUnitService.addOrganisationUnit(organisationUnitE);
    organisationUnitService.addOrganisationUnit(organisationUnitF);
    organisationUnitService.addOrganisationUnit(organisationUnitG);
    organisationUnitService.addOrganisationUnit(organisationUnitH);
    dataApprovalLevelService.addDataApprovalLevel(level1, 1);
    dataApprovalLevelService.addDataApprovalLevel(level2, 2);
    dataApprovalLevelService.addDataApprovalLevel(level3, 3);
    dataApprovalLevelService.addDataApprovalLevel(level4, 4);
    dataApprovalLevelService.addDataApprovalLevel(level5, 5);
    Set<OrganisationUnit> assignedOrgUnits = new HashSet<>();
    assignedOrgUnits.add(organisationUnitC);
    Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>();
    dataViewOrgUnits.add(organisationUnitB);
    CurrentUserService currentUserService = new MockCurrentUserService(assignedOrgUnits, dataViewOrgUnits);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataApprovalLevelService);
    Map<OrganisationUnit, Integer> readApprovalLevels = dataApprovalLevelService.getUserReadApprovalLevels();
    assertEquals(2, readApprovalLevels.size());
    assertEquals(4, (int) readApprovalLevels.get(organisationUnitC));
    assertEquals(3, (int) readApprovalLevels.get(organisationUnitB));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 13 with CurrentUserServiceTarget

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

the class DataApprovalLevelServiceTest method testGetUserReadApprovalLevels_1B.

@Test
void testGetUserReadApprovalLevels_1B() {
    // 
    // Test 1: Like when a user may capture data within their own district
    // but view data in other districts within their province.
    // 
    // Variation B: User *has* approval at lower levels authority.
    // 
    organisationUnitService.addOrganisationUnit(organisationUnitE);
    organisationUnitService.addOrganisationUnit(organisationUnitF);
    organisationUnitService.addOrganisationUnit(organisationUnitG);
    organisationUnitService.addOrganisationUnit(organisationUnitH);
    dataApprovalLevelService.addDataApprovalLevel(level1, 1);
    dataApprovalLevelService.addDataApprovalLevel(level2, 2);
    dataApprovalLevelService.addDataApprovalLevel(level3, 3);
    dataApprovalLevelService.addDataApprovalLevel(level4, 4);
    dataApprovalLevelService.addDataApprovalLevel(level5, 5);
    Set<OrganisationUnit> assignedOrgUnits = new HashSet<>();
    assignedOrgUnits.add(organisationUnitC);
    Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>();
    dataViewOrgUnits.add(organisationUnitB);
    CurrentUserService currentUserService = new MockCurrentUserService(assignedOrgUnits, dataViewOrgUnits, DataApproval.AUTH_APPROVE_LOWER_LEVELS);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataApprovalLevelService);
    Map<OrganisationUnit, Integer> readApprovalLevels = dataApprovalLevelService.getUserReadApprovalLevels();
    assertEquals(2, readApprovalLevels.size());
    assertEquals(APPROVAL_LEVEL_UNAPPROVED, (int) readApprovalLevels.get(organisationUnitC));
    assertEquals(3, (int) readApprovalLevels.get(organisationUnitB));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 14 with CurrentUserServiceTarget

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

the class DataApprovalLevelServiceTest method testGetUserDataApprovalLevelsApproveHereAndLower.

@Test
void testGetUserDataApprovalLevelsApproveHereAndLower() {
    dataApprovalLevelService.addDataApprovalLevel(level4B);
    dataApprovalLevelService.addDataApprovalLevel(level4A);
    dataApprovalLevelService.addDataApprovalLevel(level4);
    dataApprovalLevelService.addDataApprovalLevel(level3B);
    dataApprovalLevelService.addDataApprovalLevel(level3A);
    dataApprovalLevelService.addDataApprovalLevel(level3);
    dataApprovalLevelService.addDataApprovalLevel(level2B);
    dataApprovalLevelService.addDataApprovalLevel(level2A);
    dataApprovalLevelService.addDataApprovalLevel(level2);
    dataApprovalLevelService.addDataApprovalLevel(level1B);
    dataApprovalLevelService.addDataApprovalLevel(level1A);
    dataApprovalLevelService.addDataApprovalLevel(level1);
    Set<OrganisationUnit> assignedOrgUnits = new HashSet<>();
    assignedOrgUnits.add(organisationUnitB);
    Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>();
    dataViewOrgUnits.add(organisationUnitB);
    CurrentUserService currentUserService = new MockCurrentUserService(assignedOrgUnits, dataViewOrgUnits, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataApprovalLevelService);
    List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels(currentUserService.getCurrentUser());
    assertEquals("02 2A 2B 03 3A 3B 04 4A 4B", levelNames(levels));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 15 with CurrentUserServiceTarget

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

the class DataApprovalLevelServiceTest method testGetUserDataApprovalLevelsAcceptMuchLower.

@Test
void testGetUserDataApprovalLevelsAcceptMuchLower() {
    dataApprovalLevelService.addDataApprovalLevel(level4);
    Set<OrganisationUnit> assignedOrgUnits = new HashSet<>();
    assignedOrgUnits.add(organisationUnitB);
    Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>();
    dataViewOrgUnits.add(organisationUnitB);
    CurrentUserService currentUserService = new MockCurrentUserService(assignedOrgUnits, dataViewOrgUnits, DataApproval.AUTH_ACCEPT_LOWER_LEVELS);
    setDependency(CurrentUserServiceTarget.class, CurrentUserServiceTarget::setCurrentUserService, currentUserService, dataApprovalLevelService);
    List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels(currentUserService.getCurrentUser());
    assertEquals("04", levelNames(levels));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) CurrentUserServiceTarget(org.hisp.dhis.user.CurrentUserServiceTarget) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

CurrentUserServiceTarget (org.hisp.dhis.user.CurrentUserServiceTarget)24 MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)23 CurrentUserService (org.hisp.dhis.user.CurrentUserService)21 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 Test (org.junit.jupiter.api.Test)11 DhisSpringTest (org.hisp.dhis.DhisSpringTest)10 HashSet (java.util.HashSet)9 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)7 CategoryOption (org.hisp.dhis.category.CategoryOption)5 Date (java.util.Date)4 Expression (org.hisp.dhis.expression.Expression)3 PeriodType (org.hisp.dhis.period.PeriodType)3 AttributeValue (org.hisp.dhis.attribute.AttributeValue)2 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)2 OrganisationUnitLevel (org.hisp.dhis.organisationunit.OrganisationUnitLevel)2 HashMap (java.util.HashMap)1 AnalyticsServiceTarget (org.hisp.dhis.analytics.AnalyticsServiceTarget)1 Attribute (org.hisp.dhis.attribute.Attribute)1 Category (org.hisp.dhis.category.Category)1 BatchHandlerFactoryTarget (org.hisp.dhis.common.BatchHandlerFactoryTarget)1