Commit a0235fd4 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FIX #18428 TIME 0:25 split communication means url login and password

parent 21c86e55
......@@ -10,7 +10,9 @@
<attachment_type>simple_attachment</attachment_type>
</res_attachments>
<basketRedirection_afterUpload>NumericBasket</basketRedirection_afterUpload><!--basketId-->
<m2m_communication>https://cchaplin:maarch@demo.maarchcourrier.com</m2m_communication><!--moyen de communication de l'instance : email ou uri -->
<m2m_communication>https://demo.maarchcourrier.com</m2m_communication><!--moyen de communication de l'instance : email ou uri -->
<m2m_login>cchaplin</m2m_login>
<m2m_password>maarch</m2m_password>
<annuaries>
<enabled>false</enabled>
<organization>organization</organization>
......
......@@ -34,6 +34,7 @@ use Slim\Http\Response;
use SrcCore\controllers\AutoCompleteController;
use SrcCore\models\CoreConfigModel;
use SrcCore\models\DatabaseModel;
use SrcCore\models\PasswordModel;
use SrcCore\models\TextFormatModel;
use SrcCore\models\ValidatorModel;
use User\models\UserModel;
......@@ -149,13 +150,19 @@ class ContactController
}
if (!empty($body['communicationMeans'])) {
if (filter_var($body['communicationMeans'], FILTER_VALIDATE_EMAIL)) {
$body['communicationMeans'] = ['email' => $body['communicationMeans']];
} elseif (filter_var($body['communicationMeans'], FILTER_VALIDATE_URL)) {
$body['communicationMeans'] = ['url' => $body['communicationMeans']];
if (filter_var($body['communicationMeans']['email'], FILTER_VALIDATE_EMAIL)) {
$contactBody['email'] = $body['communicationMeans']['email'];
} elseif (filter_var($body['communicationMeans']['url'], FILTER_VALIDATE_URL)) {
$contactBody['url'] = $body['communicationMeans']['url'];
} else {
return $response->withStatus(400)->withJson(['errors' => _COMMUNICATION_MEANS_VALIDATOR]);
}
if (!empty($body['communicationMeans']['login'])) {
$contactBody['login'] = $body['communicationMeans']['login'];
}
if (!empty($body['communicationMeans']['password'])) {
$contactBody['password'] = PasswordModel::encrypt(['password' => $body['communicationMeans']['password']]);
}
}
$annuaryReturn = ContactController::addContactToM2MAnnuary(['body' => $body]);
......@@ -183,7 +190,7 @@ class ContactController
'address_country' => $body['addressCountry'] ?? null,
'email' => $body['email'] ?? null,
'phone' => $body['phone'] ?? null,
'communication_means' => !empty($body['communicationMeans']) ? json_encode($body['communicationMeans']) : null,
'communication_means' => !empty($contactBody) ? json_encode($contactBody) : null,
'notes' => $body['notes'] ?? null,
'creator' => $GLOBALS['id'],
'enabled' => 'true',
......@@ -262,7 +269,12 @@ class ContactController
}
if (!empty($rawContact['communication_means'])) {
$communicationMeans = json_decode($rawContact['communication_means'], true);
$contact['communicationMeans'] = $communicationMeans['url'] ?? $communicationMeans['email'];
if(!empty($communicationMeans['url'])) {
$contact['communicationMeans']['url'] = $communicationMeans['url'];
} elseif (!empty($communicationMeans['email'])) {
$contact['communicationMeans']['email'] = $communicationMeans['email'];
}
$contact['communicationMeans']['login'] = $communicationMeans['login'];
}
$filling = ContactController::getFillingRate(['contactId' => $rawContact['id']]);
......@@ -312,18 +324,29 @@ class ContactController
return $response->withStatus(400)->withJson(['errors' => $control['errors']]);
}
$contact = ContactModel::getById(['id' => $args['id'], 'select' => [1]]);
$contact = ContactModel::getById(['id' => $args['id'], 'select' => ['communication_means']]);
if (empty($contact)) {
return $response->withStatus(400)->withJson(['errors' => 'Contact does not exist']);
}
$contact['communication_means'] = json_decode($contact['communication_means'], true);
$contactBody = [];
if (!empty($contact['communication_means']['password'])) {
$contactBody['password'] = $contact['communication_means']['password'];
}
if (!empty($body['communicationMeans'])) {
if (filter_var($body['communicationMeans'], FILTER_VALIDATE_EMAIL)) {
$body['communicationMeans'] = ['email' => $body['communicationMeans']];
} elseif (filter_var($body['communicationMeans'], FILTER_VALIDATE_URL)) {
$body['communicationMeans'] = ['url' => $body['communicationMeans']];
if (filter_var($body['communicationMeans']['email'], FILTER_VALIDATE_EMAIL)) {
$contactBody['email'] = $body['communicationMeans']['email'];
} elseif (filter_var($body['communicationMeans']['url'], FILTER_VALIDATE_URL)) {
$contactBody['url'] = $body['communicationMeans']['url'];
} else {
unset($body['communicationMeans']);
unset($contactBody);
}
if (!empty($body['communicationMeans']['login'])) {
$contactBody['login'] = $body['communicationMeans']['login'];
}
if (!empty($body['communicationMeans']['password'])) {
$contactBody['password'] = PasswordModel::encrypt(['password' => $body['communicationMeans']['password']]);
}
}
......@@ -353,7 +376,7 @@ class ContactController
'address_country' => $body['addressCountry'] ?? null,
'email' => $body['email'] ?? null,
'phone' => $body['phone'] ?? null,
'communication_means' => !empty($body['communicationMeans']) ? json_encode($body['communicationMeans']) : null,
'communication_means' => !empty($contactBody) ? json_encode($contactBody) : null,
'notes' => $body['notes'] ?? null,
'modification_date' => 'CURRENT_TIMESTAMP',
'custom_fields' => !empty($body['customFields']) ? json_encode($body['customFields']) : null,
......@@ -1432,7 +1455,8 @@ class ContactController
if (!empty($contactRaw['communication_means'])) {
$communicationMeans = json_decode($contactRaw['communication_means'], true);
$contact['communicationMeans'] = $communicationMeans['url'] ?? $communicationMeans['email'];
unset($communicationMeans['password']);
$contact['communicationMeans'] = !empty($communicationMeans) ? $communicationMeans : null;
}
$filling = ContactController::getFillingRate(['contactId' => $resourceContact['item_id']]);
......
......@@ -189,6 +189,10 @@ class ReceiveMessageExchangeController
}
$loadedXml = CoreConfigModel::getXmlLoaded(['path' => 'apps/maarch_entreprise/xml/m2m_config.xml']);
if (empty($loadedXml)) {
return null;
}
$aDefaultConfig = [];
if (!empty($loadedXml)) {
foreach ($loadedXml as $key => $value) {
......
......@@ -27,6 +27,7 @@ use Note\models\NoteModel;
use Resource\controllers\ResController;
use Resource\models\ResModel;
use Respect\Validation\Validator;
use SrcCore\models\PasswordModel;
use SrcCore\models\TextFormatModel;
use Status\models\StatusModel;
use User\models\UserModel;
......@@ -233,6 +234,21 @@ class SendMessageExchangeController
} else {
$ArchivalAgencyCommunicationType['type'] = 'url';
$ArchivalAgencyCommunicationType['value'] = rtrim($aArchivalAgencyCommunicationType['url'], "/");
if (strrpos($ArchivalAgencyCommunicationType['value'], "http://") !== false) {
$prefix = "http://";
} elseif (strrpos($ArchivalAgencyCommunicationType['value'], "https://") !== false) {
$prefix = "https://";
} else {
return $response->withStatus(403)->withJson(['errors' => 'http or https missing']);
}
$url = str_replace($prefix, '', $ArchivalAgencyCommunicationType['value']);
$login = $aArchivalAgencyCommunicationType['login'] ?? '';
$password = !empty($aArchivalAgencyCommunicationType['password']) ? PasswordModel::decrypt(['cryptedPassword' => $aArchivalAgencyCommunicationType['password']]) : '';
$ArchivalAgencyCommunicationType['value'] = $prefix;
if (!empty($login) && !empty($password)) {
$ArchivalAgencyCommunicationType['value'] .= $login . ':' . $password . '@';
}
$ArchivalAgencyCommunicationType['value'] .= $url;
}
}
$ArchivalAgencyContactInformations = ContactModel::getById(['select' => ['*'], 'id' => $contactId]);
......@@ -580,6 +596,22 @@ class SendMessageExchangeController
$aDefaultConfig = ReceiveMessageExchangeController::readXmlConfig();
// If communication_type is an url, and there is a separate field for login and password, we recreate the url with the login and password
if (filter_var($aDefaultConfig['m2m_communication_type'][$aArgs['ChannelType']], FILTER_VALIDATE_URL)) {
if (!empty($aDefaultConfig['m2m_login']) && !empty($aDefaultConfig['m2m_password'])) {
$prefix = '';
if (strrpos($aDefaultConfig['m2m_communication_type'][$aArgs['ChannelType']], "http://") !== false) {
$prefix = "http://";
} elseif (strrpos($aDefaultConfig['m2m_communication_type'][$aArgs['ChannelType']], "https://") !== false) {
$prefix = "https://";
}
$url = str_replace($prefix, '', $aDefaultConfig['m2m_communication_type'][$aArgs['ChannelType']]);
$login = $aDefaultConfig['m2m_login'][0] ?? '';
$password = $aDefaultConfig['m2m_password'][0] ?? '';
$aDefaultConfig['m2m_communication_type'][$aArgs['ChannelType']] = $prefix . $login . ':' . $password . '@' . $url;
}
}
$traCommunicationObject->Channel = $aArgs['ChannelType'];
$traCommunicationObject->value = rtrim($aDefaultConfig['m2m_communication_type'][$aArgs['ChannelType']], "/");
......
......@@ -835,8 +835,9 @@ class AutoCompleteController
$externalId = json_decode($contact['external_id'], true);
$communicationMeans = json_decode($contact['communication_means'], true);
unset($communicationMeans['password']);
$autoContact['m2m'] = $externalId['m2m'];
$autoContact['communicationMeans'] = $communicationMeans['url'] ?? $communicationMeans['email'];
$autoContact['communicationMeans'] = $communicationMeans ?? null;
$autocompleteData[] = $autoContact;
}
......@@ -902,8 +903,8 @@ class AutoCompleteController
}
}
return $response->withJson($unitOrganizations);
}
return $response->withJson($unitOrganizations);
}
public static function getFolders(Request $request, Response $response)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment