From 2c3ad4b70b79edbfb9ff24dc1f60aabab1c6a41d Mon Sep 17 00:00:00 2001 From: kurund Date: Sat, 5 Jul 2014 18:58:32 +0530 Subject: [PATCH] ACL's not working correctly for select all options in export, CRM-14877 ---------------------------------------- * CRM-14877: users bypass ACLs when exporting https://issues.civicrm.org/jira/browse/CRM-14877 --- CRM/Contact/BAO/Query.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index d77c787d44..1ffdeb928f 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1254,11 +1254,15 @@ class CRM_Contact_BAO_Query { * @param boolean $count * @param boolean $sortByChar * @param boolean $groupContacts + * @param boolean $onlyDeleted * * @return array sql query parts as an array * @access public */ - function query($count = FALSE, $sortByChar = FALSE, $groupContacts = FALSE) { + function query($count = FALSE, $sortByChar = FALSE, $groupContacts = FALSE, $onlyDeleted = FALSE) { + // build permission clause + $this->generatePermissionClause($onlyDeleted, $count); + if ($count) { if (isset($this->_rowCountClause)) { $select = "SELECT {$this->_rowCountClause}"; @@ -1335,6 +1339,15 @@ class CRM_Contact_BAO_Query { $where = "WHERE {$this->_whereClause}"; } + if (!empty($this->_permissionWhereClause)) { + if (empty($where)) { + $where = "WHERE $this->_permissionWhereClause"; + } + else { + $where = "$where AND $this->_permissionWhereClause"; + } + } + $having = ''; if (!empty($this->_having)) { foreach ($this->_having as $havingSets) { @@ -4459,7 +4472,6 @@ civicrm_relationship.is_permission_a_b = 0 break; } } - $this->generatePermissionClause($onlyDeleted, $count); // building the query string $groupBy = NULL; @@ -4566,16 +4578,7 @@ civicrm_relationship.is_permission_a_b = 0 // note : this modifies _fromClause and _simpleFromClause $this->includePseudoFieldsJoin($sort); - list($select, $from, $where, $having) = $this->query($count, $sortByChar, $groupContacts); - - if(!empty($this->_permissionWhereClause)){ - if (empty($where)) { - $where = "WHERE $this->_permissionWhereClause"; - } - else { - $where = "$where AND $this->_permissionWhereClause"; - } - } + list($select, $from, $where, $having) = $this->query($count, $sortByChar, $groupContacts, $onlyDeleted); if ($additionalWhereClause) { $where = $where . ' AND ' . $additionalWhereClause; -- 2.25.1