PMCORE-3167

This commit is contained in:
Paula Quispe
2021-07-19 13:19:55 -04:00
parent 6ba7eb79a6
commit a512c3feff
4 changed files with 133 additions and 121 deletions

View File

@@ -46,7 +46,7 @@ class rbacTest extends TestCase
$rbac->initRBAC(); $rbac->initRBAC();
$result = $rbac->updateUser($data, $rolCode); $result = $rbac->updateUser($data, $rolCode);
//assert // assert
$user = \ProcessMaker\Model\RbacUsers::where('USR_UID', '=', $data['USR_UID'])->first()->toArray(); $user = \ProcessMaker\Model\RbacUsers::where('USR_UID', '=', $data['USR_UID'])->first()->toArray();
$this->assertEquals($data['USR_DUE_DATE'], $user['USR_DUE_DATE']); $this->assertEquals($data['USR_DUE_DATE'], $user['USR_DUE_DATE']);
} }

View File

@@ -42,6 +42,7 @@ class CasesTest extends TestCase
* This checks the delete case * This checks the delete case
* *
* @covers \ProcessMaker\BusinessModel\Cases::deleteCase() * @covers \ProcessMaker\BusinessModel\Cases::deleteCase()
*
* @test * @test
* @expectedException Exception * @expectedException Exception
*/ */
@@ -63,6 +64,7 @@ class CasesTest extends TestCase
* This checks the delete case * This checks the delete case
* *
* @covers \ProcessMaker\BusinessModel\Cases::deleteCase() * @covers \ProcessMaker\BusinessModel\Cases::deleteCase()
*
* @test * @test
* @expectedException Exception * @expectedException Exception
*/ */
@@ -84,6 +86,7 @@ class CasesTest extends TestCase
* This checks the delete case * This checks the delete case
* *
* @covers \ProcessMaker\BusinessModel\Cases::deleteCase() * @covers \ProcessMaker\BusinessModel\Cases::deleteCase()
*
* @test * @test
* @expectedException Exception * @expectedException Exception
*/ */

View File

