← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15485: DimensionService, fixed bug, lists of dimensions of type org unit group set and data element grou...

 

------------------------------------------------------------
revno: 15485
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-05-31 15:38:30 +0200
message:
  DimensionService, fixed bug, lists of dimensions of type org unit group set and data element group set did not respect sharing
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.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/common/DimensionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java	2014-05-19 17:59:03 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DimensionService.java	2014-05-31 13:38:30 +0000
@@ -30,6 +30,8 @@
 
 import java.util.List;
 
+import org.hisp.dhis.user.User;
+
 /**
  * @author Lars Helge Overland
  */
@@ -39,6 +41,8 @@
     
     List<NameableObject> getCanReadDimensionItems( String uid );
     
+    <T extends IdentifiableObject> List<T> filterCanRead( User user, List<T> objects );
+    
     DimensionType getDimensionType( String uid );
     
     List<DimensionalObject> getAllDimensions();

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java	2014-05-19 17:59:03 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/dimension/DefaultDimensionService.java	2014-05-31 13:38:30 +0000
@@ -34,6 +34,7 @@
 import org.hisp.dhis.common.DimensionType;
 import org.hisp.dhis.common.DimensionalObject;
 import org.hisp.dhis.common.DimensionalObjectUtils;
+import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.common.NameableObject;
 import org.hisp.dhis.dataelement.CategoryOptionGroup;
@@ -68,6 +69,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -167,21 +169,29 @@
         {            
             User user = currentUserService.getCurrentUser();
 
-            //TODO do this with query to improve performance
-
-            for ( NameableObject item : dimension.getItems() )
-            {
-                boolean canRead = aclService.canRead( user, item );
-
-                if ( canRead )
-                {
-                    items.add( item );
-                }
-            }
+            items.addAll( filterCanRead( user, dimension.getItems() ) );
         }
 
         return items;
     }
+    
+    public <T extends IdentifiableObject> List<T> filterCanRead( User user, List<T> objects )
+    {        
+        List<T> list = new ArrayList<T>( objects );
+        Iterator<T> iterator = list.iterator();
+        
+        while ( iterator.hasNext() )
+        {
+            T object = iterator.next();
+            
+            if ( !aclService.canRead( user, object ) )
+            {
+                iterator.remove();
+            }
+        }
+        
+        return list;
+    }
         
     public DimensionType getDimensionType( String uid )
     {
@@ -255,7 +265,9 @@
         dimensions.addAll( degs );
         dimensions.addAll( ougs );
 
-        return dimensions;
+        User user = currentUserService.getCurrentUser();
+        
+        return filterCanRead( user, dimensions );
     }
     
     public List<DimensionalObject> getDimensionConstraints()