← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21553: Event query, fixed bug with program check

 

------------------------------------------------------------
revno: 21553
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-12-30 15:01:35 +0100
message:
  Event query, fixed bug with program check
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.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/user/UserCredentials.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java	2015-11-17 19:46:11 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java	2015-12-30 14:01:35 +0000
@@ -290,6 +290,25 @@
 
         return programs;
     }
+    
+    /**
+     * Indicates if the given program is accessible.
+     * 
+     * @param program the program.
+     * @return true if if the given program is accessible.
+     */
+    public boolean canAccessProgram( Program program )
+    {
+        for ( UserAuthorityGroup group : userAuthorityGroups )
+        {
+            if ( group.getPrograms().contains( program ) )
+            {
+                return true;
+            }
+        }
+        
+        return false;
+    }
 
     /**
      * Indicates whether this user credentials can issue the given user authority

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2015-12-16 12:46:52 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java	2015-12-30 14:01:35 +0000
@@ -541,12 +541,7 @@
             }
         }
 
-        if ( pr != null && !userCredentials.isSuper() && userCredentials.getAllPrograms().size() == 0 )
-        {
-            throw new IllegalQueryException( "User has no access to programs" );
-        }
-
-        if ( pr != null && !userCredentials.getAllPrograms().contains( pr ) )
+        if ( pr != null && !userCredentials.isSuper() && !userCredentials.canAccessProgram( pr ) )
         {
             throw new IllegalQueryException( "User has no access to program: " + pr.getUid() );
         }