CRM-15854 - CiviMail workflow, new UI - Consistent interpretation of 'access CiviMail'
authorTim Otten <totten@civicrm.org>
Tue, 3 Mar 2015 02:11:58 +0000 (18:11 -0800)
committerTim Otten <totten@civicrm.org>
Tue, 3 Mar 2015 03:56:38 +0000 (19:56 -0800)
CRM/Core/DAO/permissions.php
CRM/Mailing/BAO/Mailing.php
CRM/Mailing/Info.php
api/v3/Mailing.php
js/angular-crmMailing/services.js
partials/crmMailing/edit-workflow.html

index bd31720c8218b174cddc8274632a8123a1b879ed..295c82566e90df25f24aa9ec7f66950c6ff31406 100644 (file)
@@ -238,19 +238,31 @@ function _civicrm_api3_permissions($entity, $action, &$params) {
   $permissions['group_organization'] = $permissions['group'];
 
   // CiviMail Permissions
+  $civiMailBasePerms = array(
+    // To get/preview/update, one must have least one of these perms:
+    // Mailing API implementations enforce nuances of create/approve/schedule permissions.
+    'access CiviMail',
+    'create mailings',
+    'schedule mailings',
+    'approve mailings',
+  );
   $permissions['mailing'] = array(
     'get' => array(
       'access CiviCRM',
-      'access CiviMail',
+      $civiMailBasePerms,
     ),
     'delete' => array(
       'access CiviCRM',
-      'access CiviMail',
+      $civiMailBasePerms,
       'delete in CiviMail',
     ),
+    'submit' => array(
+      'access CiviCRM',
+      array('access CiviMail', 'schedule mailings'),
+    ),
     'default' => array(
       'access CiviCRM',
-      'access CiviMail',
+      $civiMailBasePerms,
     ),
   );
   $permissions['mailing_a_b'] = $permissions['mailing'];
index 998a4d74bbbab481faf488585dba4447e95d8284..19e43393c733091fc566ab9f46578b1d291ed083 100644 (file)
@@ -1610,7 +1610,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
   public static function create(&$params, $ids = array()) {
     // WTH $ids
     if (empty($ids) && isset($params['id'])) {
-      $ids['id'] = $params['id'];
+      $ids['mailing_id'] = $ids['id'] = $params['id'];
     }
 
     // CRM-12430
@@ -3144,16 +3144,24 @@ AND        m.id = %1
     $fieldPerms = array();
     foreach ($fieldNames as $fieldName) {
       if ($fieldName == 'id') {
-        $fieldPerms[$fieldName] = 'access CiviMail';
+        $fieldPerms[$fieldName] = array(
+          array('access CiviMail', 'schedule mailings', 'approve mailings', 'create mailings'), // OR
+        );
       }
-      if (in_array($fieldName, array('scheduled_date', 'scheduled_id'))) {
-        $fieldPerms[$fieldName] = 'schedule mailings';
+      elseif (in_array($fieldName, array('scheduled_date', 'scheduled_id'))) {
+        $fieldPerms[$fieldName] = array(
+          array('access CiviMail', 'schedule mailings'), // OR
+        );
       }
       elseif (in_array($fieldName, array('approval_date', 'approver_id', 'approval_status_id', 'approval_note'))) {
-        $fieldPerms[$fieldName] = 'approve mailings';
+        $fieldPerms[$fieldName] = array(
+          array('access CiviMail', 'approve mailings'), // OR
+        );
       }
       else {
-        $fieldPerms[$fieldName] = 'create mailings';
+        $fieldPerms[$fieldName] = array(
+          array('access CiviMail', 'create mailings'), // OR
+        );
       }
     }
     return $fieldPerms;
index 8e306b979349768eb2c2c8503a5fc114fe6d1bc6..aefd0d23a4e18519e56806d1ecd4b78e5f7fee63 100644 (file)
@@ -149,6 +149,7 @@ class CRM_Mailing_Info extends CRM_Core_Component_Info {
     ));
     CRM_Core_Resources::singleton()->addPermissions(array(
       'view all contacts',
+      'access CiviMail',
       'create mailings',
       'schedule mailings',
       'approve mailings',
index 46a808a98b3e6edc447a4debb6b510b37b97e27b..5d4e0608025638ea76c9850a15af3a9b4d7d9565 100755 (executable)
  */
 function civicrm_api3_mailing_create($params) {
   if (CRM_Mailing_Info::workflowEnabled()) {
+    // Note: 'schedule mailings' and 'approve mailings' can update certain fields, but can't create.
+
+    if (empty($params['id'])) {
+      if (!CRM_Core_Permission::check('access CiviMail') && !CRM_Core_Permission::check('create mailings')) {
+        throw new \Civi\API\Exception\UnauthorizedException("Cannot create new mailing. Required permission: 'access CiviMail' or 'create mailings'");
+      }
+    }
+
     $safeParams = array();
     $fieldPerms = CRM_Mailing_BAO_Mailing::getWorkflowFieldPerms();
     foreach (array_keys($params) as $field) {
index deafdc5b64ca442946a94b0f52c4b569759eab54..cca3255b7ac7c85945870e418586626a667235bf 100644 (file)
       // @param mailing Object (per APIv3)
       // @return Promise an object with "subject", "body_text", "body_html"
       preview: function preview(mailing) {
-        if (CRM.crmMailing.workflowEnabled && !CRM.checkPerm('create mailings')) {
+        if (CRM.crmMailing.workflowEnabled && !CRM.checkPerm('create mailings') && !CRM.checkPerm('access CiviMail')) {
           return crmApi('Mailing', 'preview', {id: mailing.id}).then(function(result) {
             return result.values;
           });
index c0f1d6f92106f1f8d253ce1c26bbda8b082558d7..7b00de8fb26eb25e5f21238eb58a2cbc17074971 100644 (file)
@@ -11,7 +11,7 @@
 
     <div crm-ui-wizard>
 
-      <div crm-ui-wizard-step="10" crm-title="ts('Content')" ng-form="contentForm" ng-if="checkPerm('create mailings')">
+      <div crm-ui-wizard-step="10" crm-title="ts('Content')" ng-form="contentForm" ng-if="checkPerm('create mailings') || checkPerm('access CiviMail')">
         <div crm-mailing-block-summary crm-mailing="mailing"/>
         <div crm-mailing-block-mailing crm-mailing="mailing"/>
         <div crm-ui-accordion crm-title="ts('HTML')">
@@ -32,7 +32,7 @@
         </div>
       </div>
 
-      <div crm-ui-wizard-step="20" crm-title="ts('Options')" ng-form="optionsForm" ng-if="checkPerm('create mailings')">
+      <div crm-ui-wizard-step="20" crm-title="ts('Options')" ng-form="optionsForm" ng-if="checkPerm('create mailings') || checkPerm('access CiviMail')">
         <div crm-ui-accordion crm-title="ts('Responses')" crm-collapsed="true">
           <div crm-mailing-block-responses crm-mailing="mailing"/>
         </div>
         </div>
       </div>
 
-      <div crm-ui-wizard-step="40" crm-title="ts('Review')" ng-form="schedForm" ng-if="checkPerm('schedule mailings')">
+      <div crm-ui-wizard-step="40" crm-title="ts('Review')" ng-form="schedForm" ng-if="checkPerm('schedule mailings') || checkPerm('access CiviMail')">
         <div crm-ui-accordion crm-title="ts('Review')">
           <div crm-mailing-block-review crm-mailing="mailing"/>
         </div>
         <div crm-ui-accordion crm-title="ts('Schedule')">
           <div crm-mailing-block-schedule crm-mailing="mailing"/>
         </div>
-        <div crm-ui-accordion crm-title="ts('Approval')" ng-if="checkPerm('approve mailings')">
+        <div crm-ui-accordion crm-title="ts('Approval')" ng-if="checkPerm('approve mailings') || checkPerm('access CiviMail')">
           <div crm-mailing-block-approve crm-mailing="mailing"/>
         </div>
-        <center ng-if="!checkPerm('approve mailings')">
+        <center ng-if="!checkPerm('approve mailings') && !checkPerm('access CiviMail')">
           <a class="button crmMailing-submit-button" ng-click="submit()" ng-class="{blocking: block.check(), disabled: crmMailing.$invalid}">
             <div>{{ts('Submit Mailing')}}</div>
           </a>
         </center>
-        <center ng-if="checkPerm('approve mailings')">
+        <center ng-if="checkPerm('approve mailings') || checkPerm('access CiviMail')">
           <a class="button crmMailing-submit-button" ng-click="approve('Approved')" ng-class="{blocking: block.check(), disabled: crmMailing.$invalid}">
             <div>{{ts('Submit and Approve Mailing')}}</div>
           </a>