diff --git a/CRM/ACL/BAO/ACL.php b/CRM/ACL/BAO/ACL.php index c3dee1f46082..8ab4959f13ba 100644 --- a/CRM/ACL/BAO/ACL.php +++ b/CRM/ACL/BAO/ACL.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Api4\Utils\CoreUtil; + /** * * @package CRM @@ -529,4 +531,45 @@ private static function getGroupClause(array $groupIDs, string $operation): stri return ''; } + public static function getObjectTableOptions(): array { + return [ + 'civicrm_group' => ts('Group'), + 'civicrm_uf_group' => ts('Profile'), + 'civicrm_event' => ts('Event'), + 'civicrm_custom_group' => ts('Custom Group'), + ]; + } + + public static function getObjectIdOptions($context, $params): array { + if (empty($params['values']['object_table']) && empty($params['values']['object_table:label'])) { + return []; + } + if (!empty($params['values']['object_table:label'])) { + $table_name = array_flip(self::getObjectTableOptions())[$params['values']['object_table:label']]; + } + else { + $table_name = $params['values']['object_table']; + } + $finalOptions = []; + $entity = CoreUtil::getApiNameFromTableName($table_name); + $label = CoreUtil::getInfoItem($entity, 'label_field'); + $titlePlural = CoreUtil::getInfoItem($entity, 'title_plural'); + $finalOptions[] = [ + 'label' => ts('All %1', [1 => $titlePlural]), + 'id' => 0, + 'name' => 0, + ]; + $options = civicrm_api4($entity, 'get', [ + 'select' => [$label, 'id', 'name'], + ]); + foreach ($options as $option) { + $finalOptions[] = [ + 'label' => $option[$label], + 'id' => $option['id'], + 'name' => $option['name'] ?? $option['id'], + ]; + } + return $finalOptions; + } + } diff --git a/CRM/ACL/DAO/ACL.php b/CRM/ACL/DAO/ACL.php index 9683d71d3c78..ac13bb14c914 100644 --- a/CRM/ACL/DAO/ACL.php +++ b/CRM/ACL/DAO/ACL.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/ACL/ACL.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:689e7e5f58bb2cc9959817ecbbd3beeb) + * (GenCodeChecksum:79ed87b3613a7a626f02242218256dd1) */ /** @@ -294,6 +294,10 @@ public static function &fields() { 'entity' => 'ACL', 'bao' => 'CRM_ACL_BAO_ACL', 'localizable' => 0, + 'pseudoconstant' => [ + 'optionGroupName' => 'acl_role', + 'optionEditPath' => 'civicrm/admin/options/acl_role', + ], 'add' => '1.6', ], 'operation' => [ @@ -341,6 +345,9 @@ public static function &fields() { 'entity' => 'ACL', 'bao' => 'CRM_ACL_BAO_ACL', 'localizable' => 0, + 'pseudoconstant' => [ + 'callback' => 'CRM_ACL_BAO_ACL::getObjectTableOptions', + ], 'add' => '1.6', ], 'object_id' => [ @@ -359,6 +366,10 @@ public static function &fields() { 'entity' => 'ACL', 'bao' => 'CRM_ACL_BAO_ACL', 'localizable' => 0, + 'pseudoconstant' => [ + 'callback' => 'CRM_ACL_BAO_ACL::getObjectIdOptions', + 'prefetch' => 'false', + ], 'add' => '1.6', ], 'acl_table' => [ diff --git a/CRM/ACL/Form/ACL.php b/CRM/ACL/Form/ACL.php index 3f65d8d7bcbd..7282113225a0 100644 --- a/CRM/ACL/Form/ACL.php +++ b/CRM/ACL/Form/ACL.php @@ -132,7 +132,6 @@ public function buildQuickForm() { $label = ts('Role'); $role = [ '-1' => ts('- select role -'), - '0' => ts('Everyone'), ] + CRM_Core_OptionGroup::values('acl_role'); $this->add('select', 'entity_id', $label, $role, TRUE); diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 77dba37b849d..6d8375861b13 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -2776,17 +2776,17 @@ public static function appendPseudoConstantsToFields(&$fields) { * @param string $fieldName * @param string $context * @see CRM_Core_DAO::buildOptionsContext - * @param array $props + * @param array $values * Raw field values; whatever is known about this bao object. * * Note: $props can contain unsanitized input and should not be passed directly to CRM_Core_PseudoConstant::get * * @return array|bool */ - public static function buildOptions($fieldName, $context = NULL, $props = []) { + public static function buildOptions($fieldName, $context = NULL, $values = []) { // If a given bao does not override this function $baoName = get_called_class(); - return CRM_Core_PseudoConstant::get($baoName, $fieldName, [], $context); + return CRM_Core_PseudoConstant::get($baoName, $fieldName, ['values' => $values], $context); } /** diff --git a/CRM/Upgrade/Incremental/php/FiveSixtyFour.php b/CRM/Upgrade/Incremental/php/FiveSixtyFour.php index fdd22f175764..10d18a85d0b9 100644 --- a/CRM/Upgrade/Incremental/php/FiveSixtyFour.php +++ b/CRM/Upgrade/Incremental/php/FiveSixtyFour.php @@ -31,6 +31,7 @@ public function upgrade_5_64_alpha1($rev): void { $this->addTask('Add priority column onto ACL table', 'addColumn', 'civicrm_acl', 'priority', 'int NOT NULL DEFAULT 0'); $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); $this->addTask('Update post_URL/cancel_URL in logging tables', 'updateLogging'); + $this->addTask('Add in Everybody ACL Role option value', 'addEveryBodyAclOptionValue'); } public static function updateLogging($ctx): bool { @@ -44,4 +45,16 @@ public static function updateLogging($ctx): bool { return TRUE; } + public static function addEverybodyAclOptionValue($ctx): bool { + \CRM_Core_BAO_OptionValue::ensureOptionValueExists([ + 'label' => 'Everybody', + 'value' => 0, + 'option_group_id' => 'acl_role', + 'is_active' => 1, + 'name' => 'Everybody', + 'is_reserved' => 1, + ]); + return TRUE; + } + } diff --git a/Civi/Api4/ACL.php b/Civi/Api4/ACL.php index 76c009424cfd..2416179ee080 100644 --- a/Civi/Api4/ACL.php +++ b/Civi/Api4/ACL.php @@ -23,7 +23,6 @@ * * Creating a new ACL requires at minimum an entity table, entity ID and object_table. * - * @searchable none * @see https://docs.civicrm.org/user/en/latest/initial-set-up/permissions-and-access-control * @since 5.19 * @orderBy priority diff --git a/ext/civicrm_admin_ui/ang/afsearchManageACLs.aff.html b/ext/civicrm_admin_ui/ang/afsearchManageACLs.aff.html new file mode 100644 index 000000000000..4864c1fd40cd --- /dev/null +++ b/ext/civicrm_admin_ui/ang/afsearchManageACLs.aff.html @@ -0,0 +1,3 @@ +