dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36438
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18642: Fix getUserDataApprovalLevels() for user with authority for lower levels, where user's org unit i...
------------------------------------------------------------
revno: 18642
committer: jimgrace@xxxxxxxxx
branch nick: dhis2
timestamp: Thu 2015-03-19 15:17:43 -0400
message:
Fix getUserDataApprovalLevels() for user with authority for lower levels, where user's org unit is above approval levels.
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java 2015-02-26 11:19:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java 2015-03-19 19:17:43 +0000
@@ -306,10 +306,10 @@
// Get new values of assignedAtLevel and approvableAtLevel for the current approval level.
- assignedAtLevel = canReadThisLevel && ( userOrgUnitLevels.contains( approvalLevel.getOrgUnitLevel() )
+ assignedAtLevel = canReadThisLevel && ( ( mayApprove && userOrgUnitLevels.contains( approvalLevel.getOrgUnitLevel() ) )
|| ( ( mayApproveAtLowerLevels || mayAcceptAtLowerLevels ) && approvalLevel.getOrgUnitLevel() > lowestNumberOrgUnitLevel ) );
- approvableAtLevel = canReadThisLevel && ( ( mayApprove && assignedAtLevel ) || approvableAtAllLowerLevels );
+ approvableAtLevel = canReadThisLevel && ( assignedAtLevel || approvableAtAllLowerLevels );
// Test using assignedAtLevel and approvableAtLevel values from the current level.
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java 2015-03-13 16:45:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/hibernate/HibernateDataApprovalStore.java 2015-03-19 19:17:43 +0000
@@ -378,7 +378,7 @@
"left join usergroupmembers ugm on ugm.usergroupid = uga.usergroupid " +
"where couga.categoryoptionid = cocco.categoryoptionid and ugm.userid = " + user.getId() + ") )" );
- log.debug( "Get approval SQL: " + sql );
+ log.info( "Get approval SQL: " + sql );
SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java 2015-03-05 18:09:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java 2015-03-19 19:17:43 +0000
@@ -40,6 +40,7 @@
import java.util.Map;
import java.util.Set;
+import org.apache.commons.lang.StringUtils;
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
import org.hisp.dhis.dataelement.DataElementCategoryService;
@@ -522,7 +523,8 @@
assertEquals( 3, (int) readApprovalLevels.get( organisationUnitB ) );
}
- @Ignore
+ //TODO: add tests for getUserDataApprovalLevels where the user can access the CategoryOptionGroupSets
+
@Test
public void testGetUserDataApprovalLevelsApproveHere() throws Exception
{
@@ -550,14 +552,9 @@
List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels();
- assertEquals( 4, levels.size() );
- assertEquals( "02", levels.get( 0 ).getName() );
- assertEquals( "2A", levels.get( 1 ).getName() );
- assertEquals( "2B", levels.get( 2 ).getName() );
- assertEquals( "03", levels.get( 3 ).getName() );
+ assertEquals( "02", levelNames( levels ) );
}
- @Ignore
@Test
public void testGetUserDataApprovalLevelsApproveLower() throws Exception
{
@@ -584,19 +581,10 @@
setDependency( dataApprovalLevelService, "currentUserService", currentUserService, CurrentUserService.class );
List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels();
-
- assertEquals( 8, levels.size() );
- assertEquals( "2A", levels.get( 0 ).getName() );
- assertEquals( "2B", levels.get( 1 ).getName() );
- assertEquals( "03", levels.get( 2 ).getName() );
- assertEquals( "3A", levels.get( 3 ).getName() );
- assertEquals( "3B", levels.get( 4 ).getName() );
- assertEquals( "04", levels.get( 5 ).getName() );
- assertEquals( "4A", levels.get( 6 ).getName() );
- assertEquals( "4B", levels.get( 7 ).getName() );
+
+ assertEquals( "03 04", levelNames( levels ) );
}
- @Ignore
@Test
public void testGetUserDataApprovalLevelsApproveHereAndLower() throws Exception
{
@@ -623,20 +611,10 @@
setDependency( dataApprovalLevelService, "currentUserService", currentUserService, CurrentUserService.class );
List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels();
-
- assertEquals( 9, levels.size() );
- assertEquals( "02", levels.get( 0 ).getName() );
- assertEquals( "2A", levels.get( 1 ).getName() );
- assertEquals( "2B", levels.get( 2 ).getName() );
- assertEquals( "03", levels.get( 3 ).getName() );
- assertEquals( "3A", levels.get( 4 ).getName() );
- assertEquals( "3B", levels.get( 5 ).getName() );
- assertEquals( "04", levels.get( 6 ).getName() );
- assertEquals( "4A", levels.get( 7 ).getName() );
- assertEquals( "4B", levels.get( 8 ).getName() );
+
+ assertEquals( "02 03 04", levelNames( levels ) );
}
- @Ignore
@Test
public void testGetUserDataApprovalLevelsAcceptLower() throws Exception
{
@@ -663,10 +641,38 @@
setDependency( dataApprovalLevelService, "currentUserService", currentUserService, CurrentUserService.class );
List<DataApprovalLevel> levels = dataApprovalLevelService.getUserDataApprovalLevels();
-
- assertEquals( 3, levels.size() );
- assertEquals( "2A", levels.get( 0 ).getName() );
- assertEquals( "2B", levels.get( 1 ).getName() );
- assertEquals( "03", levels.get( 2 ).getName() );
+
+ assertEquals( "03 04", levelNames( levels ) );
+ }
+
+ @Test
+ public void testGetUserDataApprovalLevelsAcceptMuchLower() throws Exception
+ {
+ 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 ) );
+ }
+
+ private String levelNames(List<DataApprovalLevel> levels )
+ {
+ String names = "";
+
+ for ( DataApprovalLevel level : levels )
+ {
+ names += (names.isEmpty() ? "" : " ") + level.getName();
+ }
+
+ return names;
}
}