Search in sources :

Example 26 with CurrentUserService

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

the class DataApprovalServiceTest method testMayApproveNoAuthority.

@Test
@Category(IntegrationTest.class)
public void testMayApproveNoAuthority() {
    Set<OrganisationUnit> units = newHashSet(organisationUnitB);
    CurrentUserService currentUserService = new MockCurrentUserService(units, null, AUTH_APPR_LEVEL);
    userService.addUser(currentUserService.getCurrentUser());
    setCurrentUserServiceDependencies(currentUserService);
    Date date = new Date();
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayApprove());
    dataApprovalStore.addDataApproval(new DataApproval(level4, workflow1234, periodA, organisationUnitD, defaultOptionCombo, NOT_ACCEPTED, date, userA));
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayApprove());
    dataApprovalStore.addDataApproval(new DataApproval(level3, workflow1234, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA));
    dataApprovalStore.addDataApproval(new DataApproval(level3, workflow1234, periodA, organisationUnitE, defaultOptionCombo, NOT_ACCEPTED, date, userA));
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayApprove());
    dataApprovalStore.addDataApproval(new DataApproval(level2, workflow1234, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA));
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayApprove());
}
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) Date(java.util.Date) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) Category(org.junit.experimental.categories.Category) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Example 27 with CurrentUserService

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

the class DataApprovalLevelServiceTest method testGetUserReadApprovalLevels_1A.

@Test
public 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(dataApprovalLevelService, "currentUserService", currentUserService, CurrentUserService.class);
    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) HashSet(java.util.HashSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 28 with CurrentUserService

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

the class DataApprovalLevelServiceTest method testGetUserDataApprovalLevelsApproveHereAndLower.

@Test
public 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(dataApprovalLevelService, "currentUserService", currentUserService, CurrentUserService.class);
    List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels();
    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) HashSet(java.util.HashSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 29 with CurrentUserService

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

the class DataApprovalLevelServiceTest method testGetUserDataApprovalLevelsAcceptLower.

@Test
public 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(dataApprovalLevelService, "currentUserService", currentUserService, CurrentUserService.class);
    List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels();
    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) HashSet(java.util.HashSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 30 with CurrentUserService

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

the class DataApprovalLevelServiceTest method testGetUserReadApprovalLevels_1C.

@Test
public void testGetUserReadApprovalLevels_1C() {
    //
    // Test 1: Like when a user may capture data within their own district
    // but view data in other districts within their province.
    //
    // Variation C: No approval level for org unit level 4.
    //
    organisationUnitService.addOrganisationUnit(organisationUnitE);
    organisationUnitService.addOrganisationUnit(organisationUnitF);
    organisationUnitService.addOrganisationUnit(organisationUnitG);
    organisationUnitService.addOrganisationUnit(organisationUnitH);
    // 1st approval level
    dataApprovalLevelService.addDataApprovalLevel(level1, 1);
    // 2nd approval level
    dataApprovalLevelService.addDataApprovalLevel(level2, 2);
    // 3rd approval level
    dataApprovalLevelService.addDataApprovalLevel(level3, 3);
    // 4th approval level
    dataApprovalLevelService.addDataApprovalLevel(level5, 4);
    Set<OrganisationUnit> assignedOrgUnits = new HashSet<>();
    assignedOrgUnits.add(organisationUnitC);
    Set<OrganisationUnit> dataViewOrgUnits = new HashSet<>();
    dataViewOrgUnits.add(organisationUnitB);
    CurrentUserService currentUserService = new MockCurrentUserService(assignedOrgUnits, dataViewOrgUnits);
    setDependency(dataApprovalLevelService, "currentUserService", currentUserService, CurrentUserService.class);
    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) HashSet(java.util.HashSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)34 CurrentUserService (org.hisp.dhis.user.CurrentUserService)34 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)28 Test (org.junit.Test)28 DhisTest (org.hisp.dhis.DhisTest)19 IntegrationTest (org.hisp.dhis.IntegrationTest)18 Date (java.util.Date)17 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)17 Category (org.junit.experimental.categories.Category)17 HashSet (java.util.HashSet)9 DhisSpringTest (org.hisp.dhis.DhisSpringTest)9 DataMayNotBeApprovedException (org.hisp.dhis.dataapproval.exceptions.DataMayNotBeApprovedException)4 Expression (org.hisp.dhis.expression.Expression)2 MonthlyPeriodType (org.hisp.dhis.period.MonthlyPeriodType)2 Attribute (org.hisp.dhis.attribute.Attribute)1 AttributeValue (org.hisp.dhis.attribute.AttributeValue)1 DataElementCategoryOption (org.hisp.dhis.dataelement.DataElementCategoryOption)1 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)1 DataValue (org.hisp.dhis.datavalue.DataValue)1 MockBatchHandlerFactory (org.hisp.dhis.mock.batchhandler.MockBatchHandlerFactory)1