AdminUI: convert "Assign Users to Roles" ACL page to SearchKit/FormBuilder
authorAidan Saunders <aidan.saunders@squiffle.uk>
Mon, 24 Jul 2023 17:09:48 +0000 (18:09 +0100)
committerAidan Saunders <aidan.saunders@squiffle.uk>
Wed, 26 Jul 2023 14:21:06 +0000 (15:21 +0100)
CRM/ACL/Form/EntityRole.php
ext/civicrm_admin_ui/ang/afsearchAssignUsersToRoles.aff.html [new file with mode: 0644]
ext/civicrm_admin_ui/ang/afsearchAssignUsersToRoles.aff.json [new file with mode: 0644]
ext/civicrm_admin_ui/managed/SavedSearch_ACL_Roles.mgd.php [new file with mode: 0644]

index 4e1b41be51bc865c2ec7ccb0c678b99c172d79c0..139366b71ebb697bae729ce832561d5a8ac28b4e 100644 (file)
@@ -31,7 +31,7 @@ class CRM_ACL_Form_EntityRole extends CRM_Admin_Form {
   }
 
   /**
-   * http://adminui.localhost/wp-admin/admin.php?page=CiviCRM&q=civicrm%2Facl%2Fentityrole&reset=1&action=add Build the form object.
+   * Build the form object.
    */
   public function buildQuickForm() {
     parent::buildQuickForm();
diff --git a/ext/civicrm_admin_ui/ang/afsearchAssignUsersToRoles.aff.html b/ext/civicrm_admin_ui/ang/afsearchAssignUsersToRoles.aff.html
new file mode 100644 (file)
index 0000000..7869ede
--- /dev/null
@@ -0,0 +1,7 @@
+<div af-fieldset="">
+  <div class="af-markup">
+    <div class="help">{{:: ts('ACLs allow you to control access to CiviCRM data. An ACL consists of an Operation (e.g. View or Edit), a set of data that the operation can be performed on (e.g. a group of contacts), and a Role that has permission to do this operation.') }} <a class="crm-doc-link no-popup" href="https://docs.civicrm.org/user/en/latest/initial-set-up/permissions-and-access-control/" target="_blank">{{:: ts('Learn more ...') }}</a></div>
+
+  </div>
+  <crm-search-display-table search-name="ACL_Roles" display-name="ACL_Roles_Table_1"></crm-search-display-table>
+</div>
diff --git a/ext/civicrm_admin_ui/ang/afsearchAssignUsersToRoles.aff.json b/ext/civicrm_admin_ui/ang/afsearchAssignUsersToRoles.aff.json
new file mode 100644 (file)
index 0000000..189261d
--- /dev/null
@@ -0,0 +1,19 @@
+{
+    "type": "search",
+    "requires": [],
+    "entity_type": null,
+    "join_entity": null,
+    "title": "Assign Users to Roles",
+    "description": "",
+    "is_dashlet": false,
+    "is_public": false,
+    "is_token": false,
+    "contact_summary": null,
+    "summary_contact_type": null,
+    "icon": "fa-list-alt",
+    "server_route": "civicrm/acl/entityrole",
+    "permission": "administer CiviCRM",
+    "redirect": null,
+    "create_submission": false,
+    "navigation": null
+}
diff --git a/ext/civicrm_admin_ui/managed/SavedSearch_ACL_Roles.mgd.php b/ext/civicrm_admin_ui/managed/SavedSearch_ACL_Roles.mgd.php
new file mode 100644 (file)
index 0000000..d139ac2
--- /dev/null
@@ -0,0 +1,195 @@
+<?php
+
+use CRM_CivicrmAdminUi_ExtensionUtil as E;
+
+return [
+  [
+    'name' => 'SavedSearch_ACL_Roles',
+    'entity' => 'SavedSearch',
+    'cleanup' => 'always',
+    'update' => 'unmodified',
+    'params' => [
+      'version' => 4,
+      'values' => [
+        'name' => 'ACL_Roles',
+        'label' => E::ts('ACL Roles'),
+        'form_values' => NULL,
+        'mapping_id' => NULL,
+        'search_custom_id' => NULL,
+        'api_entity' => 'ACLEntityRole',
+        'api_params' => [
+          'version' => 4,
+          'select' => [
+            'acl_role_id:label',
+            'ACLEntityRole_Group_entity_id_01.title',
+            'is_active',
+          ],
+          'orderBy' => [],
+          'where' => [],
+          'groupBy' => [],
+          'join' => [
+            [
+              'Group AS ACLEntityRole_Group_entity_id_01',
+              'LEFT',
+              [
+                'entity_id',
+                '=',
+                'ACLEntityRole_Group_entity_id_01.id',
+              ],
+              [
+                'entity_table',
+                '=',
+                "'civicrm_group'",
+              ],
+            ],
+          ],
+          'having' => [],
+        ],
+        'expires_date' => NULL,
+        'description' => NULL,
+      ],
+      'match' => [
+        'name',
+      ],
+    ],
+  ],
+  [
+    'name' => 'SavedSearch_ACL_Roles_SearchDisplay_ACL_Roles_Table_1',
+    'entity' => 'SearchDisplay',
+    'cleanup' => 'always',
+    'update' => 'unmodified',
+    'params' => [
+      'version' => 4,
+      'values' => [
+        'name' => 'ACL_Roles_Table_1',
+        'label' => E::ts('AdminUI ACL Roles Table'),
+        'saved_search_id.name' => 'ACL_Roles',
+        'type' => 'table',
+        'settings' => [
+          'description' => NULL,
+          'sort' => [],
+          'limit' => 50,
+          'pager' => [
+            'show_count' => FALSE,
+            'expose_limit' => FALSE,
+            'hide_single' => TRUE,
+          ],
+          'placeholder' => 5,
+          'columns' => [
+            [
+              'type' => 'field',
+              'key' => 'acl_role_id:label',
+              'dataType' => 'Integer',
+              'label' => E::ts('ACL Role'),
+              'sortable' => TRUE,
+            ],
+            [
+              'type' => 'field',
+              'key' => 'ACLEntityRole_Group_entity_id_01.title',
+              'dataType' => 'String',
+              'label' => E::ts('Assigned to'),
+              'sortable' => TRUE,
+            ],
+            [
+              'type' => 'field',
+              'key' => 'is_active',
+              'dataType' => 'Boolean',
+              'label' => E::ts('Enabled'),
+              'sortable' => TRUE,
+              'editable' => TRUE,
+            ],
+            [
+              'text' => '',
+              'style' => 'default',
+              'size' => 'btn-xs',
+              'icon' => 'fa-bars',
+              'links' => [
+                [
+                  'entity' => 'ACLEntityRole',
+                  'action' => 'update',
+                  'join' => '',
+                  'target' => 'crm-popup',
+                  'icon' => 'fa-pencil',
+                  'text' => E::ts('Edit'),
+                  'style' => 'default',
+                  'path' => '',
+                  'task' => '',
+                  'condition' => [],
+                ],
+                [
+                  'task' => 'enable',
+                  'entity' => 'ACLEntityRole',
+                  'join' => '',
+                  'target' => 'crm-popup',
+                  'icon' => 'fa-toggle-on',
+                  'text' => E::ts('Enable'),
+                  'style' => 'default',
+                  'path' => '',
+                  'action' => '',
+                  'condition' => [
+                    'is_active',
+                    '=',
+                    FALSE,
+                  ],
+                ],
+                [
+                  'task' => 'disable',
+                  'entity' => 'ACLEntityRole',
+                  'join' => '',
+                  'target' => 'crm-popup',
+                  'icon' => 'fa-toggle-off',
+                  'text' => E::ts('Disable'),
+                  'style' => 'default',
+                  'path' => '',
+                  'action' => '',
+                  'condition' => [
+                    'is_active',
+                    '=',
+                    TRUE,
+                  ],
+                ],
+                [
+                  'entity' => 'ACLEntityRole',
+                  'action' => 'delete',
+                  'join' => '',
+                  'target' => 'crm-popup',
+                  'icon' => 'fa-trash',
+                  'text' => E::ts('Delete'),
+                  'style' => 'danger',
+                  'path' => '',
+                  'task' => '',
+                  'condition' => [],
+                ],
+              ],
+              'type' => 'buttons',
+              'alignment' => 'text-right',
+            ],
+          ],
+          'actions' => FALSE,
+          'classes' => [
+            'table',
+            'table-striped',
+          ],
+          'cssRules' => [
+            [
+              'disabled',
+              'is_active',
+              '=',
+              FALSE,
+            ],
+          ],
+          'addButton' => [
+            'path' => 'civicrm/acl/entityrole/edit?reset=1&action=add',
+            'text' => E::ts('Add ACL Role Assignment'),
+            'icon' => 'fa-plus',
+          ],
+        ],
+        'acl_bypass' => FALSE,
+      ],
+      'match' => [
+        'name',
+        'saved_search_id',
+      ],
+    ],
+  ],
+];