-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add / make fit for purpose email.getlist api call
The function CRM_Contact_Page_AJAX::getContactEmail is one of our earlier ajax attempts & this approach has been largely replaced with entity Reference fields. In order to switch over we need to bring Email.getlist api to parity which means 1) searching on sortname first, if less than 10 results on emails include emails 2) appropriate respect for includeWildCardInName (this should already be in the generic getlist) 3) filter out on_hold, is_deceased, do_not_email 4) acl support (should already be part of the api). The trickiest of these to support is the first - because we need to avoid using a non-performant OR My current solution is the idea of a fallback field to search if the search results are less than the limit. in most cases this won't require a second query but when it does it should be fairly quick.
- Loading branch information
1 parent
834f0bd
commit dace9ba
Showing
6 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Add / make fit for purpose email.getlist api call | ||
|
||
The function CRM_Contact_Page_AJAX::getContactEmail is one of our earlier ajax attempts & this approach has been largely | ||
replaced with entity Reference fields. In order to switch over we need to bring Email.getlist api to parity which means | ||
1) searching on sortname first, if less than 10 results on emails include emails | ||
2) appropriate respect for includeWildCardInName (this should already be in the generic getlist) | ||
3) filter out on_hold, is_deceased, do_not_email | ||
4) acl support (should already be part of the api). | ||
|
||
The trickiest of these to support is the first - because we need to avoid using a non-performant OR | ||
My current solution is the idea of a fallback field to search if the search results are less than the limit. | ||
in most cases this won't require a second query but when it does it should be fairly quick. | ||
|
||
# Please enter the commit message for your changes. Lines starting | ||
# with '#' will be ignored, and an empty message aborts the commit. | ||
# | ||
# Date: Mon Apr 6 15:48:00 2020 +1200 | ||
# | ||
# On branch emailget | ||
# Changes to be committed: | ||
# modified: api/v3/Email.php | ||
# modified: api/v3/Generic/Getlist.php | ||
# modified: tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php | ||
# modified: tests/phpunit/api/v3/ContactTest.php | ||
# modified: tests/phpunit/api/v3/EmailTest.php | ||
# | ||
# Changes not staged for commit: | ||
# modified: api/v3/Email.php | ||
# modified: templates/CRM/Contact/Form/Task/Email.tpl | ||
# modified: tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php | ||
# modified: tests/phpunit/api/v3/EmailTest.php | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,20 +14,27 @@ | |
*/ | ||
class CRM_Contact_Form_Task_EmailCommonTest extends CiviUnitTestCase { | ||
|
||
/** | ||
* Set up for tests. | ||
* | ||
* @throws \CRM_Core_Exception | ||
*/ | ||
protected function setUp() { | ||
parent::setUp(); | ||
$this->_contactIds = [ | ||
$this->individualCreate(['first_name' => 'Antonia', 'last_name' => 'D`souza']), | ||
$this->individualCreate(['first_name' => 'Anthony', 'last_name' => 'Collins']), | ||
]; | ||
$this->_optionValue = $this->callApiSuccess('optionValue', 'create', [ | ||
$this->_optionValue = $this->callAPISuccess('optionValue', 'create', [ | ||
'label' => '"Seamus Lee" <[email protected]>', | ||
'option_group_id' => 'from_email_address', | ||
]); | ||
} | ||
|
||
/** | ||
* Test generating domain emails | ||
* | ||
* @throws \CRM_Core_Exception | ||
*/ | ||
public function testDomainEmailGeneration() { | ||
$emails = CRM_Core_BAO_Email::domainEmails(); | ||
|
@@ -39,6 +46,13 @@ public function testDomainEmailGeneration() { | |
$this->assertEquals('"Seamus Lee" <[email protected]>', $optionValue['values'][$this->_optionValue['id']]['label']); | ||
} | ||
|
||
/** | ||
* Test email uses signature. | ||
* | ||
* @throws \CRM_Core_Exception | ||
* @throws \CiviCRM_API3_Exception | ||
* @throws \Civi\API\Exception\UnauthorizedException | ||
*/ | ||
public function testPostProcessWithSignature() { | ||
$mut = new CiviMailUtils($this, TRUE); | ||
Civi::settings()->set('allow_mail_from_logged_in_contact', 1); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -495,4 +495,26 @@ public function testSetBulkEmail() { | |
$this->assertEquals(1, $emails[$email2['id']]['is_bulkmail']); | ||
} | ||
|
||
/** | ||
* Test getlist. | ||
* | ||
* @throws \CRM_Core_Exception | ||
*/ | ||
public function testGetlist() { | ||
$name = 'Scarabée'; | ||
$emailMatchContactID = $this->individualCreate(['last_name' => $name, 'email' => '[email protected]']); | ||
$emailMatchEmailID = $this->callAPISuccessGetValue('Email', ['return' => 'id', 'contact_id' => $emailMatchContactID]); | ||
$this->individualCreate(['last_name' => $name, 'email' => '[email protected]', 'is_deceased' => 1]); | ||
$this->individualCreate(['last_name' => $name, 'email' => '[email protected]', 'is_deleted' => 1]); | ||
$this->individualCreate(['last_name' => $name, 'api.email.create' => ['email' => '[email protected]', 'on_hold' => 1]]); | ||
$this->individualCreate(['last_name' => $name, 'do_not_email' => 1, 'api.email.create' => ['email' => '[email protected]']]); | ||
$nameMatchContactID = $this->individualCreate(['last_name' => 'bob', 'email' => '[email protected]']); | ||
$nameMatchEmailID = $this->callAPISuccessGetValue('Email', ['return' => 'id', 'contact_id' => $nameMatchContactID]); | ||
// We should get only the active live email-able contact. | ||
$result = $this->callAPISuccess('Email', 'getlist', ['input' => 'bob'])['values']; | ||
$this->assertCount(2, $result); | ||
$this->assertEquals($nameMatchEmailID, $result[0]['id']); | ||
$this->assertEquals($emailMatchEmailID, $result[1]['id']); | ||
} | ||
|
||
} |