I just tried my code with an unassigned user who is a process supervisor and I see that you are right. If you call die() or throw new Exception() in the trigger code in current versions of ProcessMaker, it no longer stops the Cases::cancelCase() code from executing. It used to work in previous versions of PM, but it no longer works. The case can be reopened later with trigger code, but at this point the case hasn't yet been canceled, so the trigger can't reopen it.
You can always hack the PM code, but remember that your changes will be overwritten every time you upgrade PM.
You can change the code of Cases::cancelCase() in workflow/engine/classes/class.case.php
Change line 4010 (line number may be different in your version), from:
Code: Select all $this->getExecuteTriggerProcess($sApplicationUID, 'CANCELED');
To:
Code: Select all //$this->getExecuteTriggerProcess($sApplicationUID, 'CANCELED');
$groupName = "Managers"; //change to name of your group
$result = executeQuery("SELECT CON_ID FROM CONTENT WHERE CON_VALUE='$groupName'
AND CON_CATEGORY='GRP_TITLE'");
if (is_array($result) and count($result) > 0) {
$groupId = $result[1]['CON_ID'];
G::LoadClass("groups");
$g = new Groups();
$curUserId = $_SESSION['USER_LOGGED'];
if (!$g->verifyUserToGroup($groupId, $curUserId)) {
$msg = "Only people in the $groupName group can cancel cases!";
throw new Exception($msg);
}
$c = new Cases();
$aCase = $c->LoadCase($_SESSION['APPLICATION'], $_SESSION['INDEX']);
if ($aCase['CURRENT_USER_UID'] != $_SESSION['USER_LOGGED']) {
$msg = "Only the manager currently assigned to the case can cancel it!";
throw new Exception($msg);
}
}
This will stop the cancel action, but it will show a very ugly dialog box that says "System exception", so it looks like something is broken.
The more graceful way to handle this is to change the code of Actions.cancelCase() in line 896 of workflow/engine/templates/cases/open.js, but you have to put the above code in a trigger, but change it to set a variable if the case can be cancelled. Then use Ext.ajax() to execute the /cases/{app_uid}/execute-trigger/{tri_uid} endpoint and then call cases/{app_uid}/variables to get the variable to see if the cancel action can continue.