← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13453: Data approval, improved validation

 

------------------------------------------------------------
revno: 13453
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-12-27 19:02:36 +0100
message:
  Data approval, improved validation
modified:
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java
  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-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java	2013-12-27 17:35:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java	2013-12-27 18:02:36 +0000
@@ -50,7 +50,6 @@
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.user.UserService;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -145,6 +144,7 @@
         //    |   |
         //    D   F
         //
+        
         organisationUnitA = createOrganisationUnit( 'A' );
         organisationUnitB = createOrganisationUnit( 'B', organisationUnitA );
         organisationUnitC = createOrganisationUnit( 'C', organisationUnitB );

=== 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 17:42:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataApprovalController.java	2013-12-27 18:02:36 +0000
@@ -169,8 +169,6 @@
             return;
         }
         
-        User user = currentUserService.getCurrentUser();
-        
         if ( !dataApprovalService.mayApprove( organisationUnit ) )
         {
             ContextUtils.conflictResponse( response, "Current user is not authorized to approve for organisation unit: " + ou );
@@ -184,6 +182,8 @@
             ContextUtils.conflictResponse( response, "Data is not ready for approval: " + state );
             return;
         }
+
+        User user = currentUserService.getCurrentUser();
         
         DataApproval approval = new DataApproval( dataSet, period, organisationUnit, attributeOptionCombo, new Date(), user );
         
@@ -230,7 +230,7 @@
         {
             return;
         }
-        
+
         DataApproval approval = dataApprovalService.getDataApproval( dataSet, period, organisationUnit, attributeOptionCombo );
         
         if ( approval == null )
@@ -238,6 +238,12 @@
             ContextUtils.conflictResponse( response, "Data is not approved and cannot be unapproved" );
             return;
         }
+
+        if ( !dataApprovalService.mayUnapprove( approval ) )
+        {
+            ContextUtils.conflictResponse( response, "Current user is not authorized to unapprove for organisation unit: " + ou );
+            return;
+        }
         
         dataApprovalService.deleteDataApproval( approval );
     }

=== 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-27 17:42:22 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/webapp/dhis-web-reporting/javascript/dataSetReport.js	2013-12-27 18:02:36 +0000
@@ -28,7 +28,7 @@
     	var dim = $( this ).data( "uid" );
     	var item = $( this ).val();
     	
-    	if ( dim && item )
+    	if ( dim && item && item != -1 )
     	{
     		var dimQuery = dim + ":" + item;
     		dims.push( dimQuery );
@@ -122,6 +122,28 @@
 	} );
 }
 
+/**
+ * Indicates whether all attributes have a valid selection.
+ */
+dhis2.dsr.attributesSelected = function( dataSetReport )
+{
+	if ( dhis2.dsr.metaData.defaultCategoryCombo == dataSetReport.cc ) {
+		return true; // Default category combo requires no selection
+	}
+	
+	var cc = dataSetReport.cc;
+	var categoryCombo = dhis2.dsr.metaData.categoryCombos[cc];
+	
+	if ( !categoryCombo || !categoryCombo.categories ) {
+		return false;
+	}
+		
+	var expected = categoryCombo.categories.length;
+	var actual = dataSetReport.cp.length;
+	
+	return !!( expected == actual );
+}
+
 //------------------------------------------------------------------------------
 // Period
 //------------------------------------------------------------------------------
@@ -310,15 +332,16 @@
 
 dhis2.dsr.showApproval = function()
 {
+	var dataSetReport = dhis2.dsr.currentDataSetReport;
+	
 	var approval = $( "#dataSetId :selected" ).data( "approval" );
-	
-	if ( !approval ) {
+	var attributesSelected = dhis2.dsr.attributesSelected( dataSetReport );
+
+	if ( !approval || !attributesSelected ) {
 		$( "#approvalDiv" ).hide();
 		return false;
 	}
 	
-	var dataSetReport = dhis2.dsr.currentDataSetReport;
-	
 	var url = dhis2.dsr.getDataApprovalUrl( dataSetReport );
 	
 	$.get( url, function( status ) {