Merge pull request #7867 from betagouv/fix_mail_previewers

Fix: aperçu des mails
This commit is contained in:
LeSim 2022-10-06 18:02:37 +02:00 committed by GitHub
commit 6054bf68a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 65 additions and 33 deletions

View file

@ -2,6 +2,7 @@ class ExpertMailer < ApplicationMailer
helper MailerHelper
layout 'mailers/layout'
# TODO: replace with v2 after MEP
def send_dossier_decision(avis_id)
@avis = Avis.eager_load(:dossier).find(avis_id)
@dossier = @avis.dossier
@ -11,6 +12,16 @@ class ExpertMailer < ApplicationMailer
mail(to: email, subject: subject)
end
def send_dossier_decision_v2(avis)
@avis = avis
@dossier = @avis.dossier
email = @avis.expert.email
@decision = decision_dossier(@dossier)
subject = "Dossier n° #{@dossier.id} a été #{@decision} - #{@dossier.procedure.libelle}"
mail(template_name: 'send_dossier_decision', to: email, subject: subject)
end
end
def decision_dossier(dossier)

View file

@ -1262,11 +1262,12 @@ class Dossier < ApplicationRecord
.pluck('avis.id, experts_procedures.id')
# rubocop:disable Lint/UnusedBlockArgument
avis_ids = avis_experts_procedures_ids
avis = avis_experts_procedures_ids
.uniq { |(avis_id, experts_procedures_id)| experts_procedures_id }
.map { |(avis_id, _)| avis_id }
.then { |avis_ids| Avis.find(avis_ids) }
# rubocop:enable Lint/UnusedBlockArgument
avis_ids.each { |avis_id| ExpertMailer.send_dossier_decision(avis_id).deliver_later }
avis.each { |a| ExpertMailer.send_dossier_decision_v2(a).deliver_later }
end
end

View file

@ -1,8 +1,8 @@
class AdministrateurMailerPreview < ActionMailer::Preview
def activate_before_expiration
administrateur = Administrateur.new(reset_password_sent_at: Time.zone.now)
user = User.new(reset_password_sent_at: Time.zone.now)
AdministrateurMailer.activate_before_expiration(administrateur, "a4d4e4f4b4d445")
AdministrateurMailer.activate_before_expiration(user, "a4d4e4f4b4d445")
end
def notify_procedure_expires_when_termine_forced

View file

@ -1,12 +1,4 @@
class AdministrationMailerPreview < ActionMailer::Preview
def dubious_procedures
procedures_and_champs = [
[procedure_1, [TypeDeChamp.new(libelle: 'iban'), TypeDeChamp.new(libelle: 'religion')]],
[procedure_2, [TypeDeChamp.new(libelle: 'iban'), TypeDeChamp.new(libelle: 'numéro de carte bleu')]]
]
AdministrationMailer.dubious_procedures(procedures_and_champs)
end
def invite_admin
AdministrationMailer.invite_admin(administrateur, "12345678", 0)
end

View file

@ -1,12 +1,30 @@
# Preview all emails at http://localhost:3000/rails/mailers/avis_mailer
class AvisMailerPreview < ActionMailer::Preview
def avis_invitation
gestionaire = Instructeur.new(id: 1, user: User.new(email: 'jeanmichel.de-chauvigny@exemple.fr'))
avis = Avis.new(id: 1, email: 'test@exemple.fr', claimant: gestionaire)
targeted_link = TargetedUserLink.build(target_model: avis, user: avis.expert.user, target_context: :avis)
avis.dossier = Dossier.new(id: 1)
avis.dossier.procedure = Procedure.new(libelle: 'Démarche pour faire des marches')
avis.introduction = 'Il faudrait vérifier le certificat de conformité.'
AvisMailer.avis_invitation(avis, targeted_link)
procedure = Procedure.new(libelle: 'une belle procedure')
dossier = Dossier.new(id: 1, procedure:)
def dossier.visible_by_administration? = true
claimant = Instructeur.new(user: User.new(email: 'claimant@ds.fr'))
expert = Expert.new(user: User.new(email: '1@sa.com'))
avis = Avis.new(
id: 1,
introduction: 'intro',
dossier:,
expert:,
claimant:,
procedure:
)
def avis.targeted_user_links
stub = {}
def stub.find_or_create_by(_h)
TargetedUserLink.new(id: SecureRandom.uuid)
end
stub
end
AvisMailer.avis_invitation(avis, nil)
end
end

