Skip to content

Commit

Permalink
Simplify handling for case checking.
Browse files Browse the repository at this point in the history
We already check if the contact has generic case permissions in the component checking section.

We can remove that check from the case check & also early return from there since a NO
at that point can't be overriden
  • Loading branch information
eileenmcnaughton committed Oct 24, 2018
1 parent 45d17c8 commit c38aa23
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2721,15 +2721,15 @@ public static function checkPermission($activityId, $action) {
return FALSE;
}

if ( !self::hasPermissionForActivityType($activity->activity_type_id)) {
return FALSE;
}
// Return early when it is case activity.
// Check for CiviCase related permission.
if (CRM_Case_BAO_Case::isCaseActivity($activityId)) {
return self::isContactPermittedAccessToCaseActivity($activityId, $action, $activity->activity_type_id);
}

// Component related permissions.
$allow = self::hasPermissionForActivityType($activity->activity_type_id);

// Check for this permission related to contact.
$permission = CRM_Core_Permission::VIEW;
if ($action == CRM_Core_Action::UPDATE) {
Expand All @@ -2742,11 +2742,9 @@ public static function checkPermission($activityId, $action) {
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);

// Check for source contact.
if ($allow) {
$sourceContactId = self::getActivityContact($activity->id, $sourceID);
// Account for possibility of activity not having a source contact (as it may have been deleted).
$allow = $sourceContactId ? CRM_Contact_BAO_Contact_Permission::allow($sourceContactId, $permission) : TRUE;
}
$sourceContactId = self::getActivityContact($activity->id, $sourceID);
// Account for possibility of activity not having a source contact (as it may have been deleted).
$allow = $sourceContactId ? CRM_Contact_BAO_Contact_Permission::allow($sourceContactId, $permission) : TRUE;

// Check for target and assignee contacts.
if ($allow) {
Expand Down Expand Up @@ -2795,25 +2793,14 @@ public static function checkPermission($activityId, $action) {
* @return bool
*/
protected static function isContactPermittedAccessToCaseActivity($activityId, $action, $activityTypeID) {
$allow = FALSE;
foreach (['access my cases and activities', 'access all cases and activities'] as $per) {
if (CRM_Core_Permission::check($per)) {
$allow = TRUE;
break;
}
}

// Check for case specific permissions.
if ($allow) {
$oper = 'view';
if ($action == CRM_Core_Action::UPDATE) {
$oper = 'edit';
}
$allow = CRM_Case_BAO_Case::checkPermission($activityId,
$oper,
$activityTypeID
);
$oper = 'view';
if ($action == CRM_Core_Action::UPDATE) {
$oper = 'edit';
}
$allow = CRM_Case_BAO_Case::checkPermission($activityId,
$oper,
$activityTypeID
);

return $allow;
}
Expand Down

0 comments on commit c38aa23

Please sign in to comment.