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

dev/core#1230 Dedupe permissions - allow safe mode merging based on 'merge duplicate contacts' #15188

Merged
merged 1 commit into from
Sep 5, 2019
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
3 changes: 3 additions & 0 deletions CRM/Core/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,9 @@ public static function getEntityActionPermissions() {
$permissions['exception'] = [
'default' => ['merge duplicate contacts'],
];
$permissions['job'] = [
'process_batch_merge' => ['merge duplicate contacts'],
];
// Loc block is only used for events
$permissions['loc_block'] = $permissions['event'];

Expand Down
7 changes: 6 additions & 1 deletion CRM/Dedupe/Merger.php
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,15 @@ public static function retrieveFields($main, $other) {
* per comments on isSelected above.
*
* @return array|bool
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public static function batchMerge($rgid, $gid = NULL, $mode = 'safe', $batchLimit = 1, $isSelected = 2, $criteria = [], $checkPermissions = TRUE, $reloadCacheIfEmpty = NULL) {
$redirectForPerformance = ($batchLimit > 1) ? TRUE : FALSE;

if ($mode === 'aggressive' && $checkPermissions && !CRM_Core_Permission::check('force merge duplicate contacts')) {
throw new CRM_Core_Exception(ts('Insufficient permissions for aggressive mode batch merge'));
}
if (!isset($reloadCacheIfEmpty)) {
$reloadCacheIfEmpty = (!$redirectForPerformance && $isSelected == 2);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/JobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1112,7 +1112,7 @@ public function testBatchMergeCustomDataZeroValueFieldWithConflict() {
* @param $dataSet
*/
public function testBatchMergeWorksCheckPermissionsTrue($dataSet) {
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'administer CiviCRM'];
CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM', 'administer CiviCRM', 'merge duplicate contacts', 'force merge duplicate contacts'];
foreach ($dataSet['contacts'] as $params) {
$this->callAPISuccess('Contact', 'create', $params);
}
Expand Down