View file

@ -45,10 +45,6 @@ class DossierMailerPreview < ActionMailer::Preview
DossierMailer.notify_brouillon_deletion(dossier_hashes, usager_email)
end
def notify_instructeur_deletion_to_user
DossierMailer.notify_instructeur_deletion_to_user(deleted_dossier, usager_email)
end
def notify_deletion_to_administration
DossierMailer.notify_deletion_to_administration(deleted_dossier, administration_email)
end

View file

@ -1,11 +1,15 @@
class ExpertMailerPreview < ActionMailer::Preview
def send_dossier_decision
procedure = Procedure.new(libelle: 'Démarche pour faire des marches')
procedure = Procedure.new(id: 1, libelle: 'Démarche pour faire des marches')
dossier = Dossier.new(id: 1, procedure: procedure)
instructeur = Instructeur.new(id: 1, user: User.new(email: 'jeanmichel.de-chauvigny@exemple.fr'))
expert = Expert.new(id: 1, user: User.new('moussa.kanga@exemple.fr'))
expert = Expert.new(id: 1, user: User.new(email: 'moussa.kanga@exemple.fr'))
experts_procedure = ExpertsProcedure.new(expert: expert, procedure: procedure, allow_decision_access: true)
avis = Avis.new(id: 1, email: 'test@exemple.fr', dossier: dossier, claimant: instructeur, experts_procedure: experts_procedure)
ExpertMailer.send_dossier_decision(avis.id)
avis = Avis.new(id: 1, email: 'test@exemple.fr', claimant: instructeur, dossier:, experts_procedure:, expert:)
ExpertMailer.send_dossier_decision_v2(avis)
end
end

View file

@ -1,6 +1,7 @@
class GroupeInstructeurMailerPreview < ActionMailer::Preview
def add_instructeurs
groupe = GroupeInstructeur.new(label: 'Val-De-Marne')
procedure = Procedure.new(id: 1, libelle: 'une superbe procedure')
groupe = GroupeInstructeur.new(id: 1, label: 'Val-De-Marne', procedure:)
current_instructeur_email = 'admin@dgfip.com'
instructeurs = Instructeur.limit(2)
GroupeInstructeurMailer.add_instructeurs(groupe, instructeurs, current_instructeur_email)

View file

@ -11,10 +11,6 @@ class InstructeurMailerPreview < ActionMailer::Preview
InstructeurMailer.send_login_token(instructeur, "token")
end
def invite_instructeur
InstructeurMailer.invite_instructeur(instructeur, 'aedfa0d0')
end
def user_to_instructeur
InstructeurMailer.user_to_instructeur(instructeur.email)
end
@ -25,12 +21,16 @@ class InstructeurMailerPreview < ActionMailer::Preview
procedure_libelle: 'une superbe démarche',
procedure_id: 213,
nb_en_construction: 2,
nb_en_instruction: 2,
nb_accepted: 4,
nb_notification: 2
},
{
procedure_libelle: 'une démarche incroyable',
procedure_id: 213,
nb_en_construction: 1,
nb_en_instruction: 2,
nb_accepted: 5,
nb_notification: 1
}
]

View file

@ -15,10 +15,15 @@ class InviteMailerPreview < ActionMailer::Preview
dossier: dossier,
user: invited_user,
email: invited_user.email,
email_sender: 'sender@gouv.fr'
email_sender: 'sender@gouv.fr',
targeted_user_link: targeted_user_link
)
end
def targeted_user_link
TargetedUserLink.new(id: SecureRandom.uuid)
end
def dossier
Dossier.new(procedure: procedure)
end

View file

@ -20,6 +20,10 @@ class UserMailerPreview < ActionMailer::Preview
UserMailer.send_archive(Instructeur.first, Procedure.first, Archive.first)
end
def invite_instructeur
UserMailer.invite_instructeur(user, 'aedfa0d0')
end
private
def user