Skip to content

Commit

Permalink
Fold back in getGroupACLs
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Mar 24, 2021
1 parent 757d250 commit e9b3684
Showing 1 changed file with 16 additions and 46 deletions.
62 changes: 16 additions & 46 deletions CRM/ACL/BAO/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,47 +72,6 @@ public function toArray($format = '%s', $hideEmpty = FALSE) {
return $result;
}

/**
* Get all ACLs granted to a contact through all group memberships.
*
* @param int $contact_id
* The contact's ID.
* @param bool $aclRoles
* Include ACL Roles?.
*
* @return array
* Assoc array of ACL rules
* @throws \CRM_Core_Exception
*/
protected static function getGroupACLs($contact_id, $aclRoles = FALSE) {
$contact_id = CRM_Utils_Type::escape($contact_id, 'Integer');

$results = [];

if ($contact_id) {
$query = "
SELECT acl.*
FROM civicrm_acl acl
INNER JOIN civicrm_group_contact group_contact
ON acl.entity_id = group_contact.group_id
WHERE acl.entity_table = 'civicrm_group'
AND group_contact.contact_id = $contact_id
AND group_contact.status = 'Added'";

$rule = CRM_Core_DAO::executeQuery($query);

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

if ($aclRoles) {
$results += self::getGroupACLRoles($contact_id);
}

return $results;
}

/**
* Get all of the ACLs for a contact through ACL groups owned by Contact.
* groups.
Expand Down Expand Up @@ -181,15 +140,15 @@ protected static function getGroupACLRoles($contact_id) {
/**
* Get all ACLs owned by a given contact, including domain and group-level.
*
* @param int $contact_id
* @param int|null $contact_id
* The contact ID.
*
* @return array
* Assoc array of ACL rules
*
* @throws \CRM_Core_Exception
*/
public static function getAllByContact($contact_id) {
public static function getAllByContact(?int $contact_id): array {
$result = [];

/* First, the contact-specific ACLs, including ACL Roles */
Expand All @@ -204,11 +163,22 @@ public static function getAllByContact($contact_id) {
while ($rule->fetch()) {
$result[$rule->id] = $rule->toArray();
}
}
$query = "
SELECT acl.*
FROM civicrm_acl acl
INNER JOIN civicrm_group_contact group_contact
ON acl.entity_id = group_contact.group_id
WHERE acl.entity_table = 'civicrm_group'
AND group_contact.contact_id = $contact_id
AND group_contact.status = 'Added'";

/* Then, all ACLs granted through group membership */
$result += self::getGroupACLs($contact_id, TRUE);
$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 e9b3684

Please sign in to comment.