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

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

Minor code simplification

Before

Slightly more expensive method used for civicase checking

After

The hasPermissionForActivityType check is run before the civicase check and an early return is done if the contact does not have permission to 'access my cases and activities', or 'access all cases and activities'

Technical Details

We already check if the contact has generic case permissions in the component checking section, we can do that first & remove it from the case check.

Comments

Test coverage in testGetActivityCheckPermissionsByCaseComponent

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
@civibot
Copy link

civibot bot commented Dec 31, 2018

(Standard links)

@civibot civibot bot added the master label Dec 31, 2018
@eileenmcnaughton
Copy link
Contributor Author

@seamuslee001 @colemanw this is a minor follow on for things you have reviewed

@@ -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

@seamuslee001
Copy link
Contributor

Looks fine to me and with the clarification i'm happy to merge this

@seamuslee001 seamuslee001 merged commit 777612b into civicrm:master Jan 1, 2019
@seamuslee001 seamuslee001 deleted the activity_extract branch January 1, 2019 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants