Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OKR][Emails] Modifier les objets des emails partenaires #2133

Merged
merged 6 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ WIDGET_AFFECTATION_PARTNER_CACHE_EXPIRED_AFTER=30 #second
WIDGET_SIGNALEMENT_ACCEPTED_NO_SUIVI_CACHE_EXPIRED_AFTER=30 #second
WIDGET_SIGNALEMENT_TERRITOIRE_CACHE_EXPIRED_AFTER=30 #second
WIDGET_ESABORA_EVENTS_CACHE_EXPIRED_AFTER=3600 #second
FEATURE_ASK_VISITE_ENABLE=0
FEATURE_ASK_VISITE_ENABLE=1
FEATURE_NEW_FORM_ENABLE=0
FEATURE_OILHI_ENABLE=1
CRON_ENABLE=1
Expand Down
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ WIREMOCK_HOSTNAME=histologe_wiremock
WIREMOCK_PORT=8080
FEATURE_NEW_FORM_ENABLE=1
FEATURE_OILHI_ENABLE=1
FEATURE_ASK_VISITE_ENABLE=1
CRON_ENABLE=1
MAIL_ENABLE=1
ESABORA_CRON_CLOCK_SLEEP_INTERVAL=60 #second
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,4 @@ jobs:
MAILER_DSN: ${{ secrets.MAILER_DSN_CI }}
CRON_ENABLE: 1
MAIL_ENABLE: 1
FEATURE_ASK_VISITE_ENABLE: 1
24 changes: 8 additions & 16 deletions src/Controller/Back/AffectationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use App\Messenger\InterconnectionBus;
use App\Repository\AffectationRepository;
use App\Repository\PartnerRepository;
use App\Repository\SuiviRepository;
use App\Specification\Signalement\FirstAffectationAcceptedSpecification;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -103,7 +103,11 @@ public function removePartnerAffectation(
return $this->json(['status' => 'denied'], 400);
}

