← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16043: support userFilter in /api/programs, will only return programs that your current user role is all...

 

------------------------------------------------------------
revno: 16043
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-07-09 14:17:55 +0700
message:
  support userFilter in /api/programs, will only return programs that your current user role is allowed to enter data for
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramController.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-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramController.java	2014-07-03 07:59:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/event/ProgramController.java	2014-07-09 07:17:55 +0000
@@ -34,6 +34,7 @@
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramInstance;
 import org.hisp.dhis.program.ProgramInstanceService;
+import org.hisp.dhis.program.ProgramService;
 import org.hisp.dhis.schema.descriptors.ProgramSchemaDescriptor;
 import org.hisp.dhis.webapi.controller.AbstractCrudController;
 import org.hisp.dhis.webapi.webdomain.WebMetaData;
@@ -51,13 +52,16 @@
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 @Controller
-@RequestMapping( value = ProgramSchemaDescriptor.API_ENDPOINT )
+@RequestMapping(value = ProgramSchemaDescriptor.API_ENDPOINT)
 public class ProgramController
     extends AbstractCrudController<Program>
 {
     @Autowired
     private ProgramInstanceService programInstanceService;
 
+    @Autowired
+    private ProgramService programService;
+
     @Override
     protected void postCreateEntity( Program program )
     {
@@ -97,6 +101,13 @@
 
         String type = options.getOptions().get( "type" );
         String orgUnit = options.getOptions().get( "orgUnit" );
+        Boolean userFilter = Boolean.parseBoolean( options.getOptions().get( "userFilter" ) );
+
+        if ( userFilter )
+        {
+            List<Program> programs = Lists.newArrayList( programService.getProgramsByCurrentUser() );
+            entityList.retainAll( programs );
+        }
 
         if ( type != null )
         {