@@ -53,6 +53,8 @@ use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Documents; use ProcessMaker\Model\Documents;
use ProcessMaker\Model\ListUnassigned; use ProcessMaker\Model\ListUnassigned;
use ProcessMaker\Model\Triggers; use ProcessMaker\Model\Triggers;
use ProcessMaker\Model\ProcessUser;
use ProcessMaker\Model\User;
use ProcessMaker\Plugins\PluginRegistry; use ProcessMaker\Plugins\PluginRegistry;
use ProcessMaker\Services\OAuth2\Server; use ProcessMaker\Services\OAuth2\Server;
use ProcessMaker\Util\DateTime as UtilDateTime; use ProcessMaker\Util\DateTime as UtilDateTime;
@@ -60,7 +62,6 @@ use ProcessMaker\Validation\ExceptionRestApi;
use ProcessMaker\Validation\ValidationUploadedFiles; use ProcessMaker\Validation\ValidationUploadedFiles;
use ProcessMaker\Validation\Validator as FileValidator; use ProcessMaker\Validation\Validator as FileValidator;
use ProcessPeer; use ProcessPeer;
use ProcessUser;
use ProcessUserPeer; use ProcessUserPeer;
use RBAC; use RBAC;
use ResultSet; use ResultSet;
@@ -868,39 +869,72 @@ class Cases
throw $e; throw $e;
} }
} }
/**
* This function check if some user has participation over the case
*
* @param string $usrUid
* @param int $caseNumber
* @param int $index
*
* @return bool
*/
public function participation($usrUid, $caseNumber, $index)
{
$userId = User::getId($usrUid);
$query = Delegation::query()->select(['APP_NUMBER'])->case($caseNumber)->index($index)->isThreadOpen();
$query1 = clone $query;
$result = $query->userId($userId)->limit(1)->get()->values()->toArray();
$permission = empty($result) ? false : true;
// Review if the user is supervisor
if (empty($result)) {
$processes = ProcessUser::getProcessesOfSupervisor($usrUid);
$query1->processInList($processes);
$result = $query1->get()->values()->toArray();
$permission = empty($result) ? false : true;
}
return $permission;
}
/** /**
* Reassign Case * Reassign Case
* *
* @param string $applicationUid Unique id of Case * @param string $appUid Unique id of Case
* @param string $userUid Unique id of User * @param string $usrUid Unique id of User
* @param string $delIndex * @param int $delIndex
* @param string $userUidSource Unique id of User Source * @param string $userSource Unique id of User Source
* @param string $userUid $userUidTarget id of User Target * @param string $userTarget $userUidTarget id of User Target
* @param string $reason
* @param boolean $sendMail
* *
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
public function updateReassignCase($applicationUid, $userUid, $delIndex, $userUidSource, $userUidTarget) public function updateReassignCase($appUid, $usrUid, $delIndex, $userSource, $userTarget, $reason = '', $sendMail = false)
{ {
try { try {
if (!$delIndex) { if (!$delIndex) {
$delIndex = AppDelegation::getCurrentIndex($applicationUid); $delIndex = AppDelegation::getCurrentIndex($appUid);
} }
/** Reassign case */
$ws = new WsBase(); $ws = new WsBase();
$fields = $ws->reassignCase($userUid, $applicationUid, $delIndex, $userUidSource, $userUidTarget); $result = $ws->reassignCase($usrUid, $appUid, $delIndex, $userSource, $userTarget);
$array = json_decode(json_encode($fields), true); $result = (object)$result;
if (array_key_exists("status_code", $array)) { if (isset($result->status_code)) {
if ($array ["status_code"] != 0) { if ($result->status_code !== 0) {
throw (new Exception($array ["message"])); throw new Exception($result->message);
} else {
unset($array['status_code']);
unset($array['message']);
unset($array['timestamp']);
} }
} else { } else {
throw new Exception(G::LoadTranslation("ID_CASES_INCORRECT_INFORMATION", array($applicationUid))); throw new Exception(G::LoadTranslation("ID_CASES_INCORRECT_INFORMATION", [$appUid]));
}
/** Add the note */
if (!empty($reason)) {
$noteContent = $reason;
// Define the Case for register a case note
$cases = new BmCases();
$response = $cases->addNote($appUid, $usrUid, $noteContent, $sendMail);
} }
} catch (Exception $e) { } catch (Exception $e) {
throw $e; throw $e;
@@ -970,66 +1004,60 @@ class Cases
* Put pause case * Put pause case
* *
* @access public * @access public
* @param string $app_uid , Uid for case * @param string $appUid , Uid for case
* @param string $usr_uid , Uid for user * @param string $usrUid , Uid for user
* @param bool|string $del_index * @param bool|string $index
* @param null|string $unpaused_date , Date for unpaused * @param null|string $date , Date for unpaused
* @param string $time , Time for unpaused
* @param string $reason
* @param bool $sendMail
* *
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
public function putPauseCase($app_uid, $usr_uid, $del_index = false, $unpaused_date = null) public function putPauseCase($appUid, $usrUid, $index = 0, $date = null, $time = '00:00', $reason = '', $sendMail = false)
{ {
Validator::isString($app_uid, '$app_uid'); Validator::isString($appUid, '$app_uid');
Validator::isString($usr_uid, '$usr_uid'); Validator::isString($usrUid, '$usr_uid');
Validator::appUid($appUid, '$app_uid');
Validator::appUid($app_uid, '$app_uid'); Validator::usrUid($usrUid, '$usr_uid');
Validator::usrUid($usr_uid, '$usr_uid'); Validator::isInteger($index, '$del_index');
// Get the last index
if ($del_index === false) { if ($index === 0) {
$del_index = AppDelegation::getCurrentIndex($app_uid); $index = AppDelegation::getCurrentIndex($appUid);
} }
// Get the case status
Validator::isInteger($del_index, '$del_index');
$case = new ClassesCases(); $case = new ClassesCases();
$fields = $case->loadCase($app_uid); $fields = $case->loadCase($appUid);
$caseNumber = $fields['APP_NUMBER'];
if ($fields['APP_STATUS'] == 'CANCELLED') { if ($fields['APP_STATUS'] == 'CANCELLED') {
throw (new Exception(G::LoadTranslation("ID_CASE_IS_CANCELED", array($app_uid)))); throw new Exception(G::LoadTranslation("ID_CASE_IS_CANCELED", [$appUid]));
}
// Check if the case was not paused
$delay = new AppDelay();
if ($delay->isPaused($appUid, $index)) {
throw new Exception(G::LoadTranslation("ID_CASE_PAUSED", [$appUid]));
}
// Review if the user has participation or is supervisor
$permission = $this->participation($usrUid, $caseNumber, $index);
if (!$permission) {
throw new Exception(G::LoadTranslation("ID_CASE_USER_INVALID_PAUSED_CASE", [$usrUid]));
} }
$oDelay = new AppDelay(); if ($date != null) {
Validator::isDate($date, 'Y-m-d', '$unpaused_date');
if ($oDelay->isPaused($app_uid, $del_index)) {
throw (new Exception(G::LoadTranslation("ID_CASE_PAUSED", array($app_uid))));
} }
$processUser = new ProcessUser(); /** Pause case */
$arrayProcess = $processUser->getProUidSupervisor($usr_uid); $case->pauseCase($appUid, $index, $usrUid, $date . ' ' . $time);
$criteria = new Criteria("workflow"); /** Add the note */
if (!empty($reason)) {
$criteria->addSelectColumn(AppDelegationPeer::APP_UID); $noteContent = $reason;
$criteria->add(AppDelegationPeer::APP_UID, $app_uid, Criteria::EQUAL); // Define the Case for register a case note
$criteria->add(AppDelegationPeer::DEL_INDEX, $del_index, Criteria::EQUAL); $cases = new BmCases();
$criteria->add( $response = $cases->addNote($appUid, $usrUid, $noteContent, $sendMail);
$criteria->getNewCriterion(AppDelegationPeer::USR_UID, $usr_uid, Criteria::EQUAL)->addOr(
$criteria->getNewCriterion(AppDelegationPeer::PRO_UID, $arrayProcess, Criteria::IN))
);
$criteria->add(AppDelegationPeer::DEL_THREAD_STATUS, "OPEN", Criteria::EQUAL);
$criteria->add(AppDelegationPeer::DEL_FINISH_DATE, null, Criteria::ISNULL);
$rsCriteria = AppDelegationPeer::doSelectRS($criteria);
if (!$rsCriteria->next()) {
throw (new Exception(G::LoadTranslation("ID_CASE_USER_INVALID_PAUSED_CASE", array($usr_uid))));
} }
if ($unpaused_date != null) {
Validator::isDate($unpaused_date, 'Y-m-d', '$unpaused_date');
}
$case->pauseCase($app_uid, $del_index, $usr_uid, $unpaused_date);
} }
/** /**
@@ -1043,45 +1071,33 @@ class Cases
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
public function putUnpauseCase($app_uid, $usr_uid, $del_index = false) public function putUnpauseCase($appUid, $usrUid, $index = false)
{ {
Validator::isString($app_uid, '$app_uid'); Validator::isString($appUid, '$app_uid');
Validator::isString($usr_uid, '$usr_uid'); Validator::isString($usrUid, '$usr_uid');
Validator::appUid($appUid, '$app_uid');
Validator::usrUid($usrUid, '$usr_uid');
Validator::appUid($app_uid, '$app_uid'); if ($index === false) {
Validator::usrUid($usr_uid, '$usr_uid'); $index = AppDelegation::getCurrentIndex($appUid);
if ($del_index === false) {
$del_index = AppDelegation::getCurrentIndex($app_uid);
} }
Validator::isInteger($del_index, '$del_index'); Validator::isInteger($index, '$del_index');
$oDelay = new AppDelay(); $delay = new AppDelay();
if (!$delay->isPaused($appUid, $index)) {
if (!$oDelay->isPaused($app_uid, $del_index)) { throw new Exception(G::LoadTranslation("ID_CASE_NOT_PAUSED", [$appUid]));
throw (new Exception(G::LoadTranslation("ID_CASE_NOT_PAUSED", array($app_uid))));
} }
$processUser = new ProcessUser(); // Review if the user has participation or is supervisor
$arrayProcess = $processUser->getProUidSupervisor($usr_uid); $caseNumber = ModelApplication::getCaseNumber($appUid);
$permission = $this->participation($usrUid, $caseNumber, $index);
$criteria = new Criteria("workflow"); if (!$permission) {
$criteria->addSelectColumn(AppDelegationPeer::APP_UID); throw new Exception(G::LoadTranslation("ID_CASE_USER_INVALID_UNPAUSE_CASE", [$usrUid]));
$criteria->add(AppDelegationPeer::APP_UID, $app_uid, Criteria::EQUAL);
$criteria->add(AppDelegationPeer::DEL_INDEX, $del_index, Criteria::EQUAL);
$criteria->add(
$criteria->getNewCriterion(AppDelegationPeer::USR_UID, $usr_uid, Criteria::EQUAL)->addOr(
$criteria->getNewCriterion(AppDelegationPeer::PRO_UID, $arrayProcess, Criteria::IN))
);
$rsCriteria = AppDelegationPeer::doSelectRS($criteria);
if (!$rsCriteria->next()) {
throw (new Exception(G::LoadTranslation("ID_CASE_USER_INVALID_UNPAUSE_CASE", array($usr_uid))));
} }
/** Unpause case */
$case = new ClassesCases(); $case = new ClassesCases();
$case->unpauseCase($app_uid, $del_index, $usr_uid); $case->unpauseCase($appUid, $index, $usrUid);
} }
/** /**
@@ -1946,27 +1962,18 @@ class Cases
$arrayResult = $this->getStatusInfo($app_uid); $arrayResult = $this->getStatusInfo($app_uid);
if ($arrayResult["APP_STATUS"] == "CANCELLED") { if ($arrayResult["APP_STATUS"] == "CANCELLED") {
throw new Exception(G::LoadTranslation("ID_CASE_CANCELLED", array($app_uid))); throw new Exception(G::LoadTranslation("ID_CASE_CANCELLED", [$app_uid]));
} }
if ($arrayResult["APP_STATUS"] == "COMPLETED") { if ($arrayResult["APP_STATUS"] == "COMPLETED") {
throw new Exception(G::LoadTranslation("ID_CASE_IS_COMPLETED", array($app_uid))); throw new Exception(G::LoadTranslation("ID_CASE_IS_COMPLETED", [$app_uid]));
} }
$processUser = new ProcessUser(); // Review if the user has participation or is supervisor
$listProcess = $processUser->getProUidSupervisor($usr_uid); $caseNumber = ModelApplication::getCaseNumber($app_uid);
$criteria = new Criteria("workflow"); $permission = $this->participation($usr_uid, $caseNumber, $del_index);
$criteria->addSelectColumn(AppDelegationPeer::APP_UID); if (!$permission) {
$criteria->add(AppDelegationPeer::APP_UID, $app_uid, Criteria::EQUAL); throw new Exception(G::LoadTranslation("ID_NO_PERMISSION_NO_PARTICIPATED", [$usr_uid]));
$criteria->add(AppDelegationPeer::USR_UID, $usr_uid, Criteria::EQUAL);
$criteria->add(
$criteria->getNewCriterion(AppDelegationPeer::USR_UID, $usr_uid, Criteria::EQUAL)->addOr(
$criteria->getNewCriterion(AppDelegationPeer::PRO_UID, $listProcess, Criteria::IN))
);
$rsCriteria = AppDelegationPeer::doSelectRS($criteria);
if (!$rsCriteria->next()) {
throw (new Exception(G::LoadTranslation("ID_NO_PERMISSION_NO_PARTICIPATED", array($usr_uid))));
} }
$_SESSION['APPLICATION'] = $app_uid; $_SESSION['APPLICATION'] = $app_uid;

View File

@@ -134,7 +134,7 @@ class Cases extends Api
} }
break; break;
case 'doPutReassignCase': case 'doPutReassignCase':
$appUid = $this->parameters[$arrayArgs['app_uid']]; $appUid = $this->parameters[$arrayArgs['appUid']];
$usrUid = $this->getUserId(); $usrUid = $this->getUserId();
$case = new BmCases(); $case = new BmCases();
$user = new BmUser(); $user = new BmUser();
@@ -877,19 +877,21 @@ class Cases extends Api
* @param string $appUid {@min 32}{@max 32} * @param string $appUid {@min 32}{@max 32}
* @param string $usr_uid_source {@from body} {@min 32}{@max 32} * @param string $usr_uid_source {@from body} {@min 32}{@max 32}
* @param string $usr_uid_target {@from body} {@min 32}{@max 32} * @param string $usr_uid_target {@from body} {@min 32}{@max 32}
* @param string $del_index {@from body} * @param int $del_index {@from body}
* @param string $reason {@from body}
* @param boolean $sendMail {@from body}
* *
* @throws RestException * @throws RestException
* *
* @access protected * @access protected
* @class AccessControl {@className \ProcessMaker\Services\Api\Cases} * @class AccessControl {@className \ProcessMaker\Services\Api\Cases}
*/ */
public function doPutReassignCase($appUid, $usr_uid_source, $usr_uid_target, $del_index = null) public function doPutReassignCase($appUid, $usr_uid_source, $usr_uid_target, $del_index = null, $reason = '', $sendMail = false)
{ {
try { try {
$userUid = $this->getUserId(); $userUid = $this->getUserId();
$cases = new BmCases(); $cases = new BmCases();
$cases->updateReassignCase($appUid, $userUid, $del_index, $usr_uid_source, $usr_uid_target); $cases->updateReassignCase($appUid, $userUid, $del_index, $usr_uid_source, $usr_uid_target, $reason, $sendMail);
} catch (Exception $e) { } catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
} }
@@ -953,22 +955,22 @@ class Cases extends Api
* *
* @param string $appUid {@min 1}{@max 32} * @param string $appUid {@min 1}{@max 32}
* @param string $unpaused_date {@from body} * @param string $unpaused_date {@from body}
* @param string $unpaused_time {@from body}
* @param int $index {@from body}
* @param string $reason {@from body}
* @param boolean $sendMail {@from body}
* *
* @throws RestException * @throws RestException
* *
* @access protected * @access protected
* @class AccessControl {@permission PM_CASES} * @class AccessControl {@permission PM_CASES}
*/ */
public function doPutPauseCase($appUid, $unpaused_date = null) public function doPutPauseCase($appUid, $unpaused_date = null, $unpaused_time = '00:00', $index = 0, $reason = '', $sendMail = false)
{ {
try { try {
$userUid = $this->getUserId(); $userUid = $this->getUserId();
$cases = new BmCases(); $cases = new BmCases();
if ($unpaused_date == null) { $cases->putPauseCase($appUid, $userUid, $index, $unpaused_date, $unpaused_time, $reason, $sendMail);
$cases->putPauseCase($appUid, $userUid);
} else {
$cases->putPauseCase($appUid, $userUid, false, $unpaused_date);
}
} catch (Exception $e) { } catch (Exception $e) {
throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()); throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
} }