HOR-2482
Endpoint: POST /api/1.0/{workspace}/cases/reassign/ no funciona correctamente
This commit is contained in:
@@ -12,6 +12,7 @@ use \CasesPeer;
|
|||||||
class Cases
|
class Cases
|
||||||
{
|
{
|
||||||
private $formatFieldNameInUppercase = true;
|
private $formatFieldNameInUppercase = true;
|
||||||
|
private $messageResponse = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the format of the fields name (uppercase, lowercase)
|
* Set the format of the fields name (uppercase, lowercase)
|
||||||
@@ -2878,6 +2879,7 @@ class Cases
|
|||||||
*
|
*
|
||||||
* return json Return an json with the result of the reassigned cases.
|
* return json Return an json with the result of the reassigned cases.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function doPostReassign($data)
|
public function doPostReassign($data)
|
||||||
{
|
{
|
||||||
if (!is_array($data)) {
|
if (!is_array($data)) {
|
||||||
@@ -2888,112 +2890,125 @@ class Cases
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$dataResponse = $data;
|
$dataResponse = $data;
|
||||||
|
|
||||||
//Verify data
|
|
||||||
$arrayCasesToReassign = $data['cases'];
|
|
||||||
|
|
||||||
$arrayMsg = [];
|
|
||||||
|
|
||||||
foreach ($arrayCasesToReassign as $key => $value) {
|
|
||||||
$appDelegation = \AppDelegationPeer::retrieveByPK($value['APP_UID'], $value['DEL_INDEX']);
|
|
||||||
|
|
||||||
if (is_null($appDelegation)) {
|
|
||||||
$arrayMsg[] = [
|
|
||||||
'app_uid' => $value['APP_UID'],
|
|
||||||
'del_index' => $value['DEL_INDEX'],
|
|
||||||
'result' => 0,
|
|
||||||
'status' => 'DELEGATION_NOT_EXISTS'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($arrayMsg)) {
|
|
||||||
return ['cases' => $arrayMsg];
|
|
||||||
}
|
|
||||||
|
|
||||||
$task = new \ProcessMaker\BusinessModel\Task();
|
|
||||||
$supervisor = new \ProcessMaker\BusinessModel\ProcessSupervisor();
|
|
||||||
|
|
||||||
$userUid = $data['usr_uid_target'];
|
|
||||||
|
|
||||||
foreach ($arrayCasesToReassign as $value) {
|
|
||||||
$appDelegation = \AppDelegationPeer::retrieveByPK($value['APP_UID'], $value['DEL_INDEX']);
|
|
||||||
|
|
||||||
//Verify data
|
|
||||||
$taskUid = $appDelegation->getTasUid();
|
|
||||||
|
|
||||||
$flagBoolean = $task->checkUserOrGroupAssignedTask($taskUid, $userUid);
|
|
||||||
$flagps = $supervisor->isUserProcessSupervisor($appDelegation->getProUid(), $userUid);
|
|
||||||
|
|
||||||
if (!$flagBoolean && !$flagps) {
|
|
||||||
$arrayMsg[] = [
|
|
||||||
'app_uid' => $value['APP_UID'],
|
|
||||||
'del_index' => $value['DEL_INDEX'],
|
|
||||||
'result' => 0,
|
|
||||||
'status' => 'USER_NOT_ASSIGNED_TO_TASK'
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($arrayMsg)) {
|
|
||||||
return ['cases' => $arrayMsg];
|
|
||||||
}
|
|
||||||
|
|
||||||
G::LoadClass('case');
|
|
||||||
$oCases = new \Cases();
|
|
||||||
$appDelegation = new \AppDelegation();
|
|
||||||
$casesToReassign = $data['cases'];
|
$casesToReassign = $data['cases'];
|
||||||
$result = 0;
|
$oCases = new \Cases();
|
||||||
if (sizeof($casesToReassign)) {
|
|
||||||
foreach ($casesToReassign as $key => $val) {
|
foreach ($casesToReassign as $key => $val) {
|
||||||
|
$appDelegation = \AppDelegationPeer::retrieveByPK($val['APP_UID'], $val['DEL_INDEX']);
|
||||||
|
$existDelegation = $this->validateReassignData($appDelegation, $val, $data, 'DELEGATION_NOT_EXISTS');
|
||||||
|
if ($existDelegation) {
|
||||||
|
$existDelegation = $this->validateReassignData($appDelegation, $val, $data, 'USER_NOT_ASSIGNED_TO_TASK');
|
||||||
|
if ($existDelegation) {
|
||||||
$usrUid = '';
|
$usrUid = '';
|
||||||
if (array_key_exists('USR_UID', $val)) {
|
if (array_key_exists('USR_UID', $val)) {
|
||||||
if ($val['USR_UID'] != '') {
|
if ($val['USR_UID'] != '') {
|
||||||
$usrUid = $val['USR_UID'];
|
$usrUid = $val['USR_UID'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($usrUid == '') {
|
if ($usrUid == '') {
|
||||||
$fields = $appDelegation->load($val['APP_UID'], $val['DEL_INDEX']);
|
$fields = $appDelegation->toArray(\BasePeer::TYPE_FIELDNAME);
|
||||||
$usrUid = $fields['USR_UID'];
|
$usrUid = $fields['USR_UID'];
|
||||||
}
|
}
|
||||||
//Will be not able reassign a case when is paused
|
//Will be not able reassign a case when is paused
|
||||||
$flagReassign = true;
|
$flagPaused = $this->validateReassignData($appDelegation, $val, $data, 'ID_REASSIGNMENT_PAUSED_ERROR');
|
||||||
if (\AppDelay::isPaused($val['APP_UID'], $val['DEL_INDEX'])) {
|
//Current users of OPEN DEL_INDEX thread
|
||||||
$dataResponse['cases'][$key]['result'] = 0;
|
$flagSameUser = $this->validateReassignData($appDelegation, $val, $data, 'REASSIGNMENT_TO_THE_SAME_USER');
|
||||||
$dataResponse['cases'][$key]['status'] = \G::LoadTranslation('ID_REASSIGNMENT_PAUSED_ERROR');
|
//reassign case
|
||||||
$flagReassign = false;
|
if ($flagPaused && $flagSameUser) {
|
||||||
|
$reassigned = $oCases->reassignCase($val['APP_UID'], $val['DEL_INDEX'], $usrUid, $data['usr_uid_target']);
|
||||||
|
$result = $reassigned ? 1 : 0;
|
||||||
|
$this->messageResponse = [
|
||||||
|
'APP_UID' => $val['APP_UID'],
|
||||||
|
'DEL_INDEX' => $val['DEL_INDEX'],
|
||||||
|
'RESULT' => $result,
|
||||||
|
'STATUS' => 'SUCCESS'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$dataResponse['cases'][$key] = $this->messageResponse;
|
||||||
|
}
|
||||||
|
unset($dataResponse['usr_uid_target']);
|
||||||
|
return G::json_encode($dataResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Current users of OPEN DEL_INDEX thread
|
/**
|
||||||
$aCurUser = $appDelegation->getCurrentUsers($val['APP_UID'], $val['DEL_INDEX']);
|
* @param $appDelegation
|
||||||
|
* @param $value
|
||||||
|
* @param $data
|
||||||
|
* @param string $type
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function validateReassignData($appDelegation, $value, $data, $type = 'DELEGATION_NOT_EXISTS')
|
||||||
|
{
|
||||||
|
$return = true;
|
||||||
|
switch ($type) {
|
||||||
|
case 'DELEGATION_NOT_EXISTS':
|
||||||
|
if (is_null($appDelegation)) {
|
||||||
|
$this->messageResponse = [
|
||||||
|
'APP_UID' => $value['APP_UID'],
|
||||||
|
'DEL_INDEX' => $value['DEL_INDEX'],
|
||||||
|
'RESULT' => 0,
|
||||||
|
'STATUS' => $type
|
||||||
|
];
|
||||||
|
$return = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'USER_NOT_ASSIGNED_TO_TASK':
|
||||||
|
$task = new \ProcessMaker\BusinessModel\Task();
|
||||||
|
$supervisor = new \ProcessMaker\BusinessModel\ProcessSupervisor();
|
||||||
|
$taskUid = $appDelegation->getTasUid();
|
||||||
|
$flagBoolean = $task->checkUserOrGroupAssignedTask($taskUid, $data['usr_uid_target']);
|
||||||
|
$flagps = $supervisor->isUserProcessSupervisor($appDelegation->getProUid(), $data['usr_uid_target']);
|
||||||
|
|
||||||
|
if (!$flagBoolean && !$flagps) {
|
||||||
|
$this->messageResponse = [
|
||||||
|
'APP_UID' => $value['APP_UID'],
|
||||||
|
'DEL_INDEX' => $value['DEL_INDEX'],
|
||||||
|
'RESULT' => 0,
|
||||||
|
'STATUS' => 'USER_NOT_ASSIGNED_TO_TASK'
|
||||||
|
];
|
||||||
|
$return = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'ID_REASSIGNMENT_PAUSED_ERROR':
|
||||||
|
if (\AppDelay::isPaused($value['APP_UID'], $value['DEL_INDEX'])) {
|
||||||
|
$this->messageResponse = [
|
||||||
|
'APP_UID' => $value['APP_UID'],
|
||||||
|
'DEL_INDEX' => $value['DEL_INDEX'],
|
||||||
|
'RESULT' => 0,
|
||||||
|
'STATUS' => \G::LoadTranslation('ID_REASSIGNMENT_PAUSED_ERROR')
|
||||||
|
];
|
||||||
|
$return = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'REASSIGNMENT_TO_THE_SAME_USER':
|
||||||
|
$aCurUser = $appDelegation->getCurrentUsers($value['APP_UID'], $value['DEL_INDEX']);
|
||||||
if (!empty($aCurUser)) {
|
if (!empty($aCurUser)) {
|
||||||
foreach ($aCurUser as $keyAux => $value) {
|
foreach ($aCurUser as $keyAux => $val) {
|
||||||
if ($value === $data['usr_uid_target']) {
|
if ($val === $data['usr_uid_target']) {
|
||||||
$flagReassign = false;
|
$this->messageResponse = [
|
||||||
$result = 1;
|
'APP_UID' => $value['APP_UID'],
|
||||||
|
'DEL_INDEX' => $value['DEL_INDEX'],
|
||||||
|
'RESULT' => 1,
|
||||||
|
'STATUS' => 'SUCCESS'
|
||||||
|
];
|
||||||
|
$return = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//DEL_INDEX is CLOSED
|
//DEL_INDEX is CLOSED
|
||||||
$dataResponse['cases'][$key]['result'] = 0;
|
$this->messageResponse = [
|
||||||
$dataResponse['cases'][$key]['status'] = \G::LoadTranslation('ID_REASSIGNMENT_ERROR');
|
'APP_UID' => $value['APP_UID'],
|
||||||
$flagReassign = false;
|
'DEL_INDEX' => $value['DEL_INDEX'],
|
||||||
|
'RESULT' => 0,
|
||||||
|
'STATUS' => \G::LoadTranslation('ID_REASSIGNMENT_ERROR')
|
||||||
|
];
|
||||||
|
$return = false;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
if ($flagReassign) {
|
|
||||||
$reassigned = $oCases->reassignCase($val['APP_UID'], $val['DEL_INDEX'], $usrUid, $data['usr_uid_target']);
|
|
||||||
$result = $reassigned ? 1 : 0;
|
|
||||||
$dataResponse['cases'][$key]['status'] = 'SUCCESS';
|
|
||||||
}
|
}
|
||||||
$dataResponse['cases'][$key]['result'] = $result;
|
return $return;
|
||||||
}
|
|
||||||
}
|
|
||||||
unset($dataResponse['usr_uid_target']);
|
|
||||||
|
|
||||||
return G::json_encode($dataResponse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ class Cases extends Api
|
|||||||
|
|
||||||
//Check if the user is supervisor process
|
//Check if the user is supervisor process
|
||||||
$case = new \ProcessMaker\BusinessModel\Cases();
|
$case = new \ProcessMaker\BusinessModel\Cases();
|
||||||
$supervisor = new \ProcessMaker\BusinessModel\ProcessSupervisor();
|
|
||||||
$user = new \ProcessMaker\BusinessModel\User();
|
$user = new \ProcessMaker\BusinessModel\User();
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
@@ -70,10 +69,10 @@ class Cases extends Api
|
|||||||
|
|
||||||
if (!empty($arrayApplicationData)) {
|
if (!empty($arrayApplicationData)) {
|
||||||
if (!$user->checkPermission($usrUid, 'PM_REASSIGNCASE')) {
|
if (!$user->checkPermission($usrUid, 'PM_REASSIGNCASE')) {
|
||||||
if($user->checkPermission($usrUid, 'PM_REASSIGNCASE_SUPERVISOR')){
|
if ($user->checkPermission($usrUid, 'PM_REASSIGNCASE_SUPERVISOR')) {
|
||||||
$supervisor = new \ProcessMaker\BusinessModel\ProcessSupervisor();
|
$supervisor = new \ProcessMaker\BusinessModel\ProcessSupervisor();
|
||||||
$flagps = $supervisor->isUserProcessSupervisor($arrayApplicationData['PRO_UID'], $usrUid);
|
$flagps = $supervisor->isUserProcessSupervisor($arrayApplicationData['PRO_UID'], $usrUid);
|
||||||
if(!$flagps){
|
if (!$flagps) {
|
||||||
$count = $count + 1;
|
$count = $count + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user