Skip to content

Commit

Permalink
Add in PseudoConstants for various fields in ACL entity
Browse files Browse the repository at this point in the history
Add in Search Kit and form Builder display for ACLs

Update function titles following discussion with coleman and update translation in managed entity
  • Loading branch information
seamuslee001 committed Jun 23, 2023
1 parent 3867a13 commit bab8f74
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 5 deletions.
43 changes: 43 additions & 0 deletions CRM/ACL/BAO/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
+--------------------------------------------------------------------+
*/

use Civi\Api4\Utils\CoreUtil;

/**
*
* @package CRM
Expand Down Expand Up @@ -524,4 +526,45 @@ protected static function loadPermittedIDs(int $contactID, string $tableName, in
return $ids;
}

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::operationTables())[$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;
}

}
13 changes: 12 additions & 1 deletion CRM/ACL/DAO/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/ACL/ACL.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:689e7e5f58bb2cc9959817ecbbd3beeb)
* (GenCodeChecksum:79ed87b3613a7a626f02242218256dd1)
*/

/**
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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' => [
Expand All @@ -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' => [
Expand Down
6 changes: 3 additions & 3 deletions CRM/Core/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
1 change: 0 additions & 1 deletion Civi/Api4/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions ext/civicrm_admin_ui/ang/afsearchManageACLs.aff.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div af-fieldset="">
<crm-search-display-table search-name="Manage_ACLs" display-name="Manage_ACLs_Table_1"></crm-search-display-table>
</div>
8 changes: 8 additions & 0 deletions ext/civicrm_admin_ui/ang/afsearchManageACLs.aff.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "search",
"title": "Manage ACLs",
"icon": "fa-list-alt",
"server_route": "civicrm/acl",
"permission": "administer CiviCRM",
"navigation": null
}
179 changes: 179 additions & 0 deletions ext/civicrm_admin_ui/managed/SavedSearch_Manage_ACLs.mgd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php

use CRM_CivicrmAdminUi_ExtensionUtil as E;

return [
[
'name' => 'SavedSearch_Manage_ACLs',
'entity' => 'SavedSearch',
'cleanup' => 'unused',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'name' => 'Manage_ACLs',
'label' => E::ts('Manage ACLs'),
'form_values' => NULL,
'mapping_id' => NULL,
'search_custom_id' => NULL,
'api_entity' => 'ACL',
'api_params' => [
'version' => 4,
'select' => [
'entity_id:label',
'operation:label',
'object_table:label',
'object_id:label',
'name',
'is_active',
'deny',
'priority',
],
'orderBy' => [],
'where' => [],
'groupBy' => [],
'join' => [],
'having' => [],
],
'expires_date' => NULL,
'description' => NULL,
],
'match' => [
'name',
],
],
],
[
'name' => 'SavedSearch_Manage_ACLs_SearchDisplay_Manage_ACLs_Table_1',
'entity' => 'SearchDisplay',
'cleanup' => 'unused',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'name' => 'Manage_ACLs_Table_1',
'label' => E::ts('Manage ACLs'),
'saved_search_id.name' => 'Manage_ACLs',
'type' => 'table',
'settings' => [
'description' => NULL,
'sort' => [
[
'priority',
'ASC',
],
],
'limit' => 50,
'pager' => [],
'placeholder' => 5,
'columns' => [
[
'type' => 'field',
'key' => 'entity_id:label',
'dataType' => 'Integer',
'label' => E::ts('Role'),
'sortable' => TRUE,
],
[
'type' => 'field',
'key' => 'operation:label',
'dataType' => 'String',
'label' => E::ts('Operation'),
'sortable' => TRUE,
],
[
'type' => 'field',
'key' => 'object_table:label',
'dataType' => 'String',
'label' => E::ts('Type of Data'),
'sortable' => TRUE,
],
[
'type' => 'field',
'key' => 'object_id:label',
'dataType' => 'Integer',
'label' => E::ts('Which Data'),
'sortable' => TRUE,
],
[
'type' => 'field',
'key' => 'name',
'dataType' => 'String',
'label' => E::ts('Description'),
'sortable' => TRUE,
],
[
'type' => 'field',
'key' => 'is_active',
'dataType' => 'Boolean',
'label' => E::ts('Enabled'),
'sortable' => TRUE,
],
[
'type' => 'field',
'key' => 'deny',
'dataType' => 'Boolean',
'label' => E::ts('Mode'),
'sortable' => TRUE,
'rewrite' => '{if "[deny]" eq "1"}' . E::ts('Deny') . '{else}' . E::ts('Allow') . '{/if}',
],
[
'type' => 'field',
'key' => 'priority',
'dataType' => 'Integer',
'label' => E::ts('Priority'),
'sortable' => TRUE,
],
[
'text' => '',
'style' => 'default',
'size' => 'btn-xs',
'icon' => 'fa-bars',
'links' => [
[
'entity' => 'ACL',
'action' => 'update',
'join' => '',
'target' => 'crm-popup',
'icon' => 'fa-pencil',
'text' => E::ts('Edit ACL'),
'style' => 'default',
'path' => '',
'condition' => [],
],
[
'entity' => 'ACL',
'action' => 'delete',
'join' => '',
'target' => 'crm-popup',
'icon' => 'fa-trash',
'text' => E::ts('Delete ACL'),
'style' => 'danger',
'path' => '',
'condition' => [],
],
],
'type' => 'menu',
'alignment' => 'text-right',
],
],
'actions' => TRUE,
'classes' => [
'table',
'table-striped',
],
'addButton' => [
'path' => 'civicrm/acl/edit?reset=1&action=add',
'text' => E::ts('Add ACL'),
'icon' => 'fa-plus',
],
],
'acl_bypass' => FALSE,
],
'match' => [
'name',
'saved_search_id',
],
],
],
];
10 changes: 10 additions & 0 deletions xml/schema/ACL/ACL.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<type>int unsigned</type>
<title>Entity ID</title>
<comment>ID of the object possessing this ACL</comment>
<pseudoconstant>
<optionGroupName>acl_role</optionGroupName>
</pseudoconstant>
<add>1.6</add>
</field>
<dynamicForeignKey>
Expand Down Expand Up @@ -91,6 +94,9 @@
<type>varchar</type>
<length>64</length>
<comment>The table of the object controlled by this ACL entry</comment>
<pseudoconstant>
<callback>CRM_ACL_BAO_ACL::getObjectTableOptions</callback>
</pseudoconstant>
<add>1.6</add>
</field>
<field>
Expand All @@ -99,6 +105,10 @@
<type>int unsigned</type>
<comment>The ID of the object controlled by this ACL entry</comment>
<add>1.6</add>
<pseudoconstant>
<callback>CRM_ACL_BAO_ACL::getObjectIdOptions</callback>
<prefetch>false</prefetch>
</pseudoconstant>
</field>
<field>
<name>acl_table</name>
Expand Down

0 comments on commit bab8f74

Please sign in to comment.