Skip to content

Commit

Permalink
Only call getGroupACLRoles if contactID is present
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Mar 24, 2021
1 parent 9d64793 commit 59b8c22
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions CRM/ACL/BAO/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public static function operation(): array {
* Array of assoc. arrays of ACL rules
* @throws \CRM_Core_Exception
*/
protected static function getGroupACLRoles($contact_id) {
$contact_id = CRM_Utils_Type::escape($contact_id, 'Integer');
protected static function getGroupACLRoles(int $contact_id) {

$query = " SELECT acl.*
FROM civicrm_acl acl
Expand Down Expand Up @@ -78,26 +77,6 @@ protected static function getGroupACLRoles($contact_id) {
$results[$rule->id] = $rule->toArray();
}

// also get all acls for "Any Role" case
// and authenticated User Role if present
$roles = "0";
$session = CRM_Core_Session::singleton();
if ($session->get('ufID') > 0) {
$roles .= ",2";
}

$query = "
SELECT acl.*
FROM civicrm_acl acl
WHERE acl.entity_id IN ( $roles )
AND acl.entity_table = 'civicrm_acl_role'
";

$rule = CRM_Core_DAO::executeQuery($query);
while ($rule->fetch()) {
$results[$rule->id] = $rule->toArray();
}

return $results;
}

Expand Down Expand Up @@ -141,8 +120,27 @@ public static function getAllByContact(?int $contact_id): array {
while ($rule->fetch()) {
$result[$rule->id] = $rule->toArray();
}
$result += self::getGroupACLRoles($contact_id);
}
// also get all acls for "Any Role" case
// and authenticated User Role if present
$roles = '0';
$session = CRM_Core_Session::singleton();
if ($session->get('ufID') > 0) {
$roles .= ',2';
}

$query = "
SELECT acl.*
FROM civicrm_acl acl
WHERE acl.entity_id IN ( $roles )
AND acl.entity_table = 'civicrm_acl_role'
";

$rule = CRM_Core_DAO::executeQuery($query);
while ($rule->fetch()) {
$result[$rule->id] = $rule->toArray();
}
$result += self::getGroupACLRoles($contact_id);
return $result;
}

Expand Down

0 comments on commit 59b8c22

Please sign in to comment.