From 3cbe6baccaf9046255174ffa8575043e735212a5 Mon Sep 17 00:00:00 2001 From: colemanw Date: Sat, 7 Oct 2023 13:30:12 -0400 Subject: [PATCH] Fix Activity ACL clause generation Regression was caused by 918e583a146876fb42932a1d959796fd710b7b74 updating DAO::getSelectWhereClause but not CRM_Contact_BAO_Query::generatePermissionClause. Turns out the code was being duplicated and the latter could just call the former. --- CRM/Contact/BAO/Query.php | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 57039fdb89..0969bc8bfc 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -5077,27 +5077,12 @@ civicrm_relationship.start_date > {$today} } } + // Add ACL permission clause generated by the BAO. This is the same clause used by API::get. + // TODO: Why only activities? if (isset($this->_tables['civicrm_activity'])) { - $bao = new CRM_Activity_BAO_Activity(); - $clauses = $subclauses = []; - foreach ($bao->addSelectWhereClause() as $field => $vals) { - if ($vals && $field !== 'id') { - foreach ($vals as $val) { - $clauses[] = $bao->tableName() . ".$field " . $val; - } - } - elseif ($vals) { - $subclauses[] = "$field " . implode(" AND $field ", (array) $vals); - } - } - if ($subclauses) { - $clauses[] = $bao->tableName() . '.`id` IN (SELECT `id` FROM `' . $bao->tableName() . '` WHERE ' . implode(' AND ', $subclauses) . ')'; - } - if (!empty($clauses) && $this->_permissionWhereClause) { - $this->_permissionWhereClause .= ' AND (' . implode(' AND ', $clauses) . ')'; - } - elseif (!empty($clauses)) { - $this->_permissionWhereClause .= '(' . implode(' AND ', $clauses) . ')'; + $clauses = array_filter(CRM_Activity_BAO_Activity::getSelectWhereClause()); + if ($clauses) { + $this->_permissionWhereClause .= ($this->_permissionWhereClause ? ' AND ' : '') . '(' . implode(' AND ', $clauses) . ')'; } } } -- 2.25.1