Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-18456 - Catch api case permission exceptions #8199

Merged
merged 1 commit into from Apr 21, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 27 additions & 9 deletions CRM/Case/BAO/Case.php
Expand Up @@ -1901,7 +1901,7 @@ public static function getCaseManagerContact($caseType, $caseId) {
* @param int $contactId
* @param bool $excludeDeleted
*
* @return null|string
* @return int
*/
public static function caseCount($contactId = NULL, $excludeDeleted = TRUE) {
$params = array('check_permissions' => TRUE);
Expand All @@ -1911,7 +1911,13 @@ public static function caseCount($contactId = NULL, $excludeDeleted = TRUE) {
if ($contactId) {
$params['contact_id'] = $contactId;
}
return civicrm_api3('Case', 'getcount', $params);
try {
return civicrm_api3('Case', 'getcount', $params);
}
catch (CiviCRM_API3_Exception $e) {
// Lack of permissions will throw an exception
return 0;
}
}

/**
Expand Down Expand Up @@ -2542,12 +2548,18 @@ public static function checkPermission($activityId, $operation, $actTypeId = NUL
if (in_array($operation, $caseActOperations)) {
static $caseCount;
if (!isset($caseCount)) {
$caseCount = civicrm_api3('Case', 'getcount', array(
'check_permissions' => TRUE,
'status_id' => array('!=' => 'Closed'),
'is_deleted' => 0,
'end_date' => array('IS NULL' => 1),
));
try {
$caseCount = civicrm_api3('Case', 'getcount', array(
'check_permissions' => TRUE,
'status_id' => array('!=' => 'Closed'),
'is_deleted' => 0,
'end_date' => array('IS NULL' => 1),
));
}
catch (CiviCRM_API3_Exception $e) {
// Lack of permissions will throw an exception
$caseCount = 0;
}
}
if ($operation == 'File On Case') {
$allow = !empty($caseCount);
Expand Down Expand Up @@ -2793,7 +2805,13 @@ public static function accessCase($caseId, $denyClosed = TRUE) {
if ($denyClosed && !CRM_Core_Permission::check('access all cases and activities')) {
$params['status_id'] = array('!=' => 'Closed');
}
return (bool) civicrm_api3('Case', 'getcount', $params);
try {
return (bool) civicrm_api3('Case', 'getcount', $params);
}
catch (CiviCRM_API3_Exception $e) {
// Lack of permissions will throw an exception
return FALSE;
}
}

/**
Expand Down