From 18b1706ac849ce8965e2aec52c27bd754b524647 Mon Sep 17 00:00:00 2001 From: colemanw Date: Thu, 22 Jun 2023 14:04:27 -0700 Subject: [PATCH] ACL - Ensure all priorities are unique --- CRM/ACL/Form/ACL.php | 8 +++++--- CRM/Upgrade/Incremental/sql/5.64.alpha1.mysql.tpl | 2 ++ Civi/Api4/ACL.php | 4 ++++ templates/CRM/ACL/Form/ACL.tpl | 2 +- templates/CRM/ACL/Page/ACL.tpl | 4 ++-- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CRM/ACL/Form/ACL.php b/CRM/ACL/Form/ACL.php index 4ac78946d1..a86ebb1fcb 100644 --- a/CRM/ACL/Form/ACL.php +++ b/CRM/ACL/Form/ACL.php @@ -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); } } diff --git a/CRM/Upgrade/Incremental/sql/5.64.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/5.64.alpha1.mysql.tpl index 883b1a10f4..2fa75d0fbb 100644 --- a/CRM/Upgrade/Incremental/sql/5.64.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/5.64.alpha1.mysql.tpl @@ -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 diff --git a/Civi/Api4/ACL.php b/Civi/Api4/ACL.php index 700aed13e8..76c009424c 100644 --- a/Civi/Api4/ACL.php +++ b/Civi/Api4/ACL.php @@ -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; } diff --git a/templates/CRM/ACL/Form/ACL.tpl b/templates/CRM/ACL/Form/ACL.tpl index d51c24a97f..15cefe0ef5 100644 --- a/templates/CRM/ACL/Form/ACL.tpl +++ b/templates/CRM/ACL/Form/ACL.tpl @@ -51,7 +51,7 @@ {$form.priority.label} - {$form.priority.label}
+ {$form.priority.html}
{ts}Higher priority ACL rules will override lower priority rules{/ts} diff --git a/templates/CRM/ACL/Page/ACL.tpl b/templates/CRM/ACL/Page/ACL.tpl index 3f3850fe29..c867e1457e 100644 --- a/templates/CRM/ACL/Page/ACL.tpl +++ b/templates/CRM/ACL/Page/ACL.tpl @@ -24,14 +24,14 @@ - + - + -- 2.25.1
{ts}Role{/ts}{ts}Role{/ts} {ts}Operation{/ts} {ts}Type of Data{/ts} {ts}Which Data{/ts} {ts}Description{/ts} {ts}Enabled?{/ts} {ts}Mode{/ts}{ts}Priority{/ts}{ts}Priority{/ts}