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] Remove calls to fatal() #16746

Merged
merged 1 commit into from Mar 16, 2020
Merged

Conversation

eileenmcnaughton
Copy link
Contributor

Overview

  • Remove calls to fatal()
  • comment blocks
  • using strict comparison
  • don't use elseif where the prior if threw an exception

Before

use of CRM_Core_Fatal()

After

throwing exceptions

Technical Details

Comments

Also other minor cleanup on
- comment blocks
- using strict comparison
- don't use elseif where the prior if threw an exceptionn
@civibot
Copy link

civibot bot commented Mar 11, 2020

(Standard links)

@civibot civibot bot added the master label Mar 11, 2020
@@ -88,7 +90,7 @@ public static function add(&$params) {
if (!empty($params['workflow_id']) && !CRM_Core_Permission::check('edit system workflow message templates')) {
throw new \Civi\API\Exception\UnauthorizedException(ts('%1', [1 => $systemWorkflowPermissionDeniedMessage]));
}
elseif (!CRM_Core_Permission::check('edit user-driven message templates')) {
if (!CRM_Core_Permission::check('edit user-driven message templates')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

elseif is meaningless when previous if throws an exception

Copy link
Contributor

Choose a reason for hiding this comment

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

@eileenmcnaughton i think it might have some meaning, If you have an end user that is able to edit system workflow templates but not the user driven ones (why i have no idea). The change here would mean that the check for user driven message templates permission is now no longer dependant on if you have a workflow_id or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right but if the first IF is true then it throws an exception & never reaches the second - which is what elseif achieves when no exception is thrown

Copy link
Contributor

Choose a reason for hiding this comment

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

My point is if the user is able to satisfy the permission check i.e. the if fails (we have a workflow id and they have the correct permission) changing from an elseif to an if will mean the 2nd permission check will run no matter if there is a workflow_id in the params or not. With elseif it will only run if there is no workflow id in the params array.

(edited comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we have 2 checks

If check 1 is true then an exception is thrown and the process does not proceed. The elseif is never reached

If not then the second check is performed, as it would be if the elseif were there

The second check will still only run if the first check is false because of the early exit

@seamuslee001 seamuslee001 merged commit ffdf4f9 into civicrm:master Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants