Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Search Display of ACLs #26624

Merged
merged 3 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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;
}

}
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
1 change: 0 additions & 1 deletion CRM/ACL/Form/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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
colemanw marked this conversation as resolved.
Show resolved Hide resolved
*
* @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
13 changes: 13 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveSixtyFour.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}

}
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',
],
],
],
];
4 changes: 3 additions & 1 deletion tests/phpunit/api/v3/SyntaxConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,9 @@ public function testCreateSingleValueAlter($entityName): void {
$options[$optionValue[0][$keyColumn]] = 'new option value';
}
}
$entity[$field] = array_rand($options);
if ($options) {
$entity[$field] = array_rand($options);
}
}
if (!empty($specs['FKClassName']) && !empty($specs['pseudoconstant'])) {
// in the weird situation where a field has both an fk and pseudoconstant defined,
Expand Down
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 I just noticed this. Why did you add this <prefetch> flag? I'm honestly not even sure what this would do when paired with a <callback>, I don' think that's ever been done before.

</pseudoconstant>
</field>
<field>
<name>acl_table</name>
Expand Down