When an Avis is created an email is sent to the Gestionnaire
This commit is contained in:
parent
f6359cb7aa
commit
efdac753c6
5 changed files with 60 additions and 0 deletions
9
app/mailers/avis_mailer.rb
Normal file
9
app/mailers/avis_mailer.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
class AvisMailer < ApplicationMailer
|
||||||
|
|
||||||
|
def you_are_invited_on_dossier(avis)
|
||||||
|
@avis = avis
|
||||||
|
email = @avis.gestionnaire.try(:email) || @avis.email
|
||||||
|
mail(to: email, subject: "Donnez votre avis sur le dossier nº #{@avis.dossier.id} (#{@avis.dossier.procedure.libelle})")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -2,6 +2,8 @@ class Avis < ApplicationRecord
|
||||||
belongs_to :dossier
|
belongs_to :dossier
|
||||||
belongs_to :gestionnaire
|
belongs_to :gestionnaire
|
||||||
|
|
||||||
|
after_create :notify_gestionnaire
|
||||||
|
|
||||||
scope :with_answer, -> { where.not(answer: nil) }
|
scope :with_answer, -> { where.not(answer: nil) }
|
||||||
scope :without_answer, -> { where(answer: nil) }
|
scope :without_answer, -> { where(answer: nil) }
|
||||||
scope :for_dossier, ->(dossier_id) { where(dossier_id: dossier_id) }
|
scope :for_dossier, ->(dossier_id) { where(dossier_id: dossier_id) }
|
||||||
|
@ -10,4 +12,8 @@ class Avis < ApplicationRecord
|
||||||
def email_to_display
|
def email_to_display
|
||||||
gestionnaire.try(:email) || email
|
gestionnaire.try(:email) || email
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notify_gestionnaire
|
||||||
|
AvisMailer.you_are_invited_on_dossier(self).deliver_now
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
24
app/views/avis_mailer/you_are_invited_on_dossier.html.haml
Normal file
24
app/views/avis_mailer/you_are_invited_on_dossier.html.haml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
%html
|
||||||
|
%body
|
||||||
|
%p
|
||||||
|
Bonjour,
|
||||||
|
%br
|
||||||
|
= "Vous avez été invité à donner votre avis sur le dossier nº #{@avis.dossier.id} de la procédure : #{@avis.dossier.procedure.libelle}."
|
||||||
|
%br
|
||||||
|
Message de votre interlocuteur :
|
||||||
|
|
||||||
|
%p{ style: 'border: 1px solid grey' }
|
||||||
|
= @avis.introduction
|
||||||
|
|
||||||
|
%p
|
||||||
|
= link_to "Connectez-vous pour donner votre avis", new_gestionnaire_session_url
|
||||||
|
|
||||||
|
Bonne journée,
|
||||||
|
%br
|
||||||
|
%br
|
||||||
|
L'équipe Téléprocédures Simplifiées
|
||||||
|
%br
|
||||||
|
%br
|
||||||
|
%hr
|
||||||
|
%br
|
||||||
|
Merci de ne pas répondre à cet email. Postez directement vos questions dans votre dossier sur la plateforme.
|
13
spec/mailers/avis_mailer_spec.rb
Normal file
13
spec/mailers/avis_mailer_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
RSpec.describe AvisMailer, type: :mailer do
|
||||||
|
describe '.you_are_invited_on_dossier' do
|
||||||
|
let(:avis) { create(:avis) }
|
||||||
|
|
||||||
|
subject { described_class.you_are_invited_on_dossier(avis) }
|
||||||
|
|
||||||
|
it { expect(subject.subject).to eq("Donnez votre avis sur le dossier nº #{avis.dossier.id} (#{avis.dossier.procedure.libelle})") }
|
||||||
|
it { expect(subject.body).to include("Vous avez été invité à donner votre avis sur le dossier nº #{avis.dossier.id} de la procédure : #{avis.dossier.procedure.libelle}.") }
|
||||||
|
it { expect(subject.body).to include(avis.introduction) }
|
||||||
|
end
|
||||||
|
end
|
8
spec/mailers/previews/avis_mailer_preview.rb
Normal file
8
spec/mailers/previews/avis_mailer_preview.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Preview all emails at http://localhost:3000/rails/mailers/avis_mailer
|
||||||
|
class AvisMailerPreview < ActionMailer::Preview
|
||||||
|
|
||||||
|
def you_are_invited_on_dossier
|
||||||
|
AvisMailer.you_are_invited_on_dossier(Avis.last)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
Loading…
Reference in a new issue