From 302e4e03875fe291abdef4dedf8a15f8edd72aaf Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Thu, 16 Jul 2020 16:26:59 -0400 Subject: [PATCH] mailing#70 Don't create users for test mail if user doesn't have permission --- ang/crmMailing/services.js | 2 +- api/v3/Mailing.php | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/ang/crmMailing/services.js b/ang/crmMailing/services.js index 45c2063732..3dbbf9ae98 100644 --- a/ang/crmMailing/services.js +++ b/ang/crmMailing/services.js @@ -470,7 +470,7 @@ .then(function (deliveryInfos) { var count = Object.keys(deliveryInfos).length; if (count === 0) { - CRM.alert(ts('Could not identify any recipients. Perhaps the group is empty?')); + CRM.alert(ts('Could not identify any recipients. Perhaps your test group is empty, or you tried sending to contacts that do not exist and you have no permission to add contacts.')); } }) ; diff --git a/api/v3/Mailing.php b/api/v3/Mailing.php index 011a19f149..756cf75ab8 100644 --- a/api/v3/Mailing.php +++ b/api/v3/Mailing.php @@ -657,7 +657,7 @@ function civicrm_api3_mailing_send_test($params) { $emailId = $emailDetail[$email]['email_id']; $contactId = $emailDetail[$email]['contact_id']; } - if (!$contactId) { + if (!$contactId && CRM_Core_Permission::check('add contacts')) { //create new contact. $contact = civicrm_api3('Contact', 'create', [ @@ -669,13 +669,15 @@ function civicrm_api3_mailing_send_test($params) { $contactId = $contact['id']; $emailId = $contact['values'][$contactId]['api.Email.get']['id']; } - civicrm_api3('MailingEventQueue', 'create', - [ - 'job_id' => $job['id'], - 'email_id' => $emailId, - 'contact_id' => $contactId, - ] - ); + if ($emailId && $contactId) { + civicrm_api3('MailingEventQueue', 'create', + [ + 'job_id' => $job['id'], + 'email_id' => $emailId, + 'contact_id' => $contactId, + ] + ); + } } } -- 2.25.1