CRM-16526 CIVI-3 Added restrictions for deleting line items
authorEdsel <edsel.lopez@jmaconsulting.biz>
Wed, 17 Feb 2016 11:57:08 +0000 (17:27 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Mon, 22 Feb 2016 18:11:38 +0000 (23:41 +0530)
----------------------------------------
* CRM-16526: ACLs for Financial Types
  https://issues.civicrm.org/jira/browse/CRM-16526

api/v3/LineItem.php

index 26f09975162134433864333fe336b991b0e445b0..fd44939691bbf81236a6fdc1720815fbc01b77af 100644 (file)
@@ -49,23 +49,25 @@ function civicrm_api3_line_item_create($params) {
       $op = CRM_Core_Action::ADD;
     }
     else {
-      if (empty($params['financial_type_id'])) {
-        $params['financial_type_id'] = civicrm_api3('LineItem', 'getvalue', array(
-          'id' => $params['id'],
-          'return' => 'financial_type_id',
-        ));
-      }
       $op = CRM_Core_Action::UPDATE;
     }
+    if (empty($params['financial_type_id'])) {
+      $params['financial_type_id'] = civicrm_api3('LineItem', 'getvalue', array(
+        'id' => $params['id'],
+        'return' => 'financial_type_id',
+      ));
+    }
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, $op);
+    if (in_array($params['financial_type_id'], array_keys($types))) {
+      $params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params, TRUE);
+      return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+    }
+    else {
+      throw new API_Exception('You do not have permission to create this line item');
+    }
   }
-  if (in_array($params['financial_type_id'], array_keys($types))) {
-    $params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params, TRUE);
-    return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
-  }
-  else {
-    throw new API_Exception('You do not have permission to create this line item');
-  }
+  $params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params, TRUE);
+  return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
 }
 
 /**
@@ -114,5 +116,17 @@ function civicrm_api3_line_item_get($params) {
  *   API result array
  */
 function civicrm_api3_line_item_delete($params) {
+  if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
+    CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types);
+    if (empty($params['financial_type_id'])) {
+      $params['financial_type_id'] = civicrm_api3('LineItem', 'getvalue', array(
+        'id' => $params['id'],
+        'return' => 'financial_type_id',
+      ));
+    }
+    if (!in_array($params['financial_type_id'], array_keys($types))) {
+      throw new API_Exception('You do not have permission to delete this line item');
+    }
+  }
   return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
-}
+}
\ No newline at end of file