Move (now tested) delete acl check from v3 api to pre delete hook
authoreileen <emcnaughton@wikimedia.org>
Fri, 28 Aug 2020 04:08:56 +0000 (16:08 +1200)
committereileen <emcnaughton@wikimedia.org>
Fri, 28 Aug 2020 22:45:42 +0000 (10:45 +1200)
api/v3/LineItem.php
ext/financialacls/financialacls.php

index a5e5f34ff37dd76ab19b455e36b65ed1ef6ad606..f5b47a5e86f9a7dc0bb09084b69115f760bb0ec3 100644 (file)
@@ -75,18 +75,11 @@ function civicrm_api3_line_item_get($params) {
  *
  * @param array $params
  *   Array containing id of the group to be deleted.
+ *
  * @return array API result array
  * @throws API_Exception
+ * @throws \CiviCRM_API3_Exception
  */
 function civicrm_api3_line_item_delete($params) {
-  if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !empty($params['check_permissions'])) {
-    CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, CRM_Core_Action::DELETE);
-    if (empty($params['financial_type_id'])) {
-      $params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_LineItem', $params['id'], '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);
 }
index e6c39a0ab06890039330ed41417adcc8bf759428..dda05b28f659f4f17086938c7236f93f5c0b9030 100644 (file)
@@ -143,6 +143,31 @@ function financialacls_civicrm_themes(&$themes) {
   _financialacls_civix_civicrm_themes($themes);
 }
 
+/**
+ * Intervene to prevent deletion, where permissions block it.
+ *
+ * @param \CRM_Core_DAO $op
+ * @param string $objectName
+ * @param int|null $id
+ * @param array $params
+ *
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ */
+function financialacls_civicrm_pre($op, $objectName, $id, &$params) {
+  if ($objectName === 'LineItem' && $op === 'delete' && !empty($params['check_permissions'])) {
+    if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
+      CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, CRM_Core_Action::DELETE);
+      if (empty($params['financial_type_id'])) {
+        $params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_LineItem', $params['id'], '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');
+      }
+    }
+  }
+}
+
 // --- Functions below this ship commented out. Uncomment as required. ---
 
 /**