ACL - Ensure all priorities are unique
authorcolemanw <coleman@civicrm.org>
Thu, 22 Jun 2023 21:04:27 +0000 (14:04 -0700)
committercolemanw <coleman@civicrm.org>
Thu, 22 Jun 2023 21:04:27 +0000 (14:04 -0700)
CRM/ACL/Form/ACL.php
CRM/Upgrade/Incremental/sql/5.64.alpha1.mysql.tpl
Civi/Api4/ACL.php
templates/CRM/ACL/Form/ACL.tpl
templates/CRM/ACL/Page/ACL.tpl

index 4ac78946d102014bf62df045811ad1ea9ccbf28b..a86ebb1fcb864a1c3a24ad778d7935d35ed027e0 100644 (file)
@@ -29,7 +29,8 @@ class CRM_ACL_Form_ACL extends CRM_Admin_Form {
 
     if ($this->_action & CRM_Core_Action::ADD) {
       $defaults['object_type'] = 1;
-      $defaults['priority'] = 0;
+      $defaults['deny'] = 0;
+      $defaults['priority'] = 1 + CRM_Utils_Weight::getMax(CRM_ACL_DAO_ACL::class, NULL, 'priority');
     }
 
     $showHide = new CRM_Core_ShowHideBlocks();
@@ -164,8 +165,8 @@ class CRM_ACL_Form_ACL extends CRM_Admin_Form {
     $this->addRadio('deny', ts('Mode'), [
       0 => ts('Allow'),
       1 => ts('Deny'),
-    ]);
-    $this->add('number', 'priority', ts('Priority'));
+    ], [], NULL, TRUE);
+    $this->add('number', 'priority', ts('Priority'), ['min' => 1], TRUE);
 
     $this->addFormRule(['CRM_ACL_Form_ACL', 'formRule']);
   }
@@ -288,6 +289,7 @@ class CRM_ACL_Form_ACL extends CRM_Admin_Form {
         $params['id'] = $this->_id;
       }
 
+      $params['priority'] = \CRM_Utils_Weight::updateOtherWeights(CRM_ACL_DAO_ACL::class, $this->_values['priority'] ?? NULL, $params['priority'], NULL, 'priority');
       CRM_ACL_BAO_ACL::writeRecord($params);
     }
   }
index 883b1a10f4c3f88bf0c6cdeaf5396d4334d3d2de..2fa75d0fbb9c01051f901f085115f70a87bb24de 100644 (file)
@@ -1,5 +1,7 @@
 {* file to handle db changes in 5.64.alpha1 during upgrade *}
 
+UPDATE `civicrm_acl` SET `priority` = `id`;
+
 -- fix mis-casing of field name. Note the php function doesn't permit the name change hence it is here
 -- but field is not localised.
 ALTER TABLE civicrm_uf_group
index 700aed13e8006d5f82d0781c101afb71e02400da..76c009424cfd19c02c2985fd28c88934009e6efa 100644 (file)
@@ -10,6 +10,8 @@
  */
 namespace Civi\Api4;
 
+use Civi\Api4\Generic\Traits\SortableEntity;
+
 /**
  * ACL (Access Control List).
  *
@@ -24,8 +26,10 @@ namespace Civi\Api4;
  * @searchable none
  * @see https://docs.civicrm.org/user/en/latest/initial-set-up/permissions-and-access-control
  * @since 5.19
+ * @orderBy priority
  * @package Civi\Api4
  */
 class ACL extends Generic\DAOEntity {
+  use SortableEntity;
 
 }
index d51c24a97f1c67e779b1ceb986e4616d310f917c..15cefe0ef5944da947829ddf6bbf34558d8cdcd2 100644 (file)
@@ -51,7 +51,7 @@
      </tr>
      <tr class="crm-acl-form-block-priority">
        <td class="label">{$form.priority.label}</td>
-       <td>{$form.priority.label}<br />
+       <td>{$form.priority.html}<br />
          <span class="description">{ts}Higher priority ACL rules will override lower priority rules{/ts}</span>
        </td>
      </tr>
index 3f3850fe2986d861d12462a496d75f3d6c0640b1..c867e1457e235c6128e1e5b8c6870966dc1d8fc2 100644 (file)
           <table id="options" class="display">
             <thead>
             <tr class="columnheader">
-              <th id="sortable">{ts}Role{/ts}</th>
+              <th>{ts}Role{/ts}</th>
               <th>{ts}Operation{/ts}</th>
               <th>{ts}Type of Data{/ts}</th>
               <th>{ts}Which Data{/ts}</th>
               <th>{ts}Description{/ts}</th>
               <th>{ts}Enabled?{/ts}</th>
               <th>{ts}Mode{/ts}</th>
-              <th>{ts}Priority{/ts}</th>
+              <th id="sortable">{ts}Priority{/ts}</th>
               <th></th>
             </tr>
             </thead>