Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
By medoman
#788808
good morning friends
i have an approval path in my company, every step in this path have a manager in the second step to forward it or send back to his employee...
these managers are members in the BDU group,
i need this manager (that participate in this case) has the privilege to cancel the case only when he is the current user for the case, any one else in the case must not have this privilege even the case creator.
please help
By zainab
#788814
A case can be cancelled only when a User is working on it, or a user who is the Process Supervisor and has the PM_CANCELCASE permission. When a manager is working on the case, set a trigger to fire when the manager opens the case to set the value of @@manager to UID of manager.

To prevent others from cancelling the case create a trigger with following code:
Code: Select all
if(!isset(@@manager) || @@USER_LOGGED<>@@manager)
{
 G::SendMessageText("You cannot cancel this case!"). 
 die(); //prevent the action from executing
 }
In this case, only when the manager is the Current User he will be able to cancel the case, no one else will be able to cancel the case even if they have the process supervisor permission. But if the Current User is the manager and some other user has Process Supervisor permission then he might be able to cancel the case, haven't check for that yet but in rest all the cases it works.

Set this trigger to fire when cancelling a case, please refer http://wiki.processmaker.com/3.1/Trigge ... tion_cases
User avatar
By amosbatto
#788827
Follow Zainab's instructions, but if you want to check if the person is a member of a group and that the logged-in user is the currently assigned user, then use this trigger code:
Code: Select all
$groupName = "BDU";
$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();
   if (!$g->verifyUserToGroup($groupID, @@USER_LOGGED)) {
      die("<font color=red>Only the manager currently assigned to the case can cancel it!</font>");
   }
   $c = new Cases();
   $aCase = $c->LoadCase(@APPLICATION, @%INDEX);
   if ($aCase['CURRENT_USER_UID'] != @@USER_LOGGED) {
      die("<font color=red>Only the manager currently assigned to the case can cancel it!</font>");
   }
}
User avatar
By amosbatto
#788856
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.

In the rapidly evolving world of online sports be[…]

STEPN integrates social networking and games that […]

Cenforce 150 is a medication used to cope with a c[…]

What's SAP FICO?

Trustworthy and skill-building, each of these actu[…]