#[Route('/{signalement}/{affectation}/{user}/response', name: 'back_signalement_affectation_response', methods: 'POST')]
#[Route(
'/{signalement}/{affectation}/{user}/response',
name: 'back_signalement_affectation_response',
methods: 'POST'
)]
public function affectationResponseSignalement(
SuiviManager $suiviManager,
UserManager $userManager,
Expand All @@ -112,7 +116,7 @@ public function affectationResponseSignalement(
Affectation $affectation,
User $user,
Request $request,
SuiviRepository $suiviRepository,
FirstAffectationAcceptedSpecification $firstAcceptedAffectationSpecification,
): Response {
$this->denyAccessUnlessGranted('ASSIGN_ANSWER', $affectation);
if ($this->isCsrfTokenValid('signalement_affectation_response_'.$signalement->getId(), $request->get('_token'))
Expand All @@ -122,19 +126,7 @@ public function affectationResponseSignalement(
$motifRefus = (Affectation::STATUS_REFUSED === $status) ? $response['motifRefus'] : null;
$affectation = $this->affectationManager->updateAffectation($affectation, $user, $status, $motifRefus);

$suiviAffectationAccepted = $suiviRepository->findSuiviByDescription(
$signalement,
'<p>Suite à votre signalement, le ou les partenaires compétents'
);
$affectationAccepted = $signalement->getAffectations()->filter(function (Affectation $affectation) {
return Affectation::STATUS_ACCEPTED === $affectation->getStatut();
});

if (!$signalement->getIsImported()
&& 1 === $affectationAccepted->count()
&& Affectation::STATUS_ACCEPTED === $affectation->getStatut()
&& empty($suiviAffectationAccepted)
) {
if ($firstAcceptedAffectationSpecification->isSatisfiedBy($signalement, $affectation)) {
$adminEmail = $parameterBag->get('user_system_email');
$adminUser = $userManager->findOneBy(['email' => $adminEmail]);
$suiviManager->createSuivi(
Expand Down
22 changes: 22 additions & 0 deletions src/DataFixtures/Files/Affectation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ affectations:
affected_by: "admin-territoire-13-01@histologe.fr"
motif_cloture: "DEPART_OCCUPANT"
territory: "Bouches-du-Rhône"
-
signalement: 2022-6
partner: "partenaire-13-01@histologe.fr"
statut: 1
answered_by: "admin-territoire-13-01@histologe.fr"
affected_by: "admin-territoire-13-01@histologe.fr"
territory: "Bouches-du-Rhône"
-
signalement: 2022-12
partner: "partenaire-01-03@histologe.fr"
Expand Down Expand Up @@ -174,3 +181,18 @@ affectations:
answered_by: "admin-01@histologe.fr"
affected_by: "admin-01@histologe.fr"
territory: "Pas-de-Calais"
-
signalement: 2024-01
partner: "partenaire-62-01@histologe.fr"
statut: 0
answered_by: "admin-01@histologe.fr"
affected_by: "admin-01@histologe.fr"
territory: "Pas-de-Calais"
-
signalement: 2023-20
partner: "partenaire-13-01@histologe.fr"
statut: 1
answered_by: "admin-01@histologe.fr"
affected_by: "admin-01@histologe.fr"
territory: "Bouches-du-Rhône"
created_at: '-15 days'
12 changes: 12 additions & 0 deletions src/DataFixtures/Files/Intervention.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,15 @@ interventions:
conclude_procedure: [ 'RSD' ]
occupant_present: 1
proprietaire_present: 0
-
signalement: "2024-02"
partner: "partenaire-62-01@histologe.fr"
user: "user-62-01@histologe.fr"
scheduled_at: '+2 days'
status: 'PLANNED'
-
signalement: "2022-6"
partner: "partenaire-13-01@histologe.fr"
user: "admin-partenaire-13-01@histologe.fr"
scheduled_at: '-2 days'
status: 'PLANNED'
6 changes: 6 additions & 0 deletions src/DataFixtures/Loader/LoadAffectationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public function loadAffectation(ObjectManager $manager, array $row): void
->setMotifRefus(MotifRefus::tryFrom($row['motif_refus']));
}

if (isset($row['created_at'])) {
$affectation
->setCreatedAt($createdAt = (new \DateTimeImmutable())->modify($row['created_at']))
->setAnsweredAt($createdAt);
}

$manager->persist($affectation);
}

Expand Down
17 changes: 14 additions & 3 deletions src/DataFixtures/Loader/LoadInterventionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ private function loadInterventions(ObjectManager $manager, array $row): void
$intervention = (new Intervention())
->setSignalement($this->signalementRepository->findOneBy(['reference' => $row['signalement']]))
->setPartner($this->partnerRepository->findOneBy(['email' => $row['partner']]))
->setScheduledAt(isset($row['scheduled_at'])
? new \DateTimeImmutable($row['scheduled_at'])
: (new \DateTimeImmutable())->modify('+1 month'))
->setScheduledAt($this->getScheduledAt($row))
->setType(InterventionType::VISITE)
->setDetails($row['details'] ?? null)
->setOccupantPresent($row['occupant_present'] ?? null)
Expand Down Expand Up @@ -82,6 +80,19 @@ private function loadInterventions(ObjectManager $manager, array $row): void
$manager->persist($intervention);
}

public function getScheduledAt(array $row): \DateTimeImmutable
{
if (isset($row['scheduled_at'])) {
if (str_contains($row['scheduled_at'], '2 days')) {
return (new \DateTimeImmutable())->modify($row['scheduled_at']);
}

return new \DateTimeImmutable($row['scheduled_at']);
}

return (new \DateTimeImmutable())->modify('+1 month');
}

public function getOrder(): int
{
return 17;
Expand Down
19 changes: 14 additions & 5 deletions src/Factory/Interconnection/Oilhi/DossierMessageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ private function buildInterventionData(Signalement $signalement): ?array

$interventionData['date_visite'] = $intervention->getScheduledAt()->format(self::FORMAT_DATE);
$interventionData['operateur_visite'] = $intervention->getDoneBy() ?? $intervention->getPartner()->getNom();
$interventionData['rapport_visite'] = $this->urlGenerator->generate(
'show_uploaded_file',
['filename' => $intervention->getFiles()->first()->getFilename()],
UrlGeneratorInterface::ABSOLUTE_URL
).'?t='.$this->csrfTokenManager->getToken('suivi_signalement_ext_file_view');
$interventionData['rapport_visite'] = $this->getRapportVisite($intervention);

return $interventionData;
}
Expand Down Expand Up @@ -218,4 +214,17 @@ private function getTypeDeclarant(Signalement $signalement): ?string

return $typeDeclarant;
}

private function getRapportVisite(Intervention $intervention): ?string
{
if ($intervention->getFiles()->isEmpty()) {
return null;
}

return $this->urlGenerator->generate(
'show_uploaded_file',
['filename' => $intervention->getFiles()->first()->getFilename()],
UrlGeneratorInterface::ABSOLUTE_URL
).'?t='.$this->csrfTokenManager->getToken('suivi_signalement_ext_file_view');
}
}
11 changes: 10 additions & 1 deletion src/Service/Mailer/Mail/Signalement/AssignementNewMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class AssignementNewMailer extends AbstractNotificationMailer
{
protected ?NotificationMailerType $mailerType = NotificationMailerType::TYPE_ASSIGNMENT_NEW;
protected ?string $mailerSubject = 'Un nouveau signalement vous attend sur %param.platform_name%.';
protected ?string $mailerSubject = '[%s] Un nouveau signalement vous attend sur %s.';
protected ?string $mailerButtonText = 'Accéder au signalement';
protected ?string $mailerTemplate = 'affectation_email';

Expand All @@ -40,4 +40,13 @@ public function getMailerParamsFromNotification(NotificationMail $notificationMa
),
];
}

public function updateMailerSubjectFromNotification(NotificationMail $notificationMail): void
{
$this->mailerSubject = sprintf(
$this->mailerSubject,
$notificationMail->getSignalement()->getCpOccupant(),
$this->parameterBag->get('platform_name'),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class SignalementClosedToAllPartnersMailer extends AbstractNotificationMailer
{
protected ?NotificationMailerType $mailerType = NotificationMailerType::TYPE_SIGNALEMENT_CLOSED_TO_PARTNERS;
protected ?string $mailerSubject = 'Le signalement #%s a été cloturé';
protected ?string $mailerSubject = '[%s - %s] Clôture du signalement';
protected ?string $mailerButtonText = 'Accéder au signalement';
protected ?string $mailerTemplate = 'closed_to_partners_signalement_email';

Expand Down Expand Up @@ -41,6 +41,11 @@ public function getMailerParamsFromNotification(NotificationMail $notificationMa

public function updateMailerSubjectFromNotification(NotificationMail $notificationMail): void
{
$this->mailerSubject = sprintf($this->mailerSubject, $notificationMail->getSignalement()->getReference());
$signalement = $notificationMail->getSignalement();
$this->mailerSubject = sprintf(
$this->mailerSubject,
$signalement->getReference(),
$signalement->getNomOccupant()
sfinx13 marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class SignalementClosedToOnePartnerMailer extends AbstractNotificationMailer
{
protected ?NotificationMailerType $mailerType = NotificationMailerType::TYPE_SIGNALEMENT_CLOSED_TO_PARTNER;
protected ?string $mailerSubject = '[%s - %s] %s a terminé son intervention';
protected ?string $mailerButtonText = 'Accéder au signalement';
protected ?string $mailerTemplate = 'closed_to_partner_signalement_email';

Expand Down Expand Up @@ -45,10 +46,12 @@ public function updateMailerSubjectFromNotification(NotificationMail $notificati
{
/** @var User $user */
$user = $this->security->getUser();
$signalement = $notificationMail->getSignalement();
$this->mailerSubject = sprintf(
'%s a terminé son intervention sur #%s',
$this->mailerSubject,
$signalement->getReference(),
$signalement->getNomOccupant(),
sfinx13 marked this conversation as resolved.
Show resolved Hide resolved
$user?->getPartner()->getNom(),
$notificationMail?->getSignalement()->getReference()
);
}
}
7 changes: 6 additions & 1 deletion src/Service/Mailer/Mail/Signalement/SignalementNewMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class SignalementNewMailer extends AbstractNotificationMailer
{
protected ?NotificationMailerType $mailerType = NotificationMailerType::TYPE_SIGNALEMENT_NEW;
protected ?string $mailerSubject = 'Un nouveau signalement vous attend';
protected ?string $mailerSubject = '[%s] Un nouveau signalement vous attend';
protected ?string $mailerButtonText = 'Voir le signalement';
protected ?string $mailerTemplate = 'new_signalement_email';

Expand All @@ -38,4 +38,9 @@ public function getMailerParamsFromNotification(NotificationMail $notificationMa
], UrlGeneratorInterface::ABSOLUTE_URL),
];
}

public function updateMailerSubjectFromNotification(NotificationMail $notificationMail): void
{
$this->mailerSubject = sprintf($this->mailerSubject, $notificationMail->getSignalement()->getCpOccupant());
}
}
7 changes: 5 additions & 2 deletions src/Service/Mailer/Mail/Suivi/SuiviNewCommentBackMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class SuiviNewCommentBackMailer extends AbstractNotificationMailer
{
protected ?NotificationMailerType $mailerType = NotificationMailerType::TYPE_NEW_COMMENT_BACK;
protected ?string $mailerSubject = '[%s - %s] Nouveau suivi';
protected ?string $mailerButtonText = 'Accéder au signalement';
protected ?string $mailerTemplate = 'nouveau_suivi_signalement_back_email';

Expand All @@ -37,9 +38,11 @@ public function getMailerParamsFromNotification(NotificationMail $notificationMa

public function updateMailerSubjectFromNotification(NotificationMail $notificationMail): void
{
$signalement = $notificationMail->getSignalement();
$this->mailerSubject = sprintf(
'Nouveau suivi sur le signalement #%s',
$notificationMail->getSignalement()->getReference()
$this->mailerSubject,
$signalement->getReference(),
$signalement->getNomOccupant()
sfinx13 marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class SuiviVisiteAbortedToPartnerMailer extends AbstractNotificationMailer
{
protected ?NotificationMailerType $mailerType = NotificationMailerType::TYPE_VISITE_ABORTED_TO_PARTNER;
protected ?string $mailerSubject = '[%s - %s] Visite non effectuée';
protected ?string $mailerButtonText = 'Accéder au signalement';
protected ?string $mailerTemplate = 'nouveau_suivi_visite_aborted_email';

Expand All @@ -39,6 +40,10 @@ public function getMailerParamsFromNotification(NotificationMail $notificationMa

public function updateMailerSubjectFromNotification(NotificationMail $notificationMail): void
{
$this->mailerSubject = sprintf('#%s Visite non effectuée', $notificationMail->getSignalement()->getReference());
$signalement = $notificationMail->getSignalement();
$this->mailerSubject = sprintf($this->mailerSubject,
$signalement->getReference(),
$signalement->getNomOccupant()
sfinx13 marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class SuiviVisiteConfirmedToPartnerMailer extends AbstractNotificationMailer
{
protected ?NotificationMailerType $mailerType = NotificationMailerType::TYPE_VISITE_CONFIRMED_TO_PARTNER;
protected ?string $mailerSubject = '[%s - %s] Conclusion de visite disponible';
protected ?string $mailerButtonText = 'Accéder au signalement';
protected ?string $mailerTemplate = 'nouveau_suivi_visite_confirmed_to_partner_email';

Expand All @@ -39,6 +40,10 @@ public function getMailerParamsFromNotification(NotificationMail $notificationMa

public function updateMailerSubjectFromNotification(NotificationMail $notificationMail): void
{
$this->mailerSubject = sprintf('#%s Conclusion de visite disponible', $notificationMail->getSignalement()->getReference());
$signalement = $notificationMail->getSignalement();
$this->mailerSubject = sprintf($this->mailerSubject,
$signalement->getReference(),
$signalement->getNomOccupant()
sfinx13 marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class SuiviVisiteCreatedToPartnerMailer extends AbstractNotificationMailer
{
protected ?NotificationMailerType $mailerType = NotificationMailerType::TYPE_VISITE_CREATED_TO_PARTNER;
protected ?string $mailerSubject = '[%s - %s] Visite programmée';
protected ?string $mailerButtonText = 'Accéder au signalement';
protected ?string $mailerTemplate = 'nouveau_suivi_visite_created_to_partner_email';

Expand All @@ -39,6 +40,10 @@ public function getMailerParamsFromNotification(NotificationMail $notificationMa

public function updateMailerSubjectFromNotification(NotificationMail $notificationMail): void
{
$this->mailerSubject = sprintf('#%s Visite du logement prévue', $notificationMail->getSignalement()->getReference());
$signalement = $notificationMail->getSignalement();
$this->mailerSubject = sprintf($this->mailerSubject,
$signalement->getReference(),
$signalement->getNomOccupant()
sfinx13 marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class SuiviVisiteFutureReminderToPartnerMailer extends AbstractNotificationMailer
{
protected ?NotificationMailerType $mailerType = NotificationMailerType::TYPE_VISITE_FUTURE_REMINDER_TO_PARTNER;
protected ?string $mailerSubject = '[%s - %s] Rappel : visite du logement prévue';
sfinx13 marked this conversation as resolved.
Show resolved Hide resolved
protected ?string $mailerButtonText = 'Accéder au signalement';
protected ?string $mailerTemplate = 'nouveau_suivi_visite_future_reminder_to_partner_email';

Expand All @@ -39,6 +40,11 @@ public function getMailerParamsFromNotification(NotificationMail $notificationMa

public function updateMailerSubjectFromNotification(NotificationMail $notificationMail): void
{
$this->mailerSubject = sprintf('#%s Rappel : visite du logement prévue', $notificationMail->getSignalement()->getReference());
$signalement = $notificationMail->getSignalement();
$this->mailerSubject = sprintf(
$this->mailerSubject,
$signalement->getReference(),
$signalement->getNomOccupant()
sfinx13 marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
Loading
Loading