From ad268ba4407838eea3deb2dd98515ac65bc45be6 Mon Sep 17 00:00:00 2001 From: Edsel Date: Wed, 8 Apr 2015 18:16:25 +0530 Subject: [PATCH] CIVI-28 Added permissions for memberrship types --- CRM/Contribute/Selector/Search.php | 4 ++-- CRM/Financial/BAO/FinancialType.php | 3 ++- CRM/Member/Form/Membership.php | 8 +++++++- CRM/Member/Form/MembershipType.php | 9 +++++++-- CRM/Member/Page/MembershipType.php | 14 ++++++++++++-- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CRM/Contribute/Selector/Search.php b/CRM/Contribute/Selector/Search.php index 8388849c1f..00159b7d92 100644 --- a/CRM/Contribute/Selector/Search.php +++ b/CRM/Contribute/Selector/Search.php @@ -388,10 +388,10 @@ class CRM_Contribute_Selector_Search extends CRM_Core_Selector_Base implements C continue; } if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) { - unset($links[2]); + 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[8]); + unset($links[CRM_Core_Action::DELETE]); } // the columns we are interested in foreach (self::$_properties as $property) { diff --git a/CRM/Financial/BAO/FinancialType.php b/CRM/Financial/BAO/FinancialType.php index 008211f65d..6db839ab57 100644 --- a/CRM/Financial/BAO/FinancialType.php +++ b/CRM/Financial/BAO/FinancialType.php @@ -181,9 +181,10 @@ class CRM_Financial_BAO_FinancialType extends CRM_Financial_DAO_FinancialType { ); foreach ($financialType as $key => $financialTypeName) { - if (!in_array($key, $revenueFinancialType)) { + if (!in_array($key, $revenueFinancialType) || !CRM_Core_Permission::check('add contributions of type ' . $financialTypeName)) { unset($financialType[$key]); } + } return $financialType; } diff --git a/CRM/Member/Form/Membership.php b/CRM/Member/Form/Membership.php index 73f5a1b2ef..ea6446ebdf 100644 --- a/CRM/Member/Form/Membership.php +++ b/CRM/Member/Form/Membership.php @@ -657,9 +657,15 @@ class CRM_Member_Form_Membership extends CRM_Member_Form { //add field for amount to allow an amount to be entered that differs from minimum $this->add('text', 'total_amount', ts('Amount')); } + if (CRM_Core_Action::ADD & $this->_action) { + $op = 'add'; + } + else if (CRM_Core_Action::UPDATE & $this->_action) { + $op = 'edit'; + } $this->add('select', 'financial_type_id', ts('Financial Type'), - array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType() + array('' => ts('- select -')) + CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $op) ); $this->addElement('checkbox', 'is_different_contribution_contact', ts('Record Payment from a Different Contact?')); diff --git a/CRM/Member/Form/MembershipType.php b/CRM/Member/Form/MembershipType.php index 67eda46ef3..722df00d7d 100644 --- a/CRM/Member/Form/MembershipType.php +++ b/CRM/Member/Form/MembershipType.php @@ -167,9 +167,14 @@ class CRM_Member_Form_MembershipType extends CRM_Member_Form_MembershipConfig { $this->add('date', 'month_fixed_period_rollover_day', ts('Fixed Period Rollover Day'), CRM_Core_SelectValues::date(NULL, 'd'), FALSE ); - + if (CRM_Core_Action::ADD & $this->_action) { + $op = 'add'; + } + else if (CRM_Core_Action::UPDATE & $this->_action) { + $op = 'edit'; + } $this->add('select', 'financial_type_id', ts('Financial Type'), - array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), TRUE, array('class' => 'crm-select2') + array('' => ts('- select -')) + CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $op), TRUE, array('class' => 'crm-select2') ); $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE); diff --git a/CRM/Member/Page/MembershipType.php b/CRM/Member/Page/MembershipType.php index d66d6f8ada..7e620b3145 100644 --- a/CRM/Member/Page/MembershipType.php +++ b/CRM/Member/Page/MembershipType.php @@ -114,8 +114,12 @@ 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))) { + continue; + } + $links = self::links(); $membershipType[$dao->id] = array(); - CRM_Core_DAO::storeValues($dao, $membershipType[$dao->id]); + CRM_Core_DAO::storeValues($dao, $membershipType[$dao->id]); $membershipType[$dao->id]['period_type'] = CRM_Utils_Array::value($dao->period_type, CRM_Core_SelectValues::periodType(), ''); $membershipType[$dao->id]['visibility'] = CRM_Utils_Array::value($dao->visibility, CRM_Core_SelectValues::memberVisibility(), ''); @@ -137,6 +141,12 @@ 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))) { + 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))) { + unset($links[CRM_Core_Action::DELETE]); + } // form all action links $action = array_sum(array_keys($this->links())); @@ -149,7 +159,7 @@ class CRM_Member_Page_MembershipType extends CRM_Core_Page { $action -= CRM_Core_Action::DISABLE; } $membershipType[$dao->id]['order'] = $membershipType[$dao->id]['weight']; - $membershipType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, + $membershipType[$dao->id]['action'] = CRM_Core_Action::formLink($links, $action, array('id' => $dao->id), ts('more'), FALSE, -- 2.25.1