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

REF - Use function to get component name from permission #22688

Merged
merged 1 commit into from
Feb 6, 2022

Conversation

colemanw
Copy link
Member

@colemanw colemanw commented Feb 3, 2022

Overview

Refactors some long-winded code which was attempting to do what an existing function does better

Before

Try to guess component name from permission name, based on string fudgery

After

Use a function which does it without guessing

Comments

I'm fairly certain this change is correct, but someone else should look at it to ensure I'm not missing some important difference between the existing code (silly as it was) and the new function.

@civibot
Copy link

civibot bot commented Feb 3, 2022

(Standard links)

@colemanw
Copy link
Member Author

colemanw commented Feb 6, 2022

Retest this please

@demeritcowboy
Copy link
Contributor

I can take a look.

@demeritcowboy
Copy link
Contributor

demeritcowboy commented Feb 6, 2022

Looks ok.

One sanity check I did was to compare the before/after output of cv ev --user=something "$perms = CRM_Core_Permission::basicPermissions(); foreach ($perms as $p => $dontcare) { var_dump(CRM_Core_BAO_Dashboard::checkPermission([$p], null)); }" with admin/regular/anonymous users. Checks out.

This function also appears to only be called from one place in universe (the same file), so it limits the scope. I'm ok to merge just might be worth making the function private.

@@ -189,17 +176,10 @@ public static function checkPermission($permissions, $operator) {
}
}

if (!$showDashlet && !$hasPermission) {
return FALSE;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, a triple negative! I wonder if there's a simpler way to write that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hehe. Seems there isn't not a way to avoid it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wouldn't be unsurprised if we couldn't simplify it.

@colemanw
Copy link
Member Author

colemanw commented Feb 6, 2022

Ok @demeritcowboy I changed the function to be private and added some additional cleanup for your reviewing pleasure :)

@colemanw colemanw merged commit 9f9f878 into civicrm:master Feb 6, 2022
@colemanw colemanw deleted the getComponentName branch February 6, 2022 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants