From: Eileen McNaughton Date: Thu, 14 Dec 2023 06:56:35 +0000 (+1300) Subject: Move link handling to extension X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=65f0ca64610c6673eb1b2919746fd9bb844ed493;p=civicrm-core.git Move link handling to extension --- diff --git a/CRM/Contribute/Selector/Search.php b/CRM/Contribute/Selector/Search.php index fc755d92d8..180fbbbebf 100644 --- a/CRM/Contribute/Selector/Search.php +++ b/CRM/Contribute/Selector/Search.php @@ -357,35 +357,8 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C $qfKey, $componentContext ); - - $checkLineItem = FALSE; // Set defaults to empty to prevent e-notices. $row = ['amount_level' => '']; - // Now check for lineItems - if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) { - $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($result->id); - foreach ($lineItems as $items) { - if (!CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { - $checkLineItem = TRUE; - break; - } - if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { - unset($links[CRM_Core_Action::UPDATE]); - } - if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { - unset($links[CRM_Core_Action::DELETE]); - } - } - if ($checkLineItem) { - continue; - } - if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) { - unset($links[CRM_Core_Action::UPDATE]); - } - if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) { - unset($links[CRM_Core_Action::DELETE]); - } - } // the columns we are interested in foreach (self::$_properties as $property) { if (property_exists($result, $property)) { @@ -405,7 +378,7 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C ); $isPayLater = FALSE; - if ($result->is_pay_later && ($row['contribution_status_name'] ?? NULL) == 'Pending') { + if ($result->is_pay_later && ($row['contribution_status_name'] ?? NULL) === 'Pending') { $isPayLater = TRUE; $row['contribution_status'] .= ' (' . ts('Pay Later') . ')'; $links[CRM_Core_Action::ADD] = [ @@ -427,9 +400,10 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contribution_id; $actions = [ - 'id' => $result->contribution_id, - 'cid' => $result->contact_id, + 'id' => (int) $result->contribution_id, + 'cid' => (int) $result->contact_id, 'cxt' => $this->_context, + 'financial_type_id' => $result->financial_type_id ? (int) $result->financial_type_id : NULL, ]; if (in_array($row['contribution_status_name'], ['Partially paid', 'Pending refund']) || $isPayLater) { @@ -463,7 +437,7 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C FALSE, 'contribution.selector.row', 'Contribution', - $result->contribution_id + (int) $result->contribution_id ); $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id diff --git a/ext/financialacls/financialacls.php b/ext/financialacls/financialacls.php index e638def589..ed0c5bf7c7 100644 --- a/ext/financialacls/financialacls.php +++ b/ext/financialacls/financialacls.php @@ -447,6 +447,31 @@ function financialacls_civicrm_links(string $op, ?string $objectName, $objectID, } if ($objectName === 'MembershipType') { $financialType = CRM_Core_PseudoConstant::getName('CRM_Member_BAO_MembershipType', 'financial_type_id', CRM_Member_BAO_MembershipType::getMembershipType($objectID)['financial_type_id']); + } + if ($objectName === 'Contribution') { + // Now check for lineItems + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) { + $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID((int) $objectID); + foreach ($lineItems as $item) { + $financialType = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'financial_type_id', $item['financial_type_id']); + if (!CRM_Core_Permission::check('view contributions of type ' . $financialType)) { + // Remove all links & early return for this contribution if there is an un-viewable financial type. + $links = []; + return; + } + if (!CRM_Core_Permission::check('edit contributions of type ' . $financialType)) { + unset($links[CRM_Core_Action::UPDATE]); + } + if (!CRM_Core_Permission::check('delete contributions of type ' . $financialType)) { + unset($links[CRM_Core_Action::DELETE]); + } + } + $financialTypeID = $values['financial_type_id'] ?? CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $objectID, 'financial_type_id'); + $financialType = CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'financial_type_id', $financialTypeID); + } + } + + if (!empty($financialType)) { $hasEditPermission = CRM_Core_Permission::check('edit contributions of type ' . $financialType); $hasDeletePermission = CRM_Core_Permission::check('delete contributions of type ' . $financialType); if (!$hasDeletePermission || !$hasEditPermission) {