1

I want to modify CiviCase so that every user with the right "view my cases and activities" can see and use the "Print a Report" button in the Case View. Right now, this is only granted to users with the "view all cases and activities" right.

I modified a template (sites/default/files/civicrm/templates_c/en_US/%%64/643/643EC55F%%CaseView.tpl.php) where I found the "Print Report" link in the following code:

<?php if ($this->_tpl_vars['hasAccessToMyCases']): ?> &nbsp;

          <a class="crm-hover-button action-item no-popup" href="<?php echo CRM_Utils_System::crmURL(array('p' => 'civicrm/case/report/print','q' => "all=1&redact=0&cid=".($this->_tpl_vars['contactID'])."&caseID=".($this->_tpl_vars['caseId'])."&asn="), $this);?>
"><i class="crm-i fa-print" aria-hidden="true"></i> <?php $this->_tag_stack[] = array('ts', array()); $_block_repeat=true;smarty_block_ts($this->_tag_stack[count($this->_tag_stack)-1][1], null, $this, $_block_repeat);while ($_block_repeat) { ob_start(); ?>Print Report<?php $_block_content = ob_get_contents(); ob_end_clean(); $_block_repeat=false;echo smarty_block_ts($this->_tag_stack[count($this->_tag_stack)-1][1], $_block_content, $this, $_block_repeat); }  array_pop($this->_tag_stack); ?></a>
        <?php endif; ?>

and changed the condition to:

<?php if ($this->_tpl_vars['hasAccessToMyCases']): ?> &nbsp;

Now, the "Print Report" button appears also when I log in as a user that has only "view my cases and activities" rights. But when I click on it, I get redirected to the (non-logged-in) startpage.

Does anybody have an idea what else needs to be changed?

Edit: I created an extension including Demerit's code. It was necessary to additionally change the permission in the file templates/CRM/Case/Form/CaseView.tpl so the button will be visible in the first place. Though, the functionality doesn't work yet.

Edit: I think the problem is that I am setting the permission to "view all cases and activities" only on the CaseView form, but not the page that opens when user clicks 'Print Report'. I suppose the permissions for that page are set in sites/all/modules/civicrm/CRM/Report/Page/Report.php.

1
  • I made a typo. Have updated. But I admit I haven't tested the solution, just pointing in a direction to go.
    – Demerit
    Commented Sep 30, 2020 at 15:03

2 Answers 2

1

sites/default/files/civicrm/templates_c is where temporary compiled files live. You could try instead editing templates/CRM/Case/Form/CaseView.tpl but there is no such thing as hasAccessToMyCases (where you've just replaced "All" with "My") so you'd need to use something else. But also note this will break when you upgrade since the file will get replaced.

What I would do is create an extension and in hook_civicrm_buildForm I would do something like:

if ($formName == 'CRM_Case_Form_CaseView') {
  $form->assign('hasAccessToAllCases',
    CRM_Core_Permission::check('access my cases and activities'));
}

This would also give access to the Audit Report, but you're probably ok with that since it's just a variation of the Print Report. I vaguely remember the original reason for restricting being something like "this would make it too easy for somebody to print it and then give it to an unauthorized person, either on purpose or inadvertently". It was a different era.

But it may also allow access to other things it shouldn't. Would need to test.

Then you also need to edit this line in CRM/Case/xml/Menu/Case.xml which controls access to urls, and then clear civi caches after at Admin - System Settings - Cleanup Caches.

<access_arguments>access all cases and activities</access_arguments>

change to

<access_arguments>access my cases and activities</access_arguments>

Also when you get redirected like that, if you then visit any civi page it will show you the actual error.

4
  • In templates/CRM/Case/Form/CaseView.tpl there is such a thing as hasAccessToMyCases. It needs to be changed for the Print-Report button to appear.
    – emma
    Commented Oct 1, 2020 at 8:38
  • There is hasAccessToAllCases not hasAccessToMyCases. The above code reassigns the former's value. For your 2nd edit above, you might be right there is somewhere else you need to also update.
    – Demerit
    Commented Oct 1, 2020 at 12:47
  • Have updated with the other place you need to update, and I've actually tested it this time.
    – Demerit
    Commented Oct 1, 2020 at 14:04
  • Now it works!! Thanks a lot!
    – emma
    Commented Oct 5, 2020 at 8:38
0

I now created a small extension for that purpose: https://github.com/5knots/de.5knoten.access-to-print-report

It is my first extension and I am open for any comments on that :)

1
  • Nice. The extension has a couple copies of core files in its root directory that I don't think would do anything. Are they just there for your own reference?
    – Demerit
    Commented Dec 11, 2020 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.