Revert Matt's fix for dev/membership#24 as it is incomplete and add a unit test in...
authorSeamus Lee <seamuslee001@gmail.com>
Sun, 31 May 2020 22:13:36 +0000 (08:13 +1000)
committerSeamus Lee <seamuslee001@gmail.com>
Sun, 31 May 2020 22:13:36 +0000 (08:13 +1000)
CRM/Member/BAO/Membership.php
CRM/Member/Page/Tab.php
tests/phpunit/api/v3/FinancialTypeACLTest.php

index 90e68000ee0ad2dd91485636b5d845c73ada3744..df5e17a48d3cd6e45c4d338f5531315dd2cc3a96 100644 (file)
@@ -1579,6 +1579,11 @@ WHERE  civicrm_membership.contact_id = civicrm_contact.id
    * @return null|string
    */
   public static function getContactMembershipCount($contactID, $activeOnly = FALSE) {
+    CRM_Financial_BAO_FinancialType::getAvailableMembershipTypes($membershipTypes);
+    $addWhere = " AND membership_type_id IN (0)";
+    if (!empty($membershipTypes)) {
+      $addWhere = " AND membership_type_id IN (" . implode(',', array_keys($membershipTypes)) . ")";
+    }
     $select = "SELECT count(*) FROM civicrm_membership ";
     $where = "WHERE civicrm_membership.contact_id = {$contactID} AND civicrm_membership.is_test = 0 ";
 
@@ -1588,7 +1593,7 @@ WHERE  civicrm_membership.contact_id = civicrm_contact.id
       $where .= " and civicrm_membership_status.is_current_member = 1";
     }
 
-    $query = $select . $where;
+    $query = $select . $where . $addWhere;
     return CRM_Core_DAO::singleValueQuery($query);
   }
 
index 7c4ad24d143ac0f18572ff28cba266b88e0a7206..6818490f1784aa640fea28f2aa75d84234cb15e1 100644 (file)
@@ -33,9 +33,17 @@ class CRM_Member_Page_Tab extends CRM_Core_Page {
    * called when action is browse.
    */
   public function browse() {
+    $links = self::links('all', $this->_isPaymentProcessor, $this->_accessContribution);
+    CRM_Financial_BAO_FinancialType::getAvailableMembershipTypes($membershipTypes);
+    $addWhere = "membership_type_id IN (0)";
+    if (!empty($membershipTypes)) {
+      $addWhere = "membership_type_id IN (" . implode(',', array_keys($membershipTypes)) . ")";
+    }
+
     $membership = [];
     $dao = new CRM_Member_DAO_Membership();
     $dao->contact_id = $this->_contactId;
+    $dao->whereAdd($addWhere);
     $dao->find();
 
     //CRM--4418, check for view, edit, delete
index a5c22596d7797c9402099f42d30833618bbc9e91..7aa516ebd47191325edffd2845efe2448739e9d9 100644 (file)
@@ -316,4 +316,20 @@ class api_v3_FinancialTypeACLTest extends CiviUnitTestCase {
     $this->assertEquals($contribution['count'], 1);
   }
 
+  public function testMembersipTypeACLFinancialTypeACL() {
+    $contactID = $this->individualCreate();
+    $this->contactMembershipCreate(['contact_id' => $contactID]);
+    $this->enableFinancialACLs();
+    $this->setPermissions([
+      'access CiviCRM',
+      'access CiviContribute',
+      'view all contacts',
+      'add contributions of type Donation',
+      'view contributions of type Donation',
+    ]);
+    $this->assertEquals(0, CRM_Member_BAO_Membership::getContactMembershipCount($contactID));
+    $this->addFinancialAclPermissions([['view', 'Member Dues']]);
+    $this->assertEquals(1, CRM_Member_BAO_Membership::getContactMembershipCount($contactID));
+  }
+
 }