From 8703c19833f6a27ee6abb0804461330de255f25c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 13 Feb 2022 17:19:59 -0500 Subject: [PATCH] SearchKit - Add 'merge contacts' task --- .../Api4/Action/SearchDisplay/GetSearchTasks.php | 12 ++++++++++++ .../crmSearchTasks/crmSearchTasks.component.js | 9 +++++++++ .../ang/crmSearchTasks/crmSearchTasks.html | 16 +++++++++++----- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php index 165441a173..da0c5d61d1 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php @@ -24,6 +24,7 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction { * @throws \API_Exception */ public function _run(\Civi\Api4\Generic\Result $result) { + // Adding checkPermissions filters out actions the user is not allowed to perform $entity = Entity::get($this->checkPermissions)->addWhere('name', '=', $this->entity) ->addSelect('name', 'title_plural') ->setChain(['actions' => ['$name', 'getActions', ['where' => [['name', 'IN', ['update', 'delete']]]], 'name']]) @@ -108,6 +109,17 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction { ]; } } + if (!$this->checkPermissions || \CRM_Core_Permission::check(['merge duplicate contacts', 'delete contacts'])) { + $tasks[$entity['name']]['contact.merge'] = [ + 'title' => E::ts('Dedupe - Merge 2 Contacts'), + 'number' => '=== 2', + 'icon' => 'fa-compress', + 'crmPopup' => [ + 'path' => "'civicrm/contact/merge'", + 'query' => '{reset: 1, cid: ids[0], oid: ids[1], action: "update"}', + ], + ]; + } } if ($entity['name'] === 'Contribution') { diff --git a/ext/search_kit/ang/crmSearchTasks/crmSearchTasks.component.js b/ext/search_kit/ang/crmSearchTasks/crmSearchTasks.component.js index d9953b202d..4910dcdd19 100644 --- a/ext/search_kit/ang/crmSearchTasks/crmSearchTasks.component.js +++ b/ext/search_kit/ang/crmSearchTasks/crmSearchTasks.component.js @@ -42,6 +42,15 @@ return $scope.$eval('' + ctrl.ids.length + action.number); }; + this.getActionTitle = function(action) { + if (ctrl.isActionAllowed(action)) { + return ctrl.ids.length ? + ts('Perform action on %1 %2', {1: ctrl.ids.length, 2: ctrl.entityInfo[ctrl.ids.length === 1 ? 'title' : 'title_plural']}) : + ts('Perform action on all %1', {1: ctrl.entityInfo.title_plural}); + } + return ts('Selected number must be %1', {1: action.number.replace('===', '')}); + }; + this.doAction = function(action) { if (!ctrl.isActionAllowed(action)) { return; diff --git a/ext/search_kit/ang/crmSearchTasks/crmSearchTasks.html b/ext/search_kit/ang/crmSearchTasks/crmSearchTasks.html index a61cb9b811..e2b5e4dc42 100644 --- a/ext/search_kit/ang/crmSearchTasks/crmSearchTasks.html +++ b/ext/search_kit/ang/crmSearchTasks/crmSearchTasks.html @@ -1,14 +1,20 @@ -
-
-- 2.25.1