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

Simplify handling for case checking. #13372

Merged
merged 1 commit into from
Jan 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 10 additions & 23 deletions CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2693,17 +2693,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.
if (!self::hasPermissionForActivityType($activity->activity_type_id)) {
return FALSE;
}

// Check for this permission related to contact.
$permission = CRM_Core_Permission::VIEW;
if ($action == CRM_Core_Action::UPDATE) {
Expand Down Expand Up @@ -2768,25 +2766,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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton is this taken care of in the hasPermissionForActivityType?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 yep - it retrieves a list of permissable components & then checks types are associated with them

Copy link
Contributor Author

@eileenmcnaughton eileenmcnaughton Jan 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can see it looks for components

$components = self::activityComponents(FALSE);

which filters with

        if ($compObj->info['name'] == 'CiviCase') {
          if (CRM_Case_BAO_Case::accessCiviCase()) {
            $components[$compObj->componentID] = $compObj->info['name'];
          }
        }

which calls

  /**
   * Since we drop 'access CiviCase', allow access
   * if user has 'access my cases and activities'
   * or 'access all cases and activities'
   */
  public static function accessCiviCase() {
    if (!self::enabled()) {
      return FALSE;
    }

    if (CRM_Core_Permission::check('access my cases and activities') ||
      CRM_Core_Permission::check('access all cases and activities')
    ) {
      return TRUE;
    }

    return FALSE;
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 somewhat ironically I have a follow up that will make this kinda redundant for api calls but this allow() function is still called from a bunch of places. I added testGetActivityCheckPermissionsByCaseComponent as part of this refactoring effort - but it got added in advance of some of these changes so the link isn't obvious

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