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

Fix activity view bug where an activity type id in the url overrides … #27496

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Sep 18, 2023

Overview

Fix activity view bug where an activity type id in the url overrides the actual activity type id

When we view an activity there is code in the template that renders differently depending on the activity type id. However, if the activity ID (atype) is wrong in the url it gives the url precedence

This is a bit obscure - I hit it when I changed the activity type id in the database & the view did not update

Before

Create an activity with details

-ALTERNATIVE ITEM 0-
Hi,

Wassup!?!?

Let's check if the output when viewing the form has legible line breaks in the output.

Thanks!

-ALTERNATIVE ITEM 1-

<div dir="ltr">Hi,<br></div>
<div dir="ltr"><br></div>
<div dir="ltr">Wassup!?!?<br></div>
<div dir="ltr"><br></div>
<div dir="ltr">Let&#39;s check if the output when viewing the form has legible line breaks in the output.<br></div>
<div dir="ltr"><br></div>
<div dir="ltr">Thanks!<br></div>
-ALTERNATIVE END-

(might need to save directly to DB UPDATE - no through the UI works)

View the activity - it looks like

image

Alter the activity view url - put the activity type ID for pdf letter (default install = 22 ) into the url as atype - you get the unadulterated version

image

After

The activity type ID comes from the activity not the url

Technical Details

A bit of minor clean up too

Comments

@civibot
Copy link

civibot bot commented Sep 18, 2023

🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷

Introduction for new contributors...
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
Quick links for reviewers...

➡️ Online demo of this PR 🔗

@civibot civibot bot added the master label Sep 18, 2023
@@ -65,7 +69,6 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
*/
protected $_sourceContactId;
protected $_targetContactId;
protected $_asigneeContactId;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unused

@@ -265,33 +268,20 @@ public function preProcess() {

$this->assign('context', $this->_context);

$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
$this->setAction(CRM_Utils_Request::retrieve('action', 'String', $this));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Once #27495 is merged it will cast to an int & we can be confident it is numeric

@demeritcowboy
Copy link
Contributor

I can review this but there's a lot going on here and if I remember right this area was a bit fraught with danger. And I think case activity calls this too.

@eileenmcnaughton eileenmcnaughton force-pushed the activity_view branch 2 times, most recently from 43ea66f to 8781048 Compare September 18, 2023 22:55
@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy yeah - your tests found the danger - I'm pulling it back ...

@@ -9,7 +9,7 @@
*}
<div class="crm-block crm-content-block crm-activity-view-block">
{if $activityTypeDescription}
<div class="help">{$activityTypeDescription}</div>
<div class="help">{$activityTypeDescription|escape}</div>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no direct reason - but the temptation to change how this is loaded is there so this is hardening in case that happens

Copy link
Contributor

Choose a reason for hiding this comment

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

Going to try to look at this this weekend but just noting that this field is html so purify seems more better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@eileenmcnaughton
Copy link
Contributor Author

test this please


// cleanup
$this->callAPISuccess('option_value', 'delete', ['id' => $result['id']]);
$form = $this->getTestForm('CRM_Activity_Form_Activity', [], ['atype' => 800, 'cid' => $this->source]);
Copy link
Contributor

@demeritcowboy demeritcowboy Sep 25, 2023

Choose a reason for hiding this comment

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

I get a fail here because action is null, so I think it just needs to add 'action' => 'add' to the params. But also while it's a nice addition to check the template vars, what this test was about was checking that somebody doesn't mess up $form->_activityTypeName (line 267).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@demeritcowboy I've pushe dup the fix - but I am trying to avoid checking properties & check what the form outputs instead - the property is 'public' but ... not really. It's an internal form property - but what the form outputs is the variable....

Copy link
Contributor

Choose a reason for hiding this comment

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

Since removing the existing coverage isn't necessary for fixing the bug and the discussion around public vars gets into scope creep, I'd suggest a compromise to add your test as a new test, which adds some good coverage, and then this would be good to merge (with the other test fail about the action url param addressed).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@demeritcowboy actually the way I make it work to test the form is by switching to the form test wrapper - which gives a better level of testing - but it explicitly doesn't allow testing properties - other than where they have publicly supported getter methods

@@ -25,7 +25,7 @@
<table class="form-layout">
{if $activityTypeDescription }
Copy link
Contributor

Choose a reason for hiding this comment

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

This line is where it needs a rebase.

@@ -27,7 +27,7 @@
<table class="form-layout">
{if $activityTypeDescription }
Copy link
Contributor

Choose a reason for hiding this comment

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

And also a rebase here.

@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy this kinda fell off the radar but I just rebased it since that seemed to be the issue....

@demeritcowboy
Copy link
Contributor

Right. The other issue was that it changes what the existing test was testing which I'd like to keep, and that change isn't necessary to fix the bug. If it's added as a new test then this is an easy merge.

@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy are you wanting to keep the test on that property because you are accessing the property from an extension? The form-test methodology is deliberately biased against testing properties that are not supported for external use as part of trying to test the contract rather than things that are really internal to the form. We have been adding supported functions like getActivityID() & getActivityValue() (we have getParticipantID() & getParticipantValue() on a few forms.

@demeritcowboy
Copy link
Contributor

Ok what I'll do is take the test and move it to an extension and run it elsewhere.

So there's just the action param problem - I guess it's expecting CRM_Core_Action::ADD instead although that feels wrong.

@eileenmcnaughton
Copy link
Contributor Author

@demeritcowboy I can add in the getActivityValue() function if you want & add a test on that?

I'm not totally clear on the action one - what do we need to do

@demeritcowboy
Copy link
Contributor

Oh it's a different test failing than before. CRM_Case_BAO_CaseTest::testGetRelatedCases now needs to set $_REQUEST['action'] = 'add'.

For this test, the name and docblock should be changed since that's not what it's testing anymore. It's now testing the smarty template variable.

@eileenmcnaughton eileenmcnaughton force-pushed the activity_view branch 2 times, most recently from ffe3408 to 09f7a34 Compare December 3, 2023 02:52
@demeritcowboy
Copy link
Contributor

jenkins retest this please

This PR seems to keep growing...

@eileenmcnaughton
Copy link
Contributor Author

I moved getActivityValue() to a trait & added some handling for the inconsistency around action


if ($this->_action & CRM_Core_Action::DELETE) {
$action = CRM_Utils_Request::retrieve('action', 'String', $this);
if ($action === 'add') {
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't needed. Request::retrieve already does this hack.

As a general comment, I think this is unfair. This should be a 3 line PR, and now I have to r-run it again, and I've already spent a few hours reviewing it several times. All that had to happen on the last revision to get a merge was to add one line to one of the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh gawd you are right - my head was just spinning on how it was working & I couldn't see it - I'll take this out again

…the actual activity type id

When we view an activity there is code in the template that renders differently depending on the
activity type id. However, if the activity ID (atype) is wrong in the url it gives the url precedence

This is a bit obscure - I hit it when I changed the activity type id in the database & the view
did not update
@demeritcowboy demeritcowboy merged commit 6ef0fa1 into civicrm:master Dec 4, 2023
@eileenmcnaughton
Copy link
Contributor Author

Thanks @demeritcowboy - sorry this was such a drag

@eileenmcnaughton eileenmcnaughton deleted the activity_view branch December 4, 2023 19:25
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