Commit 969aa225 authored by Maxime REYROLLE's avatar Maxime REYROLLE
Browse files

compute number of mails sent, read and answered

parent ab39e095
......@@ -22,6 +22,7 @@
- Commande `app:connector:replace-ged-ssh-with-depot-sftp`: Permet de remplacer les connecteurs `ged-ssh` par des connecteurs `depot-sftp`
- Ajout d'un connecteur global generateur SEDA afin de ne positionner l'URL de l'outil qu'une seule fois #1320
- Ajout du `ServiceLevel` (Niveau de service demandé) dans les bordereaux de transfert du générateur SEDA #1344
- Colonne qui récapitule le nombre de mails sécurisés envoyés, lus et répondus sur la liste des flux "Mail sécurisés" et "Mail sécurisés avec réponse" #1345
# [3.1.5] - 2021-08-04
......
<?php
class MailsecComputeAnsweredMail extends ConnecteurTypeActionExecutor
{
private const ANSWERED_MAIL_NUMBER_FIELD = 'sent_mail_answered';
/**
* @throws NotFoundException
*/
public function go()
{
$documentEmailReponseSql = $this->objectInstancier->getInstance(DocumentEmailReponseSQL::class);
$this->getDonneesFormulaire()->setData(
$this->getMappingValue(self::ANSWERED_MAIL_NUMBER_FIELD),
$documentEmailReponseSql->getNumberOfAnsweredMail($this->id_d)
);
return true;
}
}
<?php
class MailsecComputeReadMail extends ConnecteurTypeActionExecutor
{
private const READ_MAIL_NUMBER_FIELD = 'sent_mail_read';
/**
* @throws NotFoundException
*/
public function go()
{
$documentEmail = $this->objectInstancier->getInstance(DocumentEmail::class);
$this->getDonneesFormulaire()->setData(
$this->getMappingValue(self::READ_MAIL_NUMBER_FIELD),
$documentEmail->getNumberOfMailRead($this->id_d)
);
return true;
}
}
......@@ -2,6 +2,8 @@
class MailsecEnvoyer extends ConnecteurTypeActionExecutor
{
private const SENT_MAIL_NUMBER_FIELD = 'sent_mail_number';
private function getDocumentEmail(): DocumentEmail
{
return $this->objectInstancier->getInstance(DocumentEmail::class);
......@@ -37,24 +39,28 @@ class MailsecEnvoyer extends ConnecteurTypeActionExecutor
* @return bool
* @throws NotFoundException
* @throws UnrecoverableException
* @throws Exception
*/
public function go()
{
$numberOfRecipients = 0;
foreach (['to', 'cc', 'bcc'] as $type) {
$type = $this->getMappingValue($type);
$mail_to_send = $this->getMailToSend($type);
if ($type == 'to' && ! $mail_to_send) {
if ($type == 'to' && !$mail_to_send) {
throw new UnrecoverableException(
"Impossible d'envoyer le document car il n'y a pas de destinataires (groupe ou role vide)"
);
}
foreach ($mail_to_send as $mail) {
$this->add2SendEmail($mail, $type);
++$numberOfRecipients;
}
}
$this->getDonneesFormulaire()->setData($this->getMappingValue(self::SENT_MAIL_NUMBER_FIELD), $numberOfRecipients);
$this->getMailSecConnecteur()->sendAllMail($this->id_e, $this->id_d);
$this->getActionCreator()->addAction(
......
......@@ -78,6 +78,12 @@ class MailSecDestinataireControler extends PastellControler
$this->validatePassword($mailSecInfo->donneesFormulaire, $mailSecInfo->key);
$this->getDocumentEmail()->consulter($mailSecInfo->key, $this->getJournal());
$this->getActionExecutorFactory()->executeOnDocument(
$mailSecInfo->id_e,
0,
$mailSecInfo->id_d,
'compute_read_mail'
);
$mailSecInfo->donneesFormulaire->getFormulaire()->setTabNumber(0);
$mailSecInfo->fieldDataList = $mailSecInfo->donneesFormulaire->getFieldDataList('', 0);
......@@ -278,6 +284,13 @@ class MailSecDestinataireControler extends PastellControler
}
}
$this->getActionExecutorFactory()->executeOnDocument(
$mailSecInfo->id_e,
0,
$mailSecInfo->id_d,
'compute_answered_mail'
);
$this->getObjectInstancier()->getInstance(ActionCreatorSQL::class)->addAction(
$mailSecInfo->id_e,
0,
......
......@@ -166,4 +166,16 @@ class DocumentEmail extends SQL
$sql = "UPDATE document_email SET reponse=? WHERE id_de=?";
$this->query($sql, $reponse, $id_de);
}
public function getNumberOfMailRead(string $id_d): int
{
$sql = <<<EOT
SELECT count(*)
FROM document_email
WHERE id_d = ?
AND lu = 1;
EOT;
return $this->queryOne($sql, $id_d);
}
}
......@@ -60,4 +60,16 @@ class DocumentEmailReponseSQL extends SQL
$sql = "UPDATE document_email_reponse SET is_lu=true WHERE id_d_reponse=?";
$this->query($sql, $id_d_reponse);
}
public function getNumberOfAnsweredMail(string $id_d): int
{
$sql = <<<EOT
SELECT count(*)
FROM document_email_reponse
INNER JOIN document_email ON document_email_reponse.id_de = document_email.id_de
WHERE id_d= ?;
EOT;
return $this->queryOne($sql, $id_d);
}
}
......@@ -48,6 +48,32 @@ formulaire:
key:
no-show: true
sent_mail_number:
name: Mails envoyés
default: '0'
index: true
no-show: true
sent_mail_read:
name: Mails lus
default: '0'
index: true
no-show: true
sent_mail_answered:
name: Mails répondus
default: '0'
index: true
no-show: true
champs-affiches:
- titre
- dernier_etat
- date_dernier_etat
- sent_mail_number
- sent_mail_read
- sent_mail_answered
action:
creation:
name-action: Créer
......@@ -129,3 +155,19 @@ action:
renvoi
reception-partielle
action-class: Defaut
compute_read_mail:
name: Calcul des mails lus
rule:
role_id_e: no-role
action-class: StandardAction
connecteur-type: mailsec
connecteur-type-action: MailsecComputeReadMail
compute_answered_mail:
name: Calcul des mails répondus
rule:
role_id_e: no-role
action-class: StandardAction
connecteur-type: mailsec
connecteur-type-action: MailsecComputeAnsweredMail
......@@ -53,6 +53,25 @@ formulaire:
key:
no-show: true
sent_mail_number:
name: Mails envoyés
default: '0'
index: true
no-show: true
sent_mail_read:
name: Mails lus
default: '0'
index: true
no-show: true
champs-affiches:
- titre
- dernier_etat
- date_dernier_etat
- sent_mail_number
- sent_mail_read
action:
creation:
name-action: Créer
......@@ -137,3 +156,10 @@ action:
reception-partielle
action-class: Defaut
compute_read_mail:
name: Calcul des mails lus
rule:
role_id_e: no-role
action-class: StandardAction
connecteur-type: mailsec
connecteur-type-action: MailsecComputeReadMail
......@@ -118,6 +118,16 @@ class MailSecDestinataireControlerTest extends ControlerTestCase
$documentEmailReponseSQL = $this->getObjectInstancier()->getInstance(DocumentEmailReponseSQL::class);
$this->assertEquals('', $documentEmailReponseSQL->getAllReponse($id_d)[$id_de]['titre']);
$document = $this->getDonneesFormulaireFactory()->get($id_d);
$this->assertSame(
'1',
$document->get('sent_mail_read')
);
$this->assertSame(
'1',
$document->get('sent_mail_answered')
);
}
/**
......
......@@ -92,7 +92,7 @@ class DocumentEmailReponseSQLTest extends PastellTestCase
$id_d_reponse = "REPONSE";
$documentEmail = $this->getObjectInstancier()->getInstance(DocumentEmail::class);
$document = $this->getObjectInstancier()->getInstance(Document::class);
$document = $this->getObjectInstancier()->getInstance(DocumentSQL::class);
$document->save($id_d_mailsec, "mailsec");
......@@ -116,5 +116,19 @@ class DocumentEmailReponseSQLTest extends PastellTestCase
),
$this->getDocumentEmailReponseSQL()->getAllReponse($id_d_mailsec)
);
$this->assertSame(
1,
$this->getDocumentEmailReponseSQL()->getNumberOfAnsweredMail($id_d_mailsec)
);
$key = $documentEmail->add($id_d_mailsec, "foo2@bar", "to");
$info = $documentEmail->getInfoFromKey($key);
$this->getDocumentEmailReponseSQL()->addDocumentReponseId($info['id_de'], $id_d_reponse);
$this->getDocumentEmailReponseSQL()->validateReponse($info['id_de']);
$this->assertSame(
2,
$this->getDocumentEmailReponseSQL()->getNumberOfAnsweredMail($id_d_mailsec)
);
}
}
<?php
class DocumentEmailTest extends PastellTestCase
{
/**
* @var DocumentEmail
*/
private $documentEmail;
protected function setUp()
{
$this->documentEmail = $this->getObjectInstancier()->getInstance(DocumentEmail::class);
parent::setUp();
}
public function testGetNumberOfMailRead(): void
{
$documentId = 'id_d';
$key1 = $this->documentEmail->add($documentId, '1@example.org', 'to');
$key2 = $this->documentEmail->add($documentId, '2@example.org', 'to');
$this->assertSame(0, $this->documentEmail->getNumberOfMailRead($documentId));
$this->documentEmail->consulter($key1, $this->getJournal());
$this->assertSame(1, $this->documentEmail->getNumberOfMailRead($documentId));
$this->documentEmail->consulter($key2, $this->getJournal());
$this->assertSame(2, $this->documentEmail->getNumberOfMailRead($documentId));
}
}
......@@ -9,12 +9,14 @@ class DocumentTypeValidationTest extends PHPUnit\Framework\TestCase
protected function setUp()
{
$this->documentTypeValidation = new DocumentTypeValidation(new YMLLoader(new MemoryCacheNone()));
$this->documentTypeValidation = new DocumentTypeValidation(new YMLLoader(new MemoryCacheNone()));
$this->documentTypeValidation->setListPack(["pack_chorus_pro" => false, "pack_marche" => false]);
$this->documentTypeValidation->setConnecteurTypeList(array('mailsec'));
$this->documentTypeValidation->setActionClassList(array('Supprimer','StandardAction','Defaut'));
$this->documentTypeValidation->setActionClassList(array('Supprimer', 'StandardAction', 'Defaut'));
$this->documentTypeValidation->setEntiteTypeList(array());
$this->documentTypeValidation->setConnecteurTypeActionClassList(array("MailsecEnvoyer","MailsecRenvoyer"));
$this->documentTypeValidation->setConnecteurTypeActionClassList(
['MailsecEnvoyer', 'MailsecRenvoyer', 'MailsecComputeReadMail']
);
}
public function testValidate()
......
......@@ -197,6 +197,18 @@ formulaire:
is_equal_error: Les mots de passe ne correspondent pas
key:
no-show: true
sent_mail_number:
name: Mails envoyés
default: "0"
no-show: true
sent_mail_read:
name: Mails lus
default: "0"
no-show: true
sent_mail_answered:
name: Mails répondus
default: "0"
no-show: true
"Retour GED #2":
has_ged_document_id_2:
no-show: true
......@@ -466,6 +478,7 @@ action:
to: to
cc: cc
bcc: bcc
sent_mail_number: sent_mail_number
action-automatique: mailsec-relance
mailsec-relance:
name: Relancé
......@@ -530,6 +543,24 @@ action:
rule:
no-action:
- creation
compute_read_mail:
name: Calcul des mails lus
rule:
role_id_e: no-role
action-class: StandardAction
connecteur-type: mailsec
connecteur-type-action: MailsecComputeReadMail
connecteur-type-mapping:
sent_mail_read: sent_mail_read
compute_answered_mail:
name: Calcul des mails répondus
rule:
role_id_e: no-role
action-class: StandardAction
connecteur-type: mailsec
connecteur-type-action: MailsecComputeAnsweredMail
connecteur-type-mapping:
sent_mail_answered: sent_mail_answered
preparation-send-ged_2:
name: "Préparation de l'envoi à la GED #2"
rule:
......
......@@ -62,6 +62,18 @@ formulaire:
is_equal_error: Les mots de passe ne correspondent pas
key:
no-show: true
sent_mail_number:
name: Mails envoyés
default: "0"
no-show: true
sent_mail_read:
name: Mails lus
default: "0"
no-show: true
sent_mail_answered:
name: Mails répondus
default: "0"
no-show: true
champs-affiches:
- titre
- dernier_etat
......@@ -147,6 +159,7 @@ action:
to: to
cc: cc
bcc: bcc
sent_mail_number: sent_mail_number
action-automatique: mailsec-relance
mailsec-relance:
name: Relancé
......@@ -211,3 +224,21 @@ action:
rule:
no-action:
- creation
compute_read_mail:
name: Calcul des mails lus
rule:
role_id_e: no-role
action-class: StandardAction
connecteur-type: mailsec
connecteur-type-action: MailsecComputeReadMail
connecteur-type-mapping:
sent_mail_read: sent_mail_read
compute_answered_mail:
name: Calcul des mails répondus
rule:
role_id_e: no-role
action-class: StandardAction
connecteur-type: mailsec
connecteur-type-action: MailsecComputeAnsweredMail
connecteur-type-mapping:
sent_mail_answered: sent_mail_answered
......@@ -178,6 +178,18 @@ formulaire:
is_equal_error: Les mots de passe ne correspondent pas
key:
no-show: true
sent_mail_number:
name: Mails envoyés
default: "0"
no-show: true
sent_mail_read:
name: Mails lus
default: "0"
no-show: true
sent_mail_answered:
name: Mails répondus
default: "0"
no-show: true
Acte:
acte_nature:
name: "Nature de l'acte"
......@@ -489,6 +501,7 @@ action:
to: to
cc: cc
bcc: bcc
sent_mail_number: sent_mail_number
action-automatique: mailsec-relance
mailsec-relance:
name: Relancé
......@@ -553,6 +566,24 @@ action:
rule:
no-action:
- creation
compute_read_mail:
name: Calcul des mails lus
rule:
role_id_e: no-role
action-class: StandardAction
connecteur-type: mailsec
connecteur-type-action: MailsecComputeReadMail
connecteur-type-mapping:
sent_mail_read: sent_mail_read
compute_answered_mail:
name: Calcul des mails répondus
rule:
role_id_e: no-role
action-class: StandardAction
connecteur-type: mailsec
connecteur-type-action: MailsecComputeAnsweredMail
connecteur-type-mapping:
sent_mail_answered: sent_mail_answered
pre-send-tdt:
name: "Préparation de l'envoi au Tdt"
rule:
......
......@@ -34,12 +34,29 @@ formulaire:
is_equal_error: Les mots de passe ne correspondent pas
key:
no-show: true
sent_mail_number:
name: Mails envoyés
default: '0'
no-show: true
sent_mail_read:
name: Mails lus
default: '0'
no-show: true
sent_mail_answered:
name: Mails répondus
default: '0'
no-show: true
page-condition:
Mail sécurisé:
envoi_mailsec: true
champs-affiches:
- sent_mail_number
- sent_mail_read
- sent_mail_answered
action:
preparation-send-mailsec:
......@@ -61,6 +78,7 @@ action:
to: to
cc: cc
bcc: bcc
sent_mail_number: sent_mail_number
action-automatique: mailsec-relance
mailsec-relance:
......@@ -133,4 +151,22 @@ action:
no-action:
- creation
compute_read_mail:
name: Calcul des mails lus
rule:
role_id_e: no-role
action-class: StandardAction
connecteur-type: mailsec
connecteur-type-action: MailsecComputeReadMail
connecteur-type-mapping:
sent_mail_read: sent_mail_read
compute_answered_mail:
name: Calcul des mails répondus
rule:
role_id_e: no-role
action-class: StandardAction
connecteur-type: mailsec
connecteur-type-action: MailsecComputeAnsweredMail
connecteur-type-mapping:
sent_mail_answered: sent_mail_answered
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