From 1b5fad8a3bf0f3dce72317c780ea8488bda76240 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 5 Jul 2015 14:42:51 -0400 Subject: [PATCH] CRM-9386 - Fix api saving inherited memberships --- CRM/Contact/BAO/Relationship.php | 2 +- tests/phpunit/api/v3/MembershipTest.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/Relationship.php b/CRM/Contact/BAO/Relationship.php index c026062f0f..c8f5362d5f 100644 --- a/CRM/Contact/BAO/Relationship.php +++ b/CRM/Contact/BAO/Relationship.php @@ -696,7 +696,7 @@ class CRM_Contact_BAO_Relationship extends CRM_Contact_DAO_Relationship { public static function disableEnableRelationship($id, $action, $params = array(), $ids = array(), $active = FALSE) { $relationship = self::clearCurrentEmployer($id, $action); - if (CRM_Core_Permission::access('CiviMember')) { + if ($id) { // create $params array which is required to delete memberships // of the related contacts. if (empty($params)) { diff --git a/tests/phpunit/api/v3/MembershipTest.php b/tests/phpunit/api/v3/MembershipTest.php index 8c0fbdc6a7..aa5d0937a2 100644 --- a/tests/phpunit/api/v3/MembershipTest.php +++ b/tests/phpunit/api/v3/MembershipTest.php @@ -580,6 +580,11 @@ class api_v3_MembershipTest extends CiviUnitTestCase { $result = $this->callAPISuccess('membership', 'get', $params); $this->assertEquals(1, $result['count']); + // Delete relationship and assert membership is not inherited + $this->callAPISuccess('relationship', 'delete', array('id' => $relationship1['id'])); + $result = $this->callAPISuccess('membership', 'get', $params); + $this->assertEquals(0, $result['count']); + // Tear down - reverse of creation to be safe $this->contactDelete($memberContactId[2]); $this->contactDelete($memberContactId[1]); -- 2.25.1