PMCORE-593 Action by email: when the authentication is incorrect we can see an error in the routing page.

This commit is contained in:
Roly Rudy Gutierrez Pinto
2020-06-09 12:50:12 -04:00
parent 19c4a93f33
commit 683c69ba81
8 changed files with 925 additions and 200 deletions

View File

@@ -437,18 +437,6 @@ class ActionsByEmailCoreClass extends PMPlugin
return $emailSetup;
}
/**
* Define the properties in the task related the action by email configuration
*
* @return void
*/
private function defineTaskAbeProperties()
{
$actionEmailTable = new AbeConfiguration();
$properties = $actionEmailTable->getTaskConfiguration($this->getCasePropertiesKey('PRO_UID'), $this->getTask());
$this->setTaskAbeProperties($properties);
}
/**
* Define the email from
*
@@ -623,79 +611,94 @@ class ActionsByEmailCoreClass extends PMPlugin
self::validateAndSetValues($data);
$emailServerSetup = $this->getEmailServer($dataAbe['ABE_EMAIL_SERVER_UID']);
if (!empty($emailServerSetup)) {
$cases = new Cases();
$caseFields = $cases->loadCase($this->getAppUid(), $this->getIndex());
$this->setCaseProperties($caseFields);
$this->defineTaskAbeProperties();
$caseFields['APP_DATA']['PRO_ID'] = $this->getItemAbeProperties('PRO_ID');
$caseFields['APP_DATA']['TAS_ID'] = $this->getItemAbeProperties('TAS_ID');
if (!empty($this->getTaskAbeProperties())) {
$this->defineEmailTo($this->getItemAbeProperties('ABE_EMAIL_FIELD'), $caseFields['APP_DATA']);
if (!empty($this->getEmailTo())) {
$this->defineSubject($this->getItemAbeProperties('ABE_SUBJECT_FIELD'), $caseFields['APP_DATA']);
$request = [
'ABE_REQ_UID' => '',
'ABE_UID' => $this->getItemAbeProperties('ABE_UID'),
'APP_UID' => $this->getAppUid(),
'DEL_INDEX' => $this->getIndex(),
'ABE_REQ_SENT_TO' => $this->getEmailTo(),
'ABE_REQ_SUBJECT' => $this->getSubject(),
'ABE_REQ_BODY' => '',
'ABE_REQ_ANSWERED' => 0,
'ABE_REQ_STATUS' => 'PENDING'
];
$this->setAbeRequest($request);
$this->registerRequest();
if (!empty($this->getItemAbeProperties('ABE_TYPE'))) {
// Email
$_SESSION['CURRENT_DYN_UID'] = $this->getItemAbeProperties('DYN_UID');
$__ABE__ = '';
switch ($this->getItemAbeProperties('ABE_TYPE')) {
case 'CUSTOM':
$__ABE__ .= $this->getCustomTemplate();
break;
case 'RESPONSE':
$this->defineReplyTo($dataAbe['ABE_EMAIL_SERVER_RECEIVER_UID']);
$__ABE__ .= $this->getResponseTemplate();
break;
case 'LINK':
$__ABE__ .= $this->getServicePathTemplate();
break;
case 'FIELD':
$__ABE__ .= $this->getFieldTemplate();
break;
}
$__ABE__ = preg_replace('/\<img src=\"\/js\/maborak\/core\/images\/(.+?)\>/', '', $__ABE__);
$__ABE__ = preg_replace('/\<input\b[^>]*\/>/', '', $__ABE__);
$__ABE__ = preg_replace('/<select\b[^>]*>(.*?)<\/select>/is', "", $__ABE__);
$__ABE__ = preg_replace('/align=\"center\"/', '', $__ABE__);
$__ABE__ = preg_replace('/class="tableGrid_view" /', 'class="tableGrid_view" width="100%" ',
$__ABE__);
$caseFields['APP_DATA']['__ABE__'] = $__ABE__;
$this->defineEmailFrom($emailServerSetup);
$result = $this->abeSendMessage(
$this->getItemAbeProperties('ABE_TEMPLATE'),
$caseFields['APP_DATA'],
$emailServerSetup
);
$request = [];
$request['ABE_REQ_STATUS'] = ($result->status_code == 0 ? 'SENT' : 'ERROR');
$request['ABE_REQ_BODY'] = empty($result->getAppMessUid()) ? '' : AppMessage::getAppMsgBodyByKey($result->getAppMessUid());
$this->addItemAbeRequest($request);
$this->registerRequest();
}
}
} else {
throw new Exception('Task does not have an action by email configuration.');
}
if (empty($emailServerSetup)) {
return;
}
$cases = new Cases();
$caseFields = $cases->loadCase($this->getAppUid(), $this->getIndex());
$this->setCaseProperties($caseFields);
$actionEmailTable = new AbeConfiguration();
$properties = $actionEmailTable->getTaskConfiguration($this->getCasePropertiesKey('PRO_UID'), $this->getTask());
if (empty($properties)) {
throw new Exception('Task does not have an action by email configuration.');
}
$this->setTaskAbeProperties($properties);
$caseFields['APP_DATA']['PRO_ID'] = $this->getItemAbeProperties('PRO_ID');
$caseFields['APP_DATA']['TAS_ID'] = $this->getItemAbeProperties('TAS_ID');
$this->defineEmailTo($this->getItemAbeProperties('ABE_EMAIL_FIELD'), $caseFields['APP_DATA']);
if (empty($this->getEmailTo())) {
return;
}
$this->defineSubject($this->getItemAbeProperties('ABE_SUBJECT_FIELD'), $caseFields['APP_DATA']);
$request = [
'ABE_REQ_UID' => '',
'ABE_UID' => $this->getItemAbeProperties('ABE_UID'),
'APP_UID' => $this->getAppUid(),
'DEL_INDEX' => $this->getIndex(),
'ABE_REQ_SENT_TO' => $this->getEmailTo(),
'ABE_REQ_SUBJECT' => $this->getSubject(),
'ABE_REQ_BODY' => '',
'ABE_REQ_ANSWERED' => 0,
'ABE_REQ_STATUS' => 'PENDING'
];
$this->setAbeRequest($request);
$this->registerRequest();
if (empty($this->getItemAbeProperties('ABE_TYPE'))) {
return;
}
// Email
$_SESSION['CURRENT_DYN_UID'] = $this->getItemAbeProperties('DYN_UID');
$__ABE__ = '';
switch ($this->getItemAbeProperties('ABE_TYPE')) {
case 'CUSTOM':
$__ABE__ .= $this->getCustomTemplate();
break;
case 'RESPONSE':
$this->defineReplyTo($dataAbe['ABE_EMAIL_SERVER_RECEIVER_UID']);
$__ABE__ .= $this->getResponseTemplate();
break;
case 'LINK':
$__ABE__ .= $this->getServicePathTemplate();
break;
case 'FIELD':
$__ABE__ .= $this->getFieldTemplate();
break;
}
$__ABE__ = preg_replace('/\<img src=\"\/js\/maborak\/core\/images\/(.+?)\>/', '', $__ABE__);
$__ABE__ = preg_replace('/\<input\b[^>]*\/>/', '', $__ABE__);
$__ABE__ = preg_replace('/<select\b[^>]*>(.*?)<\/select>/is', "", $__ABE__);
$__ABE__ = preg_replace('/align=\"center\"/', '', $__ABE__);
$__ABE__ = preg_replace('/class="tableGrid_view" /', 'class="tableGrid_view" width="100%" ', $__ABE__);
$caseFields['APP_DATA']['__ABE__'] = $__ABE__;
$this->defineEmailFrom($emailServerSetup);
$params = [
$this->getItemAbeProperties('ABE_TEMPLATE'),
$caseFields['APP_DATA'],
$emailServerSetup
];
$result = $this->abeSendMessage(...$params);
$request = [
'ABE_REQ_STATUS' => $result->status_code == 0 ? 'SENT' : 'ERROR',
'ABE_REQ_BODY' => '',
];
if (!empty($result->getExtraParam('AppMessUid'))) {
$request['ABE_REQ_BODY'] = AppMessage::getAppMsgBodyByKey($result->getExtraParam('AppMessUid'));
}
$this->addItemAbeRequest($request);
$this->registerRequest();
} catch (Exception $error) {
throw $error;
}

View File

@@ -8,7 +8,6 @@ use ProcessMaker\ChangeLog\ChangeLog;
use ProcessMaker\Core\JobsManager;
use ProcessMaker\Core\System;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Util\WsMessageResponse;
class WsBase
{
@@ -910,6 +909,7 @@ class WsBase
)
{
try {
$setup = [];
/*----------------------------------********---------------------------------*/
if (!empty($config)) {
@@ -972,9 +972,7 @@ class WsBase
if (!file_exists($fileTemplate)) {
$data['FILE_TEMPLATE'] = $fileTemplate;
$result = new WsResponse(28, G::LoadTranslation('ID_TEMPLATE_FILE_NOT_EXIST', SYS_LANG, $data));
return $result;
return new WsResponse(28, G::LoadTranslation('ID_TEMPLATE_FILE_NOT_EXIST', SYS_LANG, $data));
}
if ($appFields == null) {
@@ -1002,45 +1000,46 @@ class WsBase
(preg_match("/^.+\.html?$/i", $fileTemplate)) ? true : false,
isset($fieldsCase['APP_NUMBER']) ? $fieldsCase['APP_NUMBER'] : 0,
isset($fieldsCase['PRO_ID']) ? $fieldsCase['PRO_ID'] : 0,
$this->getTaskId() ?$this->getTaskId():(isset($oldFields['TAS_ID'])? $oldFields['TAS_ID'] : 0)
$this->getTaskId() ? $this->getTaskId() : (isset($oldFields['TAS_ID']) ? $oldFields['TAS_ID'] : 0)
);
$result = "";
if ($gmail != 1) {
// Create always the record in APP_MESSAGE table
if ($gmail === 1) {
return new WsResponse(0, G::loadTranslation('ID_PMGMAIL'));
}
// Create always the record in APP_MESSAGE table
$spool = new SpoolRun();
$spool->setConfig($setup);
$spool->create($messageArray);
// Get the data of the record created
$fileData = $spool->getFileData();
$fileData['spoolId'] = $spool->getSpoolId();
// Create the closure and send the required data
$closure = function() use ($setup, $fileData, $gmail, $to) {
$spool = new SpoolRun();
$spool->setConfig($setup);
$spool->create($messageArray);
// Get the data of the record created
$fileData = $spool->getFileData();
$fileData['spoolId'] = $spool->getSpoolId();
// Create the closure and send the required data
$closure = function() use ($setup, $fileData, $gmail, $to) {
$spool = new SpoolRun();
$spool->setConfig($setup);
$spool->setSpoolId($fileData['spoolId']);
$spool->setFileData($fileData);
$spool->sendMail();
return $spool;
};
$result = new WsMessageResponse(0, G::loadTranslation('ID_MESSAGE_SENT') . ": " . $to);
switch ($appMsgType) {
case WsBase::MESSAGE_TYPE_EMAIL_EVENT:
case WsBase::MESSAGE_TYPE_PM_FUNCTION:
JobsManager::getSingleton()->dispatch('EmailEvent', $closure);
break;
default :
$spool = $closure();
if ($spool->status == 'sent') {
$result = new WsMessageResponse(0, G::loadTranslation('ID_MESSAGE_SENT') . ": " . $to);
$result->setAppMessUid($spool->getSpoolId());
} else {
$result = new WsResponse(29, $spool->status . ' ' . $spool->error . PHP_EOL . print_r($setup, 1));
}
break;
}
$spool->setSpoolId($fileData['spoolId']);
$spool->setFileData($fileData);
$spool->sendMail();
return $spool;
};
switch ($appMsgType) {
case WsBase::MESSAGE_TYPE_EMAIL_EVENT:
case WsBase::MESSAGE_TYPE_PM_FUNCTION:
JobsManager::getSingleton()->dispatch('EmailEvent', $closure);
$result = new WsResponse(0, G::loadTranslation('ID_MESSAGE_SENT') . ": " . $to);
break;
default :
$spool = $closure();
if ($spool->status == 'sent') {
$result = new WsResponse(0, G::loadTranslation('ID_MESSAGE_SENT') . ": " . $to);
$result->addExtraParam('AppMessUid', $spool->getSpoolId());
} else {
$result = new WsResponse(29, $spool->status . ' ' . $spool->error . PHP_EOL . print_r($setup, 1));
}
break;
}
return $result;
} catch (Exception $e) {

View File

@@ -43,10 +43,11 @@ class WsResponse
* 36 ID_CASE_COULD_NOT_REASSIGNED
*
* 100 Exception
*/
*/
public $status_code = 0;
public $message = '';
public $timestamp = '';
private $extraParams = [];
/**
* Function __construct
@@ -56,11 +57,31 @@ class WsResponse
* @param string $message
* @return void
*/
function __construct ($status, $message)
public function __construct($status, $message)
{
$this->status_code = $status;
$this->message = $message;
$this->timestamp = date( 'Y-m-d H:i:s' );
$this->timestamp = date('Y-m-d H:i:s');
}
/**
* Get extra parameters for message response.
* @return mixed
*/
public function getExtraParam(string $name)
{
return isset($this->extraParams[$name]) ? $this->extraParams[$name] : '';
}
/**
* Add extra parameters for message response.
* @param string $name
* @param mixed $value
* @return void
*/
public function addExtraParam(string $name, $value): void
{
$this->extraParams[$name] = $value;
}
/**
@@ -69,13 +90,12 @@ class WsResponse
* @param string $operation
* @return string
*/
function getPayloadString ($operation)
public function getPayloadString($operation)
{
$res = "<$operation>\n";
$res .= "<status_code>" . $this->status_code . "</status_code>";
$res .= "<message>" . $this->message . "</message>";
$res .= "<timestamp>" . $this->timestamp . "</timestamp>";
// $res .= "<array>" . $this->timestamp . "</array>";
$res .= "<$operation>";
return $res;
}
@@ -85,9 +105,8 @@ class WsResponse
*
* @return array
*/
function getPayloadArray ()
public function getPayloadArray()
{
return array ("status_code" => $this->status_code,'message' => $this->message,'timestamp' => $this->timestamp
);
return ["status_code" => $this->status_code, 'message' => $this->message, 'timestamp' => $this->timestamp];
}
}

View File

@@ -1,32 +0,0 @@
<?php
namespace ProcessMaker\Util;
use WsResponse;
class WsMessageResponse extends WsResponse
{
private $appMessUid = null;
/**
* Get the appMessUid
*
* @return array
*/
public function getAppMessUid()
{
return $this->appMessUid;
}
/**
* Set the appMessUid
*
* @param string $v
* @return void
*/
public function setAppMessUid($v)
{
$this->appMessUid = $v;
}
}