From 58eb6eb80a24774d3b13d4347c270b4c535818cc Mon Sep 17 00:00:00 2001 From: Edsel Date: Tue, 14 Apr 2015 13:30:00 +0530 Subject: [PATCH] CIVI-28 Added check for lineitems and delete operations from actions --- CRM/Contribute/Form/Task/Delete.php | 36 ++++++++++++++++++++++++++++- CRM/Contribute/Selector/Search.php | 2 -- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/CRM/Contribute/Form/Task/Delete.php b/CRM/Contribute/Form/Task/Delete.php index 222eba1a96..eb0e485545 100644 --- a/CRM/Contribute/Form/Task/Delete.php +++ b/CRM/Contribute/Form/Task/Delete.php @@ -61,7 +61,41 @@ class CRM_Contribute_Form_Task_Delete extends CRM_Contribute_Form_Task { * Build the form object. */ public function buildQuickForm() { - $this->addDefaultButtons(ts('Delete Contributions'), 'done'); + $count = 0; + foreach ($this->_contributionIds as $key => $id) { + $finTypeID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $id, 'financial_type_id'); + if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($finTypeID))) { + unset($this->_contributionIds[$key]); + $count++; + } + // Now check for lineItems + if ($lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($id)) { + foreach ($lineItems as $items) { + if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { + unset($this->_contributionIds[$key]); + $count++; + break; + } + } + } + } + if ($count && empty($this->_contributionIds)) { + CRM_Core_Session::setStatus(ts('1 contribution could not be deleted.', array('plural' => '%count contributions could not be deleted.', 'count' => $count)), ts('Error'), 'error'); + $this->addButtons(array( + array( + 'type' => 'back', + 'name' => ts('Cancel'), + ), + ) + ); + } + elseif ($count && !empty($this->_contributionIds)) { + CRM_Core_Session::setStatus(ts('1 contribution will not be deleted.', array('plural' => '%count contributions will not be deleted.', 'count' => $count)), ts('Warning'), 'warning'); + $this->addDefaultButtons(ts('Delete Contributions'), 'done'); + } + else { + $this->addDefaultButtons(ts('Delete Contributions'), 'done'); + } } /** diff --git a/CRM/Contribute/Selector/Search.php b/CRM/Contribute/Selector/Search.php index 9d5fba445d..21aae9b0ab 100644 --- a/CRM/Contribute/Selector/Search.php +++ b/CRM/Contribute/Selector/Search.php @@ -374,11 +374,9 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C } if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { unset($links[CRM_Core_Action::UPDATE]); - break; } if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { unset($links[CRM_Core_Action::DELETE]); - break; } } if ($checkLineItem) { -- 2.25.1