dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33714
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17265: Data approval, passing current user around instead of fetching from db multiple times
------------------------------------------------------------
revno: 17265
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-10-24 14:25:34 +0200
message:
Data approval, passing current user around instead of fetching from db multiple times
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java
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/DefaultDataApprovalService.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-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java 2014-10-24 11:45:30 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/DataApprovalLevelService.java 2014-10-24 12:25:34 +0000
@@ -33,6 +33,7 @@
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
+import org.hisp.dhis.user.User;
import java.util.List;
import java.util.Map;
@@ -215,6 +216,8 @@
* @return approval level
*/
DataApprovalLevel getUserApprovalLevel( OrganisationUnit orgUnit, boolean includeDataViewOrgUnits );
+
+ DataApprovalLevel getUserApprovalLevel( User user, OrganisationUnit orgUnit, boolean includeDataViewOrgUnits );
/**
* By organisation unit subhierarchy, returns the lowest data approval
=== 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 2014-10-24 11:45:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalLevelService.java 2014-10-24 12:25:34 +0000
@@ -511,14 +511,20 @@
public DataApprovalLevel getUserApprovalLevel( OrganisationUnit orgUnit, boolean includeDataViewOrgUnits )
{
User user = currentUserService.getCurrentUser();
-
+
+ return getUserApprovalLevel( user, orgUnit, includeDataViewOrgUnits );
+ }
+
+ @Override
+ public DataApprovalLevel getUserApprovalLevel( User user, OrganisationUnit orgUnit, boolean includeDataViewOrgUnits )
+ {
if ( user != null )
{
for ( OrganisationUnit ou : user.getOrganisationUnits() )
{
if ( orgUnit.isEqualOrChildOf( org.hisp.dhis.system.util.CollectionUtils.asSet( ou ) ) )
{
- return userApprovalLevel( ou );
+ return userApprovalLevel( ou, user );
}
}
@@ -528,7 +534,7 @@
{
if ( orgUnit.isEqualOrChildOf( org.hisp.dhis.system.util.CollectionUtils.asSet( ou ) ) )
{
- return userApprovalLevel( ou );
+ return userApprovalLevel( ou, user );
}
}
}
@@ -555,7 +561,7 @@
{
for ( OrganisationUnit orgUnit : user.getOrganisationUnits() )
{
- map.put( orgUnit, requiredApprovalLevel( orgUnit ) );
+ map.put( orgUnit, requiredApprovalLevel( orgUnit, user ) );
}
}
@@ -570,7 +576,7 @@
{
if ( !map.containsKey( orgUnit ) )
{
- map.put( orgUnit, requiredApprovalLevel( orgUnit ) );
+ map.put( orgUnit, requiredApprovalLevel( orgUnit, user ) );
}
}
@@ -673,9 +679,9 @@
* @param orgUnit organisation unit to test.
* @return required approval level for user to see the data.
*/
- private int requiredApprovalLevel( OrganisationUnit orgUnit )
+ private int requiredApprovalLevel( OrganisationUnit orgUnit, User user )
{
- DataApprovalLevel userLevel = userApprovalLevel( orgUnit );
+ DataApprovalLevel userLevel = userApprovalLevel( orgUnit, user );
return userLevel == null ? 0 :
userLevel.getLevel() == getAllDataApprovalLevels().size() ? APPROVAL_LEVEL_UNAPPROVED :
@@ -704,7 +710,7 @@
* @param orgUnit organisation unit to test.
* @return approval level for user.
*/
- private DataApprovalLevel userApprovalLevel( OrganisationUnit orgUnit )
+ private DataApprovalLevel userApprovalLevel( OrganisationUnit orgUnit, User user )
{
int orgUnitLevel = organisationUnitService.getLevelOfOrganisationUnit( orgUnit );
@@ -716,7 +722,7 @@
if ( level.getOrgUnitLevel() >= orgUnitLevel
&& securityService.canRead( level )
- && canReadCOGS( level.getCategoryOptionGroupSet() ) )
+ && canReadCOGS( user, level.getCategoryOptionGroupSet() ) )
{
userLevel = level;
break;
@@ -739,11 +745,11 @@
* @param cogs The category option group set to test
* @return true if user can read at least one category option group.
*/
- private boolean canReadCOGS( CategoryOptionGroupSet cogs )
+ private boolean canReadCOGS( User user, CategoryOptionGroupSet cogs )
{
if ( cogs == null )
{
- UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials();
+ UserCredentials userCredentials = user.getUserCredentials();
return CollectionUtils.isEmpty( userCredentials.getCogsDimensionConstraints() )
&& CollectionUtils.isEmpty( userCredentials.getCatDimensionConstraints() );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java 2014-10-24 11:45:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataapproval/DefaultDataApprovalService.java 2014-10-24 12:25:34 +0000
@@ -386,7 +386,7 @@
if ( da.getOrganisationUnit() != null ) //TODO: Shouldn't be null -- fix the category option mappings to org units in the database.
{
- DataApprovalLevel userApprovalLevel = dataApprovalLevelService.getUserApprovalLevel( da.getOrganisationUnit(), false );
+ DataApprovalLevel userApprovalLevel = dataApprovalLevelService.getUserApprovalLevel( user, da.getOrganisationUnit(), false );
if ( userApprovalLevel != null )
{