Skip to content

Commit

Permalink
MAE-992: Fix restrict email recipients to contact involved with case
Browse files Browse the repository at this point in the history
  • Loading branch information
asem-compuco authored and olayiwola-compucorp committed Jan 10, 2023
1 parent c17424e commit 8c6a593
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 19 deletions.
4 changes: 2 additions & 2 deletions CRM/Civicase/Hook/BuildForm/HandleDraftActivities.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CRM_Civicase_Hook_BuildForm_HandleDraftActivities {
];

const PDF_LETTER_FORM_NAME = 'CRM_Contact_Form_Task_PDF';
const EMAIL_FORM_NAME = 'CRM_Contact_Form_Task_Email';
const EMAIL_FORM_NAME = 'CRM_Case_Form_Task_Email';
const SPECIAL_FORMS = [
self::PDF_LETTER_FORM_NAME,
self::EMAIL_FORM_NAME,
Expand Down Expand Up @@ -96,7 +96,7 @@ private function addSaveDraftButton(CRM_Core_Form &$form, $formName) {
'id' => $id,
'return' => 'case_id',
]);
$composeUrl = CRM_Utils_System::url("civicrm/activity/$atype/add", [
$composeUrl = CRM_Utils_System::url("civicrm/case/$atype/add", [
'action' => 'add',
'reset' => 1,
'caseId' => $caseId['case_id'][0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function limitRecipientFields(CRM_Core_Form &$form) {
*/
private function shouldRun($formName) {
return (
$formName === CRM_Contact_Form_Task_Email::class &&
$formName === CRM_Case_Form_Task_Email::class &&
CRM_Utils_Array::value('caseRolesBulkEmail', $_GET, '0') === '1' &&
CRM_Utils_Array::value('snippet', $_GET, '0') === CRM_Core_Smarty::PRINT_JSON &&
CRM_Utils_Array::value('cid', $_GET, '0') &&
Expand Down
6 changes: 3 additions & 3 deletions CRM/Civicase/Hook/BuildForm/RestrictCaseEmailContacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function run(CRM_Core_Form $form, $formName) {
* True when the hook can run.
*/
private function shouldRun() {
$isEmailForm = get_class($this->form) === CRM_Contact_Form_Task_Email::class;
$isCaseEmail = !empty($this->form->getVar('_caseId'));
$isEmailForm = get_class($this->form) === CRM_Case_Form_Task_Email::class;
$isCaseEmail = !empty(CRM_Utils_Request::retrieve('caseid', 'Positive'));
$shouldRestrictContacts = (bool) Civi::settings()->get('civicaseRestrictCaseEmailContacts');
$isBulkEmail = CRM_Utils_Array::value('caseRolesBulkEmail', $_GET, '0') === '1';

Expand All @@ -56,7 +56,7 @@ private function shouldRun() {
* switching cases or updating the contacts for the existing one.
*/
private function addListOfCaseContactsToSettings() {
$caseId = $this->form->getVar('_caseId');
$caseId = CRM_Utils_Request::retrieve('caseid', 'Positive');

$caseDetailsResponse = civicrm_api3('Case', 'getdetails', [
'id' => $caseId,
Expand Down
4 changes: 2 additions & 2 deletions CRM/Civicase/Hook/BuildForm/TokenTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function run(CRM_Core_Form &$form, $formName) {
if (!$this->shouldRun($formName)) {
return;
}
$this->isEmailForm = $form instanceof CRM_Contact_Form_Task_Email;
$this->isEmailForm = $form instanceof CRM_Case_Form_Task_Email;
$this->setAllRelevantCustomFields();
$this->attachNewTokenTreeToForm($form);
}
Expand Down Expand Up @@ -479,7 +479,7 @@ private function shouldRun($formName) {
return CRM_Utils_Request::retrieve('caseid', 'Integer') &&
in_array(
$formName,
[CRM_Contact_Form_Task_Email::class, CRM_Contact_Form_Task_PDF::class]
[CRM_Case_Form_Task_Email::class, CRM_Contact_Form_Task_PDF::class]
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function addActivityToAllSelectedCases() {
* Whether the hook should run or not.
*/
private function shouldRun($formName) {
return $formName === CRM_Contact_Form_Task_Email::class &&
return $formName === CRM_Case_Form_Task_Email::class &&
!empty(CRM_Utils_Array::value('allCaseIds', $_GET, '0')) &&
!empty(CRM_Utils_Array::value('caseid', $_GET, '0'));
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Civicase/Hook/PostProcess/HandleDraftActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function markPdfActivityAsComplete($form, $draftActivityID) {
* Whether the hook should run or not.
*/
private function shouldRun($formName, $urlParams) {
$specialForms = ['CRM_Contact_Form_Task_PDF', 'CRM_Contact_Form_Task_Email'];
$specialForms = ['CRM_Contact_Form_Task_PDF', 'CRM_Case_Form_Task_Email'];

return in_array($formName, $specialForms) && !empty($urlParams['draft_id']);
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Civicase/Hook/ValidateForm/SaveActivityDraft.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CRM_Civicase_Hook_ValidateForm_SaveActivityDraft {
*/
private $specialForms = [
'pdf' => 'CRM_Contact_Form_Task_PDF',
'email' => 'CRM_Contact_Form_Task_Email',
'email' => 'CRM_Case_Form_Task_Email',
];

/**
Expand Down Expand Up @@ -56,7 +56,7 @@ private function saveDraftForSpecialForms($formName, CRM_Core_Form &$form, array
// The validate stage provides an opportunity to bypass normal
// form processing, save the draft & return early.
$activityType = $form->getVar('_activityTypeId');
$caseId = $form->getVar('_caseId');
$caseId = CRM_Utils_Request::retrieve('caseid', 'String');
if (!$activityType) {
$activityType = $formName == 'CRM_Contact_Form_Task_PDF' ? 'Print PDF Letter' : 'Email';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@
draftFormParameters.caseid = activity.case_id;
}

var viewUrl = 'civicrm/activity/email/';
var addUrl = 'civicrm/case/email/';
var url = action === 'view' ? viewUrl : addUrl;

return civicaseCrmUrl(
'civicrm/activity/email/' + action,
url + action,
draftFormParameters
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
});

it('returns the popup form URL for the draft activity in create mode by default', () => {
expect(civicaseCrmUrl).toHaveBeenCalledWith('civicrm/activity/email/add',
expect(civicaseCrmUrl).toHaveBeenCalledWith('civicrm/case/email/add',
expectedActivityFormUrlParams);
});
});
Expand All @@ -83,7 +83,7 @@
});

it('returns the popup form URL for the draft activity in create mode by default', () => {
expect(civicaseCrmUrl).toHaveBeenCalledWith('civicrm/activity/email/add',
expect(civicaseCrmUrl).toHaveBeenCalledWith('civicrm/case/email/add',
expectedActivityFormUrlParams);
});
});
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Civicase/Hook/BuildForm/TokenTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ class CRM_Civicase_Hook_BuildForm_TokenTreeTest extends BaseHeadlessTest {
public function testRun() {
$this->setContactCustomFields();
$this->setCaseCustomFields();
$form = new CRM_Contact_Form_Task_Email();
$form = new CRM_Case_Form_Task_Email();
$form->assign('tokens', $this->getTokens());
$_GET['caseid'] = $_REQUEST['caseid'] = 1;
$hook = new TokenTree();
$hook->run($form, CRM_Contact_Form_Task_Email::class);
$hook->run($form, CRM_Case_Form_Task_Email::class);
$setting = CRM_Core_Resources::singleton()->getSettings();
$this->assertNotEmpty($setting['civicase-base']['custom_token_tree']);
$newTokenTree = $this->format(json_decode($setting['civicase-base']['custom_token_tree'], TRUE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function testHookAddActivitiesToAllSelectedCases() {
$_GET['allCaseIds'] = $_REQUEST['allCaseIds'] = $allCaseIds;

(new AttachEmailActivityToAllCases())->run(
CRM_Contact_Form_Task_Email::class,
new CRM_Contact_Form_Task_Email()
CRM_Case_Form_Task_Email::class,
new CRM_Case_Form_Task_Email()
);

foreach ($cases as $caseId) {
Expand Down

0 comments on commit 8c6a593

Please sign in to comment.