mailing#70 Don't create users for test mail if user doesn't have permission
authorJon Goldberg <jon@megaphonetech.com>
Thu, 16 Jul 2020 20:26:59 +0000 (16:26 -0400)
committerJon Goldberg <jon@megaphonetech.com>
Thu, 16 Jul 2020 20:26:59 +0000 (16:26 -0400)
ang/crmMailing/services.js
api/v3/Mailing.php

index 45c206373230e3a0002834b5ec657f8b7a4d0ed2..3dbbf9ae985a4fe78823be4c4765f55862b7836f 100644 (file)
             .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.'));
               }
             })
           ;
index 011a19f149ef88d2570850dbc7f3166d4ec59ce7..756cf75ab823b438455be3ec686c011aa7969b62 100644 (file)
@@ -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,
+          ]
+        );
+      }
     }
   }