← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13494: Data approval, displaying approval buttons only if user is authorized to approve/unapprove

 

------------------------------------------------------------
revno: 13494
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-12-30 15:07:06 +0100
message:
  Data approval, displaying approval buttons only if user is authorized to approve/unapprove
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js


--
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/api/controller/DataApprovalController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java	2013-12-27 18:02:36 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java	2013-12-30 14:07:06 +0000
@@ -30,6 +30,8 @@
 
 import java.io.IOException;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -66,6 +68,10 @@
 public class DataApprovalController
 {
     public static final String RESOURCE_PATH = "/dataApprovals";
+    
+    private static final String APPROVAL_STATE = "state";
+    private static final String APPROVAL_MAY_APPROVE = "mayApprove";
+    private static final String APPROVAL_MAY_UNAPPROVE = "mayUnapprove";
 
     @Autowired
     private DataApprovalService dataApprovalService;
@@ -123,10 +129,25 @@
         {
             return;
         }
-                
+        
         DataApprovalState state = dataApprovalService.getDataApprovalState( dataSet, period, organisationUnit, attributeOptionCombo );
-        
-        JacksonUtils.toJson( response.getOutputStream(), state );
+
+        boolean mayApprove = dataApprovalService.mayApprove( organisationUnit );
+        boolean mayUnapprove = false;
+        
+        if ( DataApprovalState.APPROVED.equals( state ) )
+        {
+            DataApproval approval = dataApprovalService.getDataApproval( dataSet, period, organisationUnit, attributeOptionCombo );
+            
+            mayUnapprove = dataApprovalService.mayUnapprove( approval );
+        }
+        
+        Map<String, String> approvalState = new HashMap<String, String>();
+        approvalState.put( APPROVAL_STATE, state.toString() );
+        approvalState.put( APPROVAL_MAY_APPROVE, String.valueOf( mayApprove ) );
+        approvalState.put( APPROVAL_MAY_UNAPPROVE, String.valueOf( mayUnapprove ) );
+        
+        JacksonUtils.toJson( response.getOutputStream(), approvalState );
     }
     
     @PreAuthorize( "hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')" )

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js	2013-12-29 15:22:01 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js	2013-12-30 14:07:06 +0000
@@ -96,7 +96,7 @@
 	
 	var categoryRx = [];	
 	$.each( categoryIds, function( idx, id ) {
-		categoryRx.push( $.get( "../api/dimensions/" + id + ".json" ) );
+		categoryRx.push( $.get( "../api/categories/" + id + ".json" ) );
 	} );
 
 	$.when.apply( $, categoryRx ).done( function() {
@@ -343,22 +343,33 @@
 	
 	var url = dhis2.dsr.getDataApprovalUrl( dataSetReport );
 	
-	$.get( url, function( status ) {
-		if ( status && '"READY_FOR_APPROVAL"' == status ) {
-			$( "#approvalDiv" ).show();
-			$( "#approveButton" ).prop( "disabled", false );
-			$( "#unapproveButton" ).prop( "disabled", true );
+	$.getJSON( url, function( json ) {
+		if ( !json || !json.state ) {
+			return;
+		}
+		
+		var state = json.state;		
+		if ( "READY_FOR_APPROVAL" == state ) {
 			$( "#approvalNotification" ).show().html( i18n_ready_for_approval );
+			
+			if ( json.mayApprove ) {
+				$( "#approvalDiv" ).show();
+				$( "#approveButton" ).prop( "disabled", false );
+				$( "#unapproveButton" ).prop( "disabled", true );
+			}
 		}
-		else if ( status && '"APPROVED"' == status ) {
-			$( "#approvalDiv" ).show();
-			$( "#approveButton" ).prop( "disabled", true );
-			$( "#unapproveButton" ).prop( "disabled", false );
+		else if ( "APPROVED" == state ) {
 			$( "#approvalNotification" ).show().html( i18n_approved );
+			
+			if ( json.mayUnapprove ) {
+				$( "#approvalDiv" ).show();
+				$( "#approveButton" ).prop( "disabled", true );
+				$( "#unapproveButton" ).prop( "disabled", false );
+			}
 		}
-		else if ( status && '"WAITING_FOR_LOWER_LEVEL_APPROVAL"' == status ) {
-			$( "#approvalDiv" ).hide();
-			$( "#approvalNotification" ).show().html( i18n_waiting_for_lower_level_approval );		
+		else if ( "WAITING_FOR_LOWER_LEVEL_APPROVAL" == state ) {
+			$( "#approvalNotification" ).show().html( i18n_waiting_for_lower_level_approval );	
+			$( "#approvalDiv" ).hide();	
 		}
 	} );
 }