use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.
the class DataApprovalServiceTest method testMayApproveSameLevel.
@Test
@Category(IntegrationTest.class)
public void testMayApproveSameLevel() {
Set<OrganisationUnit> units = newHashSet(organisationUnitB);
CurrentUserService currentUserService = new MockCurrentUserService(units, null, DataApproval.AUTH_APPROVE, AUTH_APPR_LEVEL);
userService.addUser(currentUserService.getCurrentUser());
setCurrentUserServiceDependencies(currentUserService);
Date date = new Date();
// Level 4 (organisationUnitD and organisationUnitF ready)
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayApprove());
// Level 3 (organisationUnitC) and Level 4 (organisationUnitF) ready
try {
dataApprovalService.approveData(newArrayList(new DataApproval(level4, workflow1234, periodA, organisationUnitD, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
fail("User should not have permission to approve org unit C.");
} catch (DataMayNotBeApprovedException ex) {
// Expected error, so add the data through dataApprovalStore:
}
dataApprovalStore.addDataApproval(new DataApproval(level4, workflow1234, periodA, organisationUnitD, defaultOptionCombo, NOT_ACCEPTED, date, userA));
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayApprove());
assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayApprove());
// Level 2 (organisationUnitB) ready
try {
dataApprovalService.approveData(newArrayList(new DataApproval(level4, workflow1234, periodA, organisationUnitF, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
fail("User should not have permission to approve org unit F.");
} catch (DataMayNotBeApprovedException ex) {
// Expected error, so add the data through dataApprovalStore:
}
dataApprovalStore.addDataApproval(new DataApproval(level4, workflow1234, periodA, organisationUnitF, defaultOptionCombo, NOT_ACCEPTED, date, userA));
try {
dataApprovalService.approveData(newArrayList(new DataApproval(level3, workflow1234, periodA, organisationUnitE, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
fail("User should not have permission to approve org unit E.");
} catch (DataMayNotBeApprovedException ex) {
// Expected error, so add the data through dataApprovalStore:
}
dataApprovalStore.addDataApproval(new DataApproval(level3, workflow1234, periodA, organisationUnitE, defaultOptionCombo, NOT_ACCEPTED, date, userA));
try {
dataApprovalService.approveData(newArrayList(new DataApproval(level3, workflow1234, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
fail("User should not have permission to approve org unit C.");
} catch (DataMayNotBeApprovedException ex) {
// Expected error, so add the data through dataApprovalStore:
}
dataApprovalStore.addDataApproval(new DataApproval(level3, workflow1234, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA));
assertEquals("UNAPPROVED_READY level=null approve=T unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo));
assertEquals("APPROVED_HERE level=level3 approve=T unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo));
assertEquals("APPROVED_ABOVE level=level4 approve=F unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo));
assertEquals("APPROVED_HERE level=level3 approve=T unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo));
assertEquals("APPROVED_ABOVE level=level4 approve=F unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo));
// Level 1 (organisationUnitA) ready
dataApprovalService.approveData(newArrayList(new DataApproval(level2, workflow1234, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
assertEquals("APPROVED_HERE level=level2 approve=F unapprove=T accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo));
assertEquals("APPROVED_ABOVE level=level3 approve=T unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo));
assertEquals("APPROVED_ABOVE level=level4 approve=F unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo));
assertEquals("APPROVED_ABOVE level=level3 approve=T unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo));
assertEquals("APPROVED_ABOVE level=level4 approve=F unapprove=F accept=F unaccept=F read=T", statusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo));
// Level 1 (organisationUnitA) try to approve
try {
dataApprovalService.approveData(newArrayList(new DataApproval(level1, workflow1234, periodA, organisationUnitA, defaultOptionCombo, NOT_ACCEPTED, date, userA)));
fail("User should not have permission to approve org unit A.");
} catch (DataMayNotBeApprovedException ex) {
// Expected
}
}
use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.
the class DataApprovalServiceTest method testAddAllAndGetDataApprovalStatus.
@Test
@Category(IntegrationTest.class)
public void testAddAllAndGetDataApprovalStatus() {
Set<OrganisationUnit> units = newHashSet(organisationUnitA);
CurrentUserService currentUserService = new MockCurrentUserService(units, null, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS);
userService.addUser(currentUserService.getCurrentUser());
setCurrentUserServiceDependencies(currentUserService);
Date date = new Date();
DataApproval dataApprovalA = new DataApproval(level1, workflow12A, periodA, organisationUnitA, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalB = new DataApproval(level2, workflow12A, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalC = new DataApproval(level2, workflow12A, periodB, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA);
DataApproval dataApprovalD = new DataApproval(level2, workflow12B, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA);
// Must be approved before A.
dataApprovalService.approveData(newArrayList(dataApprovalB, dataApprovalC, dataApprovalD));
dataApprovalService.approveData(newArrayList(dataApprovalA));
DataApprovalStatus status = dataApprovalService.getDataApprovalStatus(workflow12A, periodA, organisationUnitA, defaultOptionCombo);
assertEquals(DataApprovalState.APPROVED_HERE, status.getState());
assertNotNull(status);
assertEquals(organisationUnitA.getUid(), status.getOrganisationUnitUid());
assertEquals(date, status.getCreated());
assertEquals(userA.getId(), status.getCreator().getId());
DataApprovalLevel level = status.getApprovedLevel();
assertNotNull(level);
assertEquals(level1.getName(), level.getName());
status = dataApprovalService.getDataApprovalStatus(workflow12A, periodA, organisationUnitB, defaultOptionCombo);
assertEquals(DataApprovalState.APPROVED_ABOVE, status.getState());
assertNotNull(status);
assertEquals(organisationUnitB.getUid(), status.getOrganisationUnitUid());
assertEquals(date, status.getCreated());
assertEquals(userA.getId(), status.getCreator().getId());
level = status.getApprovedLevel();
assertNotNull(level);
assertEquals(level2.getName(), level.getName());
status = dataApprovalService.getDataApprovalStatus(workflow12A, periodB, organisationUnitB, defaultOptionCombo);
assertEquals(DataApprovalState.APPROVED_HERE, status.getState());
assertNotNull(status);
assertEquals(organisationUnitB.getUid(), status.getOrganisationUnitUid());
assertEquals(date, status.getCreated());
assertEquals(userA.getId(), status.getCreator().getId());
level = status.getApprovedLevel();
assertNotNull(level);
assertEquals(level2.getName(), level.getName());
status = dataApprovalService.getDataApprovalStatus(workflow12B, periodA, organisationUnitB, defaultOptionCombo);
assertEquals(DataApprovalState.APPROVED_HERE, status.getState());
assertNotNull(status);
assertEquals(organisationUnitB.getUid(), status.getOrganisationUnitUid());
assertEquals(date, status.getCreated());
assertEquals(userA.getId(), status.getCreator().getId());
level = status.getApprovedLevel();
assertNotNull(level);
assertEquals(level2.getName(), level.getName());
status = dataApprovalService.getDataApprovalStatus(workflow12B, periodB, organisationUnitB, defaultOptionCombo);
assertEquals(DataApprovalState.UNAPPROVED_READY, status.getState());
level = status.getApprovedLevel();
assertNull(level);
}
use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.
the class DataApprovalServiceTest method testGetDataApprovalStateOtherPeriodTypes.
@Test
@Category(IntegrationTest.class)
public void testGetDataApprovalStateOtherPeriodTypes() {
Set<OrganisationUnit> units = newHashSet(organisationUnitA);
CurrentUserService currentUserService = new MockCurrentUserService(units, null, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS);
setCurrentUserServiceDependencies(currentUserService);
assertEquals(DataApprovalState.UNAPPROVED_WAITING, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getState());
assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getState());
assertEquals(DataApprovalState.UNAPPROVED_WAITING, dataApprovalService.getDataApprovalStatus(workflow1234, periodB, organisationUnitA, defaultOptionCombo).getState());
assertEquals(DataApprovalState.UNAPPROVED_WAITING, dataApprovalService.getDataApprovalStatus(workflow1234, periodY, organisationUnitA, defaultOptionCombo).getState());
assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodY, organisationUnitD, defaultOptionCombo).getState());
assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodD, organisationUnitD, defaultOptionCombo).getState());
assertEquals(DataApprovalState.UNAPPROVED_READY, dataApprovalService.getDataApprovalStatus(workflow1234, periodW, organisationUnitD, defaultOptionCombo).getState());
}
use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.
the class DataApprovalLevelServiceTest method testGetUserReadApprovalLevels_1B.
@Test
public 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(dataApprovalLevelService, "currentUserService", currentUserService, CurrentUserService.class);
Map<OrganisationUnit, Integer> readApprovalLevels = dataApprovalLevelService.getUserReadApprovalLevels();
assertEquals(2, readApprovalLevels.size());
assertEquals(APPROVAL_LEVEL_UNAPPROVED, (int) readApprovalLevels.get(organisationUnitC));
assertEquals(3, (int) readApprovalLevels.get(organisationUnitB));
}
use of org.hisp.dhis.user.CurrentUserService in project dhis2-core by dhis2.
the class DataApprovalLevelServiceTest method testGetUserDataApprovalLevelsAcceptMuchLower.
@Test
public 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(dataApprovalLevelService, "currentUserService", currentUserService, CurrentUserService.class);
List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels();
assertEquals("04", levelNames(levels));
}
Aggregations