From e3ad0182e847bca2ca038997cbc92b16042bdb6d Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 14 Oct 2016 12:09:45 +0100 Subject: [PATCH] CRM-19311 extend group permission to include own hidden groups --- CRM/ACL/BAO/ACL.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/CRM/ACL/BAO/ACL.php b/CRM/ACL/BAO/ACL.php index e3002f65f5..7bb97cf4f6 100644 --- a/CRM/ACL/BAO/ACL.php +++ b/CRM/ACL/BAO/ACL.php @@ -862,6 +862,13 @@ SELECT g.* $allGroups = NULL, $includedGroups = NULL ) { + $userCacheKey = "{$contactID}_{$type}_{$tableName}_" . CRM_Core_Config::domainID() . '_' . md5(implode(',', array_merge((array) $allGroups, (array) $includedGroups))); + if (empty(Civi::$statics[__CLASS__]['permissioned_groups'])) { + Civi::$statics[__CLASS__]['permissioned_groups'] = array(); + } + if (!empty(Civi::$statics[__CLASS__]['permissioned_groups'][$userCacheKey])) { + return Civi::$statics[__CLASS__]['permissioned_groups'][$userCacheKey]; + } $acls = CRM_ACL_BAO_Cache::build($contactID); @@ -912,9 +919,20 @@ ORDER BY a.object_id ) { $ids = $includedGroups; } + if ($contactID) { + // Contacts create hidden groups from search results. They should be able to retrieve their own. + $ownHiddenGroupsList = CRM_Core_DAO::singleValueQuery(" + SELECT GROUP_CONCAT(id) FROM civicrm_group WHERE is_hidden =1 AND created_id = $contactID + "); + if ($ownHiddenGroupsList) { + $ownHiddenGroups = explode(',', $ownHiddenGroupsList); + $ids = array_merge($ids, $ownHiddenGroups); + } + + } CRM_Utils_Hook::aclGroup($type, $contactID, $tableName, $allGroups, $ids); - + Civi::$statics[__CLASS__]['permissioned_groups'][$userCacheKey] = $ids; return $ids; } -- 2.25.1