Skip to content

Commit 9ae90c5

Browse files
author
Jitendra Purohit
committed
CRM-20910: Check permission param while retrieving participants from api
1 parent 6005042 commit 9ae90c5

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

CRM/Contact/BAO/Query.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -6121,7 +6121,8 @@ public static function buildQillForFieldValue(
61216121
$pseudoOptions = CRM_Core_PseudoConstant::worldRegion();
61226122
}
61236123
elseif ($daoName == 'CRM_Event_DAO_Event' && $fieldName == 'id') {
6124-
$pseudoOptions = CRM_Event_BAO_Event::getEvents(0, $fieldValue, TRUE, TRUE, TRUE);
6124+
$checkPermission = CRM_Utils_Array::value('check_permission', $pseudoExtraParam, TRUE);
6125+
$pseudoOptions = CRM_Event_BAO_Event::getEvents(0, $fieldValue, TRUE, $checkPermission, TRUE);
61256126
}
61266127
elseif ($fieldName == 'contribution_product_id') {
61276128
$pseudoOptions = CRM_Contribute_PseudoConstant::products();

CRM/Event/BAO/Query.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ public static function where(&$query) {
253253
* @param $query
254254
*/
255255
public static function whereClauseSingle(&$values, &$query) {
256+
$checkPermission = TRUE;
257+
if (!empty($query->_skipPermission)) {
258+
$checkPermission = FALSE;
259+
}
256260
list($name, $op, $value, $grouping, $wildcard) = $values;
257261
$fields = array_merge(CRM_Event_BAO_Event::fields(), CRM_Event_BAO_Participant::exportableFields());
258262

@@ -400,7 +404,7 @@ public static function whereClauseSingle(&$values, &$query) {
400404
}
401405
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$tableName.$name", $op, $value, $dataType);
402406

403-
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Participant', $name, $value, $op);
407+
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Participant', $name, $value, $op, array('check_permission' => $checkPermission));
404408
$query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value));
405409
$query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1;
406410
return;
@@ -425,7 +429,7 @@ public static function whereClauseSingle(&$values, &$query) {
425429
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$tableName.$name", $op, $value, $dataType);
426430
}
427431

428-
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Participant', $name, $value, $op);
432+
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Participant', $name, $value, $op, array('check_permission' => $checkPermission));
429433
$query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value));
430434
$query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1;
431435
return;
@@ -461,7 +465,7 @@ public static function whereClauseSingle(&$values, &$query) {
461465
if (!array_key_exists($qillName, $fields)) {
462466
break;
463467
}
464-
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Event', $name, $value, $op);
468+
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Event_DAO_Event', $name, $value, $op, array('check_permission' => $checkPermission));
465469
$query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$qillName]['title'], 2 => $op, 3 => $value));
466470
return;
467471
}

tests/phpunit/api/v3/ParticipantTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,30 @@ public function testGetParticipantIdOnly() {
206206

207207
}
208208

209+
/**
210+
* Test permission for participant get.
211+
*/
212+
public function testGetParticipantWithPermission() {
213+
$config = CRM_Core_Config::singleton();
214+
$config->userPermissionClass->permissions = array();
215+
$params = array(
216+
'event_id' => $this->_eventID,
217+
'check_permissions' => TRUE,
218+
'return' => array(
219+
'participant_id',
220+
'event_id',
221+
'participant_register_date',
222+
'participant_source',
223+
),
224+
);
225+
$this->callAPIFailure('participant', 'get', $params);
226+
227+
$params['check_permissions'] = FALSE;
228+
$result = $this->callAPISuccess('participant', 'get', $params);
229+
$this->assertEquals($result['is_error'], 0);
230+
}
231+
232+
209233
/**
210234
* Check with params id.
211235
*/

0 commit comments

Comments
 (0)