From 66af7c4817fd54aa36cac0599638a863c6b49e0a Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Sun, 12 Jul 2015 13:06:35 +0530 Subject: [PATCH] --ICM-17, added condition to check FT-ACL is turned off or on --- CRM/Contribute/Form/Contribution.php | 5 ++++- CRM/Contribute/Form/ContributionBase.php | 4 +++- CRM/Contribute/Form/ContributionPage.php | 2 +- CRM/Contribute/Form/ContributionView.php | 2 +- CRM/Contribute/Form/Task/Delete.php | 28 +++++++++++++----------- CRM/Member/Form/MembershipView.php | 11 ++++++---- CRM/Member/Page/MembershipType.php | 8 ++++--- CRM/Member/Page/Tab.php | 3 +++ CRM/Member/Selector/Search.php | 8 +++++-- CRM/Price/BAO/PriceSet.php | 16 ++++++++------ CRM/Price/Form/Field.php | 4 +++- CRM/Price/Form/Set.php | 4 +++- api/v3/Contribution.php | 6 +++-- 13 files changed, 64 insertions(+), 37 deletions(-) diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index e489f103cb..f116791538 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -459,7 +459,10 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP */ public function buildQuickForm() { // FIXME: This probably needs to be done in preprocess - if ($this->_action & CRM_Core_Action::UPDATE && CRM_Utils_Array::value('financial_type_id', $this->_values)) { + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() + && $this->_action & CRM_Core_Action::UPDATE + && CRM_Utils_Array::value('financial_type_id', $this->_values) + ) { $financialTypeID = CRM_Contribute_PseudoConstant::financialType($this->_values['financial_type_id']); CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($this->_id, 'edit'); if (!CRM_Core_Permission::check('edit contributions of type ' . $financialTypeID)) { diff --git a/CRM/Contribute/Form/ContributionBase.php b/CRM/Contribute/Form/ContributionBase.php index b5e6930caf..94d74ee782 100644 --- a/CRM/Contribute/Form/ContributionBase.php +++ b/CRM/Contribute/Form/ContributionBase.php @@ -274,7 +274,9 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form { $this->_fields = array(); CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values); - if (!CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($this->_values['financial_type_id']))) { + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() + && !CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($this->_values['financial_type_id'])) + ) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } if (empty($this->_values['is_active'])) { diff --git a/CRM/Contribute/Form/ContributionPage.php b/CRM/Contribute/Form/ContributionPage.php index 63c9f224bb..bab925650b 100644 --- a/CRM/Contribute/Form/ContributionPage.php +++ b/CRM/Contribute/Form/ContributionPage.php @@ -142,7 +142,7 @@ class CRM_Contribute_Form_ContributionPage extends CRM_Core_Form { } // Check permission to edit contribution page - if ($this->_action & CRM_Core_Action::UPDATE) { + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && $this->_action & CRM_Core_Action::UPDATE) { $financialTypeID = CRM_Contribute_PseudoConstant::financialType($this->_values['financial_type_id']); if (!CRM_Core_Permission::check('edit contributions of type ' . $financialTypeID)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); diff --git a/CRM/Contribute/Form/ContributionView.php b/CRM/Contribute/Form/ContributionView.php index 3101f4aab8..63e2eabb93 100644 --- a/CRM/Contribute/Form/ContributionView.php +++ b/CRM/Contribute/Form/ContributionView.php @@ -47,7 +47,7 @@ class CRM_Contribute_Form_ContributionView extends CRM_Core_Form { $this->assign('context', $context); CRM_Contribute_BAO_Contribution::getValues($params, $values, $ids); - if ($this->_action & CRM_Core_Action::VIEW) { + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && $this->_action & CRM_Core_Action::VIEW) { $financialTypeID = CRM_Contribute_PseudoConstant::financialType($values['financial_type_id']); CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($id, 'view'); if (CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($id, 'edit', FALSE)) { diff --git a/CRM/Contribute/Form/Task/Delete.php b/CRM/Contribute/Form/Task/Delete.php index eb0e485545..d68ca73a6a 100644 --- a/CRM/Contribute/Form/Task/Delete.php +++ b/CRM/Contribute/Form/Task/Delete.php @@ -62,19 +62,21 @@ class CRM_Contribute_Form_Task_Delete extends CRM_Contribute_Form_Task { */ public function buildQuickForm() { $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 (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) { + 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; + } } } } diff --git a/CRM/Member/Form/MembershipView.php b/CRM/Member/Form/MembershipView.php index 2700b1880b..21582c28ae 100644 --- a/CRM/Member/Form/MembershipView.php +++ b/CRM/Member/Form/MembershipView.php @@ -160,10 +160,13 @@ class CRM_Member_Form_MembershipView extends CRM_Core_Form { $params = array('id' => $id); CRM_Member_BAO_Membership::retrieve($params, $values); - $finTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $values['membership_type_id'], 'financial_type_id'); - $finType = CRM_Contribute_PseudoConstant::financialType($finTypeId); - if (!CRM_Core_Permission::check('view contributions of type ' . $finType)) { - CRM_Core_Error::fatal(ts('You do not have permissionn to access this page.')); + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) { + $finTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $values['membership_type_id'], 'financial_type_id'); + $finType = CRM_Contribute_PseudoConstant::financialType($finTypeId); + + if (!CRM_Core_Permission::check('view contributions of type ' . $finType)) { + CRM_Core_Error::fatal(ts('You do not have permissionn to access this page.')); + } } $this->assign('financialTypeId', $finType); $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']); diff --git a/CRM/Member/Page/MembershipType.php b/CRM/Member/Page/MembershipType.php index 7e620b3145..e6e642d6c5 100644 --- a/CRM/Member/Page/MembershipType.php +++ b/CRM/Member/Page/MembershipType.php @@ -114,7 +114,9 @@ class CRM_Member_Page_MembershipType extends CRM_Core_Page { $dao->find(); while ($dao->fetch()) { - if (!CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) { + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() + && !CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id)) + ) { continue; } $links = self::links(); @@ -141,10 +143,10 @@ class CRM_Member_Page_MembershipType extends CRM_Core_Page { } $membershipType[$dao->id]['maxRelated'] = CRM_Utils_Array::value('max_related', $membershipType[$dao->id]); } - if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) { + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) { unset($links[CRM_Core_Action::UPDATE], $links[CRM_Core_Action::ENABLE], $links[CRM_Core_Action::DISABLE]); } - if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) { + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) { unset($links[CRM_Core_Action::DELETE]); } // form all action links diff --git a/CRM/Member/Page/Tab.php b/CRM/Member/Page/Tab.php index bf6c4f940c..52c0823e2c 100644 --- a/CRM/Member/Page/Tab.php +++ b/CRM/Member/Page/Tab.php @@ -621,6 +621,9 @@ class CRM_Member_Page_Tab extends CRM_Core_Page { } static function getPermissionedLinks($memTypeID, &$links) { + if (!self::isACLFinancialTypeStatus()) { + return FALSE; + } $finTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $memTypeID, 'financial_type_id'); $finType = CRM_Contribute_PseudoConstant::financialType($finTypeId); if (!CRM_Core_Permission::check('edit contributions of type ' . $finType)) { diff --git a/CRM/Member/Selector/Search.php b/CRM/Member/Selector/Search.php index 8af8cb4890..e518a99e37 100644 --- a/CRM/Member/Selector/Search.php +++ b/CRM/Member/Selector/Search.php @@ -407,10 +407,14 @@ class CRM_Member_Selector_Search extends CRM_Core_Selector_Base implements CRM_C // check permissions $finTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $result->membership_type_id, 'financial_type_id'); $finType = CRM_Contribute_PseudoConstant::financialType($finTypeId); - if (!CRM_Core_Permission::check('edit contributions of type ' . $finType)) { + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() + && !CRM_Core_Permission::check('edit contributions of type ' . $finType) + ) { unset($links[CRM_Core_Action::UPDATE]); } - if (!CRM_Core_Permission::check('delete contributions of type ' . $finType)) { + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && + !CRM_Core_Permission::check('delete contributions of type ' . $finType) + ) { unset($links[CRM_Core_Action::DELETE]); } $row['action'] = CRM_Core_Action::formLink($links, diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 124a41af67..2f9d71b6e7 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -963,14 +963,16 @@ WHERE id = %1"; else { $feeBlock = &$form->_priceSet['fields']; } - foreach ($feeBlock as $key => $value) { - foreach ($value['options'] as $k => $options) { - if (!CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($options['financial_type_id']))) { - unset($feeBlock[$key]['options'][$k]); + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) { + foreach ($feeBlock as $key => $value) { + foreach ($value['options'] as $k => $options) { + if (!CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($options['financial_type_id']))) { + unset($feeBlock[$key]['options'][$k]); + } + } + if (empty($feeBlock[$key]['options'])) { + unset($feeBlock[$key]); } - } - if (empty($feeBlock[$key]['options'])) { - unset($feeBlock[$key]); } } // call the hook. diff --git a/CRM/Price/Form/Field.php b/CRM/Price/Form/Field.php index 3fa34874b6..0914a27657 100644 --- a/CRM/Price/Form/Field.php +++ b/CRM/Price/Form/Field.php @@ -183,7 +183,9 @@ class CRM_Price_Form_Field extends CRM_Core_Form { // Financial Type $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType(); foreach ($financialType as $finTypeId => $type) { - if (!CRM_Core_Permission::check('add contributions of type ' . $type)) { + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() + && !CRM_Core_Permission::check('add contributions of type ' . $type) + ) { unset($financialType[$finTypeId]); } } diff --git a/CRM/Price/Form/Set.php b/CRM/Price/Form/Set.php index 2563ef8da4..85f598ff38 100644 --- a/CRM/Price/Form/Set.php +++ b/CRM/Price/Form/Set.php @@ -192,7 +192,9 @@ class CRM_Price_Form_Set extends CRM_Core_Form { $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType(); foreach ($financialType as $finTypeId => $type) { - if (!CRM_Core_Permission::check('add contributions of type ' . $type)) { + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() + && !CRM_Core_Permission::check('add contributions of type ' . $type) + ) { unset($financialType[$finTypeId]); } } diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index a3705b8459..73b6b3230d 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -195,8 +195,10 @@ function civicrm_api3_contribution_delete($params) { $financialType = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionID, 'financial_type_id'); // Now check permissioned lineitems & permissioned contribution - if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($financialType)) || - !CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($contributionID, 'delete', FALSE)) { + if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() + && !CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($financialType)) || + !CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($contributionID, 'delete', FALSE) + ) { return civicrm_api3_create_error('You do not have permission to delete this contribution'); } if (CRM_Contribute_BAO_Contribution::deleteContribution($contributionID)) { -- 2.25.1