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

Generate button links in PHP instead of smarty for ContributionView form #22588

Closed

Conversation

mattwire
Copy link
Contributor

Overview

ContributionView form has some impressive and probably insecure code to create the "link" buttons such as edit/delete. Even better the code is duplicated for top and botton!

Before

Fairly complex smarty code to generate button links for Edit/Delete on contributionview form.

After

Smarty logic recreated in PHP form (no attempt to clean up at this stage - it's meant to be a straight refactor). Smarty logic removed from top/bottom buttons and now using standard "linkButtons".

Technical Details

Comments

@civibot
Copy link

civibot bot commented Jan 20, 2022

(Standard links)

@civibot civibot bot added the master label Jan 20, 2022
@eileenmcnaughton
Copy link
Contributor

eileenmcnaughton commented Feb 3, 2022

I agree this is a good idea - ie moving it to the php layer is just better.

Regarding how this intersects with the financialacls work - I think it makes sense to consolidate fixing that in this PR - so I have removed from the other.

We are removing handling of the smarty variables $canEdit and $canDelete so the assignment of them should be removed too.

image

UPDATE - my original thoughts about a hook were wrong - we can check if the contact has permission to update (canEdit) or delete (canDelete) using the api.

so the core code should check something like this when determining whether to show the update

$results = \Civi\Api4\Contribution::checkAccess()
  ->setAction('update')
  ->addValue('id', 202)
  ->execute();
foreach ($results as $result) {
  // do something
}

We'd need to check but it looks like the hook code is already in the extension to interact with that

function _financialacls_civi_api4_authorizeContribution(\Civi\Api4\Event\AuthorizeRecordEvent $e) {

@@ -46,6 +46,7 @@ public function preProcess() {
}
$this->assign('is_template', $values['is_template']);

$noACL = FALSE;
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && $this->_action & CRM_Core_Action::VIEW) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This section should wind up removable with the view bounce being done here and then all the other checks can be done with the checkAccess being used further down

image

}
if ((
CRM_Core_Permission::check('edit_contributions')
&& CRM_Core_Permission::check('edit contributions of type ' . $financialTypeID)
Copy link
Contributor

Choose a reason for hiding this comment

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

this will simplify down to that api checkAccess

@@ -10,44 +10,6 @@
<div class="crm-block crm-content-block crm-contribution-view-form-block">
<div class="action-link">
<div class="crm-submit-buttons">
{if (call_user_func(array('CRM_Core_Permission','check'), 'edit contributions') && call_user_func(array('CRM_Core_Permission', 'check'), "edit contributions of type $financial_type") && !empty($canEdit)) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

just yay

@mattwire
Copy link
Contributor Author

mattwire commented Feb 3, 2022

@eileenmcnaughton What do you think about merging this first and then making the financialacl changes? In theory this is a "no change" PR that should just map the logic that was in smarty to PHP. I'm getting a bit muddled when looking through the changes needed as you describe above although I can see we'll end up with much cleaner code.

@eileenmcnaughton
Copy link
Contributor

@mattwire as is this actually does break financial acls - see

image

But I'll put something up to make it clearer to you what I mean - I think it will be fairly clean

@mattwire
Copy link
Contributor Author

mattwire commented Feb 3, 2022

as is this actually does break financial acls

Ah ok!

@eileenmcnaughton
Copy link
Contributor

I think I lost my comment - this is the commit that should fix it - just trying to confirm - f6957ad

Still a couple more undefined vars (eg. below) - I'm not looking into those
image

@eileenmcnaughton
Copy link
Contributor

Just confirming that I did some testing & f6957ad does make the financial acl part work - although if #22684 is not merged first then that commit causes a regression ( unconfirmed but logically I think so)

So it's just the undefined variables I think (& stopping the php layer assigns since no longer used)

@eileenmcnaughton
Copy link
Contributor

@mattwire I decided to take another look at those variables & consolidated this PR & my PR into #22698

@eileenmcnaughton
Copy link
Contributor

@mattwire we should probably close this as #22698 replaces + has fixes for the issues in this

@mattwire
Copy link
Contributor Author

Closing in favour of #22698

@mattwire mattwire closed this Feb 16, 2022
@mattwire mattwire deleted the contributionviewlinkbuttons branch February 16, 2022 12:40
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