Skip to content

Commit

Permalink
fix(Addressbook/Contact): recipient token should not have duplicated …
Browse files Browse the repository at this point in the history
…email
  • Loading branch information
ccheng-dev committed Mar 15, 2024
1 parent a73e3be commit c9cfb33
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
39 changes: 39 additions & 0 deletions tests/tine20/Addressbook/Frontend/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2990,6 +2990,45 @@ public function testSearchEmailAddresssGroup()
static::assertEquals($list['email'], $result['results'][0]['email']);
}

/**
* Search email addresss with duplicated list member email
*/
public function testSearchEmailAddresssWithDuplicatedListMemberEmail()
{
$this->_skipWithoutEmailSystemAccountConfig();

$contact = $this->_addContact();
$contact['email'] = 'duplicate@mail.test';
$contact['email_home'] = $contact['email'];
$this->_uit->saveContact($contact);
$listRole = $this->_uit->saveListRole([
Addressbook_Model_ListRole::FLD_NAME => 'my test role with duplicated member email',
Addressbook_Model_ListRole::FLD_DESCRIPTION => 'my test description',
Addressbook_Model_ListRole::FLD_MAX_MEMBERS => 1,
]);
$memberroles = array(array(
'contact_id' => $contact['id'],
'list_role_id' => $listRole['id'],
));
$list = $this->_uit->saveList(array(
'name' => 'my test list',
'description' => '',
'members' => [$contact['id']],
'memberroles' => $memberroles,
'type' => Addressbook_Model_List::LISTTYPE_LIST,
));

$result = $this->_uit->searchEmailAddresss([
["condition" => "OR", "filters" => [["condition" => "AND", "filters" => [
["field" => "name_email_query", "operator" => "contains", "value" => $list['name']]
]], ["field" => "path", "operator" => "contains", "value" => ""]]]
], ["sort" => "name", "dir" => "ASC", "start" => 0, "limit" => 50]);

static::assertEquals(1, $result['totalcount'], 'no results found');
static::assertEquals($list['email'], $result['results'][0]['email']);
static::assertCount(1, $result['results'][0]['emails']);
}

/**
* testSaveContactWithAreaLockedRelation
*/
Expand Down
3 changes: 2 additions & 1 deletion tine20/Addressbook/Controller/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -1563,11 +1563,12 @@ public function getContactsRecipientToken(array $contacts): array
. " list member : " . $memberContact->n_fileas . " has no contact emails, skip.");
continue;
}

//we only get the first match email
$preferredEmail = $memberContact->getPreferredEmailAddress();
foreach ($memberPossibleAddresses as $memberPossibleAddress) {
if ($preferredEmail === $memberPossibleAddress['email']) {
$listMemberEmails[] = $memberPossibleAddress;
break;
}
}
}
Expand Down

0 comments on commit c9cfb33

Please sign in to comment.