Skip to content

Commit

Permalink
Merge pull request #9797 from seamuslee001/CRM-19979
Browse files Browse the repository at this point in the history
CRM-19979 Fix issue where contacts cannot be removed from group or deleted if in status of pending
  • Loading branch information
eileenmcnaughton authored Feb 9, 2017
2 parents 4340d1e + bd9042d commit 4af6fbb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
6 changes: 3 additions & 3 deletions api/v3/GroupContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ function civicrm_api3_group_contact_create($params) {
function civicrm_api3_group_contact_delete($params) {
$checkParams = $params;
if (!empty($checkParams['status']) && in_array($checkParams['status'], array('Removed', 'Deleted'))) {
$checkParams['status'] = 'Added';
$checkParams['status'] = array('IN' => array('Added', 'Pending'));
}
elseif (!empty($checkParams['status']) && $checkParams['status'] == 'Added') {
$checkParams['status'] = 'Removed';
$checkParams['status'] = array('IN' => array('Pending', 'Removed'));
}
elseif (!empty($checkParams['status'])) {
unset($checkParams['status']);
}
$groupContact = civicrm_api3('GroupContact', 'get', $checkParams);
if ($groupContact['count'] == 0 && !empty($params['skip_undelete'])) {
$checkParams['status'] = 'removed';
$checkParams['status'] = array('IN' => array('Removed', 'Pending'));
}
$groupContact2 = civicrm_api3('GroupContact', 'get', $checkParams);
if ($groupContact['count'] == 0 && $groupContact2['count'] == 0) {
Expand Down
47 changes: 47 additions & 0 deletions tests/phpunit/api/v3/GroupContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,53 @@ public function testDeleteAndReAddWithId() {
$this->assertEquals($result2['total_count'], 1);
}

/**
* CRM-19979 test that group cotnact delete action works when contact is in status of pendin.
*/
public function testDeleteWithPending() {
$groupId3 = $this->groupCreate(array(
'name' => 'Test Group 3',
'domain_id' => 1,
'title' => 'New Test Group3 Created',
'description' => 'New Test Group3 Created',
'is_active' => 1,
'visibility' => 'User and User Admin Only',
));
$groupContactCreateParams = array(
'contact_id' => $this->_contactId,
'group_id' => $groupId3,
'status' => 'Pending',
);
$groupContact = $this->callAPISuccess('groupContact', 'create', $groupContactCreateParams);
$groupGetContact = $this->CallAPISuccess('groupContact', 'get', $groupContactCreateParams);
$this->callAPISuccess('groupContact', 'delete', array('id' => $groupGetContact['id'], 'status' => 'Removed'));
$this->callAPISuccess('groupContact', 'delete', array('id' => $groupGetContact['id'], 'skip_undelete' => TRUE));
$this->callAPISuccess('group', 'delete', array('id' => $groupId3));
}

/**
* CRM-19979 test that group cotnact delete action works when contact is in status of pendin and is a permanent delete.
*/
public function testPermanentDeleteWithPending() {
$groupId3 = $this->groupCreate(array(
'name' => 'Test Group 3',
'domain_id' => 1,
'title' => 'New Test Group3 Created',
'description' => 'New Test Group3 Created',
'is_active' => 1,
'visibility' => 'User and User Admin Only',
));
$groupContactCreateParams = array(
'contact_id' => $this->_contactId,
'group_id' => $groupId3,
'status' => 'Pending',
);
$groupContact = $this->callAPISuccess('groupContact', 'create', $groupContactCreateParams);
$groupGetContact = $this->CallAPISuccess('groupContact', 'get', $groupContactCreateParams);
$this->callAPISuccess('groupContact', 'delete', array('id' => $groupGetContact['id'], 'skip_undelete' => TRUE));
$this->callAPISuccess('group', 'delete', array('id' => $groupId3));
}

/**
* CRM-16945 duplicate groups are showing up when contacts are hard-added to child groups or smart groups.
*
Expand Down

0 comments on commit 4af6fbb

Please sign in to comment.