From 39694f757d34e5fb005ed78e95745aaf72533d63 Mon Sep 17 00:00:00 2001 From: Roly Rudy Gutierrez Pinto Date: Mon, 13 Jun 2016 13:14:37 -0400 Subject: [PATCH] HOR-1060 --- gulliver/system/class.rbac.php | 2 + rbac/engine/data/mysql/insert.sql | 5 +- workflow/engine/classes/class.case.php | 126 ++++++++++++++++++ workflow/engine/classes/class.pmFunctions.php | 20 +++ workflow/engine/data/mssql/insert.sql | 1 + workflow/engine/data/mysql/insert.sql | 3 +- 6 files changed, 155 insertions(+), 2 deletions(-) diff --git a/gulliver/system/class.rbac.php b/gulliver/system/class.rbac.php index 6e8ac688f..2e7dd067c 100755 --- a/gulliver/system/class.rbac.php +++ b/gulliver/system/class.rbac.php @@ -229,6 +229,8 @@ class RBAC "Delete process cases" ), array("PER_UID" => "00000000000000000000000000000037", "PER_CODE" => "PM_EDITPERSONALINFO_CALENDAR", "PER_NAME" => "Edit personal info Calendar" + ), array("PER_UID" => "00000000000000000000000000000038", "PER_CODE" => "PM_UNCANCELCASE", + "PER_NAME" => "Undo cancel case" ) ); return $permissionsAdmin; diff --git a/rbac/engine/data/mysql/insert.sql b/rbac/engine/data/mysql/insert.sql index 85a714a7d..6b36ad467 100755 --- a/rbac/engine/data/mysql/insert.sql +++ b/rbac/engine/data/mysql/insert.sql @@ -35,7 +35,8 @@ INSERT INTO `RBAC_PERMISSIONS` VALUES ('00000000000000000000000000000034','PM_SETUP_USERS_AUTHENTICATION_SOURCES','2016-03-01 00:00:00','0000-00-00 00:00:00',1,'00000000000000000000000000000002'), ('00000000000000000000000000000035','PM_SETUP_LOGS','2016-03-01 00:00:00','0000-00-00 00:00:00',1,'00000000000000000000000000000002'), ('00000000000000000000000000000036','PM_DELETE_PROCESS_CASES','2016-03-01 00:00:00','0000-00-00 00:00:00',1,'00000000000000000000000000000002'), -('00000000000000000000000000000037','PM_EDITPERSONALINFO_CALENDAR','2016-03-01 00:00:00','0000-00-00 00:00:00',1,'00000000000000000000000000000002'); +('00000000000000000000000000000037','PM_EDITPERSONALINFO_CALENDAR','2016-03-01 00:00:00','0000-00-00 00:00:00',1,'00000000000000000000000000000002'), +('00000000000000000000000000000038','PM_UNCANCELCASE','2016-03-01 00:00:00','0000-00-00 00:00:00',1,'00000000000000000000000000000002'); INSERT INTO `RBAC_ROLES` VALUES ('00000000000000000000000000000001','','00000000000000000000000000000001','RBAC_ADMIN','2007-07-31 19:10:22','2007-08-03 12:24:36',1), @@ -82,6 +83,7 @@ INSERT INTO `RBAC_ROLES_PERMISSIONS` VALUES ('00000000000000000000000000000002','00000000000000000000000000000035'), ('00000000000000000000000000000002','00000000000000000000000000000036'), ('00000000000000000000000000000002','00000000000000000000000000000037'), +('00000000000000000000000000000002','00000000000000000000000000000038'), ('00000000000000000000000000000003','00000000000000000000000000000001'), ('00000000000000000000000000000003','00000000000000000000000000000005'), ('00000000000000000000000000000004','00000000000000000000000000000001'), @@ -117,6 +119,7 @@ INSERT INTO `RBAC_ROLES_PERMISSIONS` VALUES ('00000000000000000000000000000004','00000000000000000000000000000035'), ('00000000000000000000000000000004','00000000000000000000000000000036'), ('00000000000000000000000000000004','00000000000000000000000000000037'); +('00000000000000000000000000000004','00000000000000000000000000000038'); INSERT INTO `RBAC_SYSTEMS` VALUES ('00000000000000000000000000000001','RBAC','2007-07-31 19:10:22','2007-08-03 12:24:36',1),('00000000000000000000000000000002','PROCESSMAKER','2007-07-31 19:10:22','2007-08-03 12:24:36',1); INSERT INTO `RBAC_USERS` VALUES ('00000000000000000000000000000001','admin','21232f297a57a5a743894a0e4a801fc3','Administrator','','admin@processmaker.com','2020-01-01','2007-08-03 12:24:36','2008-02-13 07:24:07',1,'MYSQL','00000000000000000000000000000000','',''); diff --git a/workflow/engine/classes/class.case.php b/workflow/engine/classes/class.case.php index 930178246..c79d0f0a3 100755 --- a/workflow/engine/classes/class.case.php +++ b/workflow/engine/classes/class.case.php @@ -4396,6 +4396,132 @@ class Cases /*----------------------------------********---------------------------------*/ } + /** + * Un cancel case + * + * @param string $caseUID + * @param string $userUID + * @return int + */ + public function unCancelCase($appUID, $userUID) + { + try { + global $RBAC; + if ($RBAC->userCanAccess('PM_UNCANCELCASE') !== 1) { + throw new Exception(G::LoadTranslation('ID_YOU_DO_NOT_HAVE_PERMISSION')); + } + + $application = new Application(); + $rowApplication = $application->load($appUID); + if ($rowApplication["APP_STATUS"] !== "CANCELLED") { + throw new Exception(G::LoadTranslation('ID_THE_APPLICATION_IS_NOT_CANCELED', [$appUID])); + } + + $criteriaAppDelay = new Criteria('workflow'); + $criteriaAppDelay->add(AppDelayPeer::APP_UID, $appUID); + $criteriaAppDelay->add(AppDelayPeer::APP_STATUS, 'CANCELLED'); + $criteriaAppDelay->add(AppDelayPeer::PRO_UID, $rowApplication['PRO_UID']); + $criteriaAppDelay->addDescendingOrderByColumn(AppDelayPeer::APP_ENABLE_ACTION_DATE); + $resultSetAppDelay = AppDelayPeer::doSelectRS($criteriaAppDelay); + $resultSetAppDelay->setFetchmode(ResultSet::FETCHMODE_ASSOC); + $resultSetAppDelay->next(); + $rowAppDelay = $resultSetAppDelay->getRow(); + if (!isset($rowAppDelay['APP_STATUS'])) { + throw new Exception(G::LoadTranslation('ID_THREAD_STATUS_DOES_NOT_EXIST_FOR_THE_APPLICATION.', [$appUID])); + } + + $users = new Users(); + $rowUsers = $users->load($userUID); + + //Application + $rowApplication['APP_STATUS'] = 'TO_DO'; + $rowApplication['APP_UPDATE_DATE'] = date('Y-m-d H:i:s'); + $application->update($rowApplication); + + //AppDelegation + $appDelegation = new AppDelegation(); + $rowAppDelegation = $appDelegation->Load($appUID, $rowAppDelay['APP_DEL_INDEX']); + + $appDelegation = new AppDelegation(); + $delIndex = $appDelegation->createAppDelegation($rowAppDelegation['PRO_UID'], $rowAppDelegation['APP_UID'], $rowAppDelegation['TAS_UID'], $userUID, $rowAppDelay['APP_THREAD_INDEX']); + + //AppThread + $dataAppThread = [ + 'APP_UID' => $rowApplication['APP_UID'], + 'APP_THREAD_INDEX' => $rowAppDelay['APP_THREAD_INDEX'], + 'APP_THREAD_STATUS' => 'OPEN', + 'DEL_INDEX' => $delIndex + ]; + $appThread = new AppThread(); + $appThread->update($dataAppThread); + + //AppDelay + $dataAppDelay = [ + 'PRO_UID' => $rowApplication['PRO_UID'], + 'APP_UID' => $rowApplication['APP_UID'], + 'APP_THREAD_INDEX' => $rowAppDelay['APP_THREAD_INDEX'], + 'APP_DELINDEX' => $delIndex, + 'APP_TYPE' => 'UNCANCEL', + 'APP_STATUS' => $rowApplication['APP_STATUS'], + 'APP_NEXT_TASK' => 0, + 'APP_DELEGATION_USER' => $userUID, + 'APP_ENABLE_ACTION_USER' => $userUID, + 'APP_ENABLE_ACTION_DATE' => date('Y-m-d H:i:s'), + 'APP_DISABLE_ACTION_USER' => 0 + ]; + $appDelay = new AppDelay(); + $appDelay->create($dataAppDelay); + + //ListCanceled + $criteriaListCanceled = new Criteria("workflow"); + $criteriaListCanceled->add(ListCanceledPeer::APP_UID, $appUID); + $resultSetListCanceled = ListCanceledPeer::doSelectRS($criteriaListCanceled); + $resultSetListCanceled->setFetchmode(ResultSet::FETCHMODE_ASSOC); + $resultSetListCanceled->next(); + $rowListCanceled = $resultSetListCanceled->getRow(); + ListCanceledPeer::doDelete($criteriaListCanceled); + $usrTotalCancelled = $rowUsers['USR_TOTAL_CANCELLED'] - 1; + + //ListInbox + $rowListCanceled['DEL_PREVIOUS_USR_USERNAME'] = $rowListCanceled['DEL_CURRENT_USR_USERNAME']; + $rowListCanceled['DEL_PREVIOUS_USR_FIRSTNAME'] = $rowListCanceled['DEL_CURRENT_USR_FIRSTNAME']; + $rowListCanceled['DEL_PREVIOUS_USR_LASTNAME'] = $rowListCanceled['DEL_CURRENT_USR_LASTNAME']; + $rowListCanceled['APP_STATUS'] = 'TO_DO'; + $rowListCanceled['APP_UPDATE_DATE'] = date('Y-m-d H:i:s'); + $rowListCanceled['DEL_RISK_DATE'] = date('Y-m-d H:i:s'); + $rowListCanceled['DEL_INDEX'] = $delIndex; + unset($rowListCanceled['DEL_CURRENT_USR_USERNAME']); + unset($rowListCanceled['DEL_CURRENT_USR_FIRSTNAME']); + unset($rowListCanceled['DEL_CURRENT_USR_LASTNAME']); + unset($rowListCanceled['APP_CANCELED_DATE']); + $listInbox = new ListInbox(); + $listInbox->create($rowListCanceled); + $usrTotalInbox = $rowUsers['USR_TOTAL_INBOX'] + 1; + + //Users + $users->update([ + 'USR_UID' => $userUID, + 'USR_TOTAL_INBOX' => $usrTotalInbox, + 'USR_TOTAL_CANCELLED' => $usrTotalCancelled + ]); + + //ListParticipatedLast + $criteriaListParticipatedLast = new Criteria("workflow"); + $criteriaListParticipatedLast->add(ListParticipatedLastPeer::APP_UID, $appUID); + $resultSetListParticipatedLast = ListParticipatedLastPeer::doSelectRS($criteriaListParticipatedLast); + $resultSetListParticipatedLast->setFetchmode(ResultSet::FETCHMODE_ASSOC); + $resultSetListParticipatedLast->next(); + $rowListParticipatedLast = $resultSetListParticipatedLast->getRow(); + $rowListParticipatedLast['APP_STATUS'] = 'TO_DO'; + $rowListParticipatedLast['DEL_THREAD_STATUS'] = 'OPEN'; + $rowListParticipatedLast['DEL_INIT_DATE'] = null; + $listParticipatedLast = new ListParticipatedLast(); + $listParticipatedLast->update($rowListParticipatedLast); + } catch (Exception $oException) { + throw $oException; + } + } + /* * reactive a case * diff --git a/workflow/engine/classes/class.pmFunctions.php b/workflow/engine/classes/class.pmFunctions.php index 479c7a4af..5776a3669 100755 --- a/workflow/engine/classes/class.pmFunctions.php +++ b/workflow/engine/classes/class.pmFunctions.php @@ -3084,6 +3084,26 @@ function PMFGeti18nText($id, $category, $lang = "en") return $text; } +/** + * @method + * The requested text in the specified language | If not found returns false + * @name PMFUnCancelCase + * @label PMF Un Cancel Case + * @param string | $caseUID | ID Case | Is the unique UID of the case + * @param string | $userUID | ID User | Is the unique ID of the user who will uncancel the case + * @return int | $value | Return | Returns 1 if the case was successfully uncancelled, otherwise returns 0 if an error ocurred + */ +function PMFUnCancelCase($caseUID, $userUID) +{ + try { + $cases = new Cases(); + $cases->unCancelCase($caseUID, $userUID); + return 1; + } catch (Exception $oException) { + return 0; + } +} + /** * @method * Function to return an array of objects containing the properties of the fields diff --git a/workflow/engine/data/mssql/insert.sql b/workflow/engine/data/mssql/insert.sql index 11e34b8b1..c66414a22 100755 --- a/workflow/engine/data/mssql/insert.sql +++ b/workflow/engine/data/mssql/insert.sql @@ -29,6 +29,7 @@ SELECT 'PER_NAME','','00000000000000000000000000000034','en','Setup User Authent SELECT 'PER_NAME','','00000000000000000000000000000035','en','Setup Logs' UNION ALL SELECT 'PER_NAME','','00000000000000000000000000000036','en','Delete process cases' UNION ALL SELECT 'PER_NAME','','00000000000000000000000000000037','en','Edit personal info Calendar' UNION ALL +SELECT 'PER_NAME','','00000000000000000000000000000038','en','Undo cancel case' UNION ALL SELECT 'PER_NAME','','00000000000000000000000000000013','en','Delete cases' UNION ALL SELECT 'PER_NAME','','00000000000000000000000000000012','en','WebDav' UNION ALL SELECT 'PER_NAME','','00000000000000000000000000000011','en','Dashboard' UNION ALL diff --git a/workflow/engine/data/mysql/insert.sql b/workflow/engine/data/mysql/insert.sql index 25a8a314c..391b36807 100644 --- a/workflow/engine/data/mysql/insert.sql +++ b/workflow/engine/data/mysql/insert.sql @@ -43,7 +43,8 @@ INSERT INTO CONTENT (CON_CATEGORY,CON_PARENT,CON_ID,CON_LANG,CON_VALUE) VALUES ('PER_NAME','','00000000000000000000000000000034','en','Setup User Authentication Sources'), ('PER_NAME','','00000000000000000000000000000035','en','Setup Logs'), ('PER_NAME','','00000000000000000000000000000036','en','Delete process cases'), -('PER_NAME','','00000000000000000000000000000037','en','Edit personal info Calendar'); +('PER_NAME','','00000000000000000000000000000037','en','Edit personal info Calendar'), +('PER_NAME','','00000000000000000000000000000038','en','Undo cancel case'); INSERT INTO LANGUAGE (LAN_ID,LAN_LOCATION,LAN_NAME,LAN_NATIVE_NAME,LAN_DIRECTION,LAN_WEIGHT,LAN_ENABLED,LAN_CALENDAR) VALUES ('aa','','Afar','','L','0','0','GREGORIAN'),