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

[TRELLO-2836] Send BauxPrecraire reports to the right DDs #1825

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all 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 app/models/report/ReportStatus.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ object ReportStatus extends PlayEnum[ReportStatus] {
/** Not read by pro status
*/
case object TraitementEnCours extends ReportStatus
case object NonConsulte extends ReportStatus

/** Read by pro status
*/
case object Transmis extends ReportStatus
case object PromesseAction extends ReportStatus
case object Infonde extends ReportStatus
case object NonConsulte extends ReportStatus
case object ConsulteIgnore extends ReportStatus
case object MalAttribue extends ReportStatus
case object SuppressionRGPD extends ReportStatus
Expand Down
38 changes: 35 additions & 3 deletions app/orchestrators/EmailNotificationOrchestrator.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package orchestrators

import cats.implicits.toTraverseOps
import models.report.Report
import models.report.ReportTag
import play.api.Logger
Expand Down Expand Up @@ -33,13 +34,44 @@ class EmailNotificationOrchestrator(mailService: MailService, subscriptionReposi
}
}

private val postalCodeRegex = "\\d{5}".r
private def extractPostalCode(s: String) =
postalCodeRegex.findFirstIn(s)

private def getDDEmails(report: Report) = {
val maybeTag = shouldNotifyDgccrf(report)

maybeTag match {
// Cas spécial BauxPrecaire
case Some(ReportTag.BauxPrecaire) =>
for {
// On doit envoyer tous les signalements Baux précaire à la dd 33. Ce sont eux qui les traitent
dd33Email <- subscriptionRepository.getDirectionDepartementaleEmail("33")
// Adresse fournie par le conso à l'étape 3.
storeDDEmail <- report.details
.find(_.label == "Adresse précise du magasin (numéro, nom de rue, code postal et nom de la ville) :")
.map(_.value)
.flatMap(extractPostalCode)
.traverse(postalCode => subscriptionRepository.getDirectionDepartementaleEmail(postalCode.take(2)))
// En fallback, l'adresse de l'entreprise identifiée
companyDDEmail <- report.companyAddress.postalCode.traverse(postalCode =>
subscriptionRepository.getDirectionDepartementaleEmail(postalCode.take(2))
)
} yield dd33Email ++ companyDDEmail.getOrElse(Seq.empty) ++ storeDDEmail.getOrElse(Seq.empty)
case Some(_) =>
// Cas nominal, on prend les emails de la DD de l'entreprise
report.companyAddress.postalCode
.map(postalCode => subscriptionRepository.getDirectionDepartementaleEmail(postalCode.take(2)))
.getOrElse(Future.successful(Seq.empty))
case None => Future.successful(Seq.empty)
}
}

def notifyDgccrfIfNeeded(report: Report): Future[Unit] =
getNotificationEmail(report) match {
case Some(email) =>
for {
ddEmails <- report.companyAddress.postalCode
.map(postalCode => subscriptionRepository.getDirectionDepartementaleEmail(postalCode.take(2)))
.getOrElse(Future.successful(Seq.empty))
ddEmails <- getDDEmails(report)
_ <-
if (ddEmails.nonEmpty) {
mailService.send(email(ddEmails))
Expand Down
Loading