From 2cacc6b444b666075ef5cf600856270bc3e34eef Mon Sep 17 00:00:00 2001 From: echarp Date: Mon, 21 Jul 2014 01:26:58 +0200 Subject: [PATCH] =?UTF-8?q?Le=20rajout=20de=20note=20=C3=A0=20un=20evt=20e?= =?UTF-8?q?n=20mod=C3=A9ration=20g=C3=A9n=C3=A8re=20un=20mail=20=C3=A0=20d?= =?UTF-8?q?estination=20des=20mod=C3=A9rateurs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/notes_controller.rb | 3 ++- app/mailers/note_mailer.rb | 10 ++++++++-- app/views/note_mailer/create.text.haml | 10 +++------- app/views/note_mailer/notify.text.haml | 13 +++++++++++++ config/locales/fr.yml | 9 +++++++-- test/mailers/note_mailer_test.rb | 11 +++++++++-- test/mailers/previews/note_mailer_preview.rb | 6 ++++++ 7 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 app/views/note_mailer/notify.text.haml diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 1e996b73..f86f63af 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -15,10 +15,11 @@ class NotesController < ApplicationController if @note.save if params[:envoiParMail] == 'oui' # Send an update mail to its author - NoteMailer.create(@note).deliver + NoteMailer.notify(@note).deliver @note.contents = t '.sendByMailWrap', contents: @note.contents @note.save end + NoteMailer.create(@note).deliver format.html { redirect_to moderations_url, notice: t('.ok') } format.json { render action: 'show', status: :created, location: @event } diff --git a/app/mailers/note_mailer.rb b/app/mailers/note_mailer.rb index 9d0ce283..0e52669c 100644 --- a/app/mailers/note_mailer.rb +++ b/app/mailers/note_mailer.rb @@ -1,10 +1,16 @@ class NoteMailer < ActionMailer::Base - def create(note) + def notify(note) @note = note mail 'In-Reply-To' => "", to: note.event.submitter, - cc: AgendaDuLibreRails::Application.config.action_mailer.default_options[:from], + subject: t('note_mailer.notify.subject', subject: note.event.title) + end + + def create(note) + @note = note + + mail 'In-Reply-To' => "", subject: t('note_mailer.create.subject', subject: note.event.title) end end diff --git a/app/views/note_mailer/create.text.haml b/app/views/note_mailer/create.text.haml index d949f7b6..62a25967 100644 --- a/app/views/note_mailer/create.text.haml +++ b/app/views/note_mailer/create.text.haml @@ -2,12 +2,8 @@ \ =t '.body', subject: @note.event.title, contents: @note.contents \ -= sanitize @note.contents.html_safe, - tags: %w(p br table tr td ul ol li a strong b em i img), - attributes: %w(href src width height) += strip_tags @note.contents +\ += moderations_url \ -=t '.edit_link' -\ -= edit_event_url @note.event, secret: @note.event.secret -\ =t '.signature' diff --git a/app/views/note_mailer/notify.text.haml b/app/views/note_mailer/notify.text.haml new file mode 100644 index 00000000..d949f7b6 --- /dev/null +++ b/app/views/note_mailer/notify.text.haml @@ -0,0 +1,13 @@ +=t '.title' +\ +=t '.body', subject: @note.event.title, contents: @note.contents +\ += sanitize @note.contents.html_safe, + tags: %w(p br table tr td ul ol li a strong b em i img), + attributes: %w(href src width height) +\ +=t '.edit_link' +\ += edit_event_url @note.event, secret: @note.event.secret +\ +=t '.signature' diff --git a/config/locales/fr.yml b/config/locales/fr.yml index ea0de679..2b530da7 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -229,7 +229,7 @@ Exemple: `%{daylimit}`" back: Modération title: Ajout d'une note de modération create: - sendByMailWrap: "

Demande d'informations complémentaires:

%{contents}
" + sendByMailWrap: "

Demande d'informations complémentaires:

%{contents}
" ok: La note a bien été ajoutée, merci! form: title: Rédaction du message @@ -298,7 +298,7 @@ Exemple: `%{daylimit}`" reminder: "Pour rappel, l'événement:" signature: "-- \nL'équipe des modérateurs de l'Agenda du Libre" note_mailer: - create: + notify: subject: "[Agenda du Libre] Demande d'informations sur l'événement '%{subject}'" title: Bonjour, body: "Nous avons bien reçu votre proposition d'événement '%{subject}', @@ -308,3 +308,8 @@ Exemple: `%{daylimit}`" edit_link: "Nous vous invitons à ajouter ces informations en éditant directement \nl'événement à l'adresse suivante:" signature: "Avec tous nos remerciements pour votre contribution,\n\n-- \nL'équipe des modérateurs de l'Agenda du Libre" + create: + subject: "[Agenda du Libre] Une note a été rajoutée à l'événement '%{subject}'" + title: Bonjour, + body: "Une note a été rajoutée à '%{subject}':" + signature: "-- \nL'équipe de modération" diff --git a/test/mailers/note_mailer_test.rb b/test/mailers/note_mailer_test.rb index 2dbb769a..196572c6 100644 --- a/test/mailers/note_mailer_test.rb +++ b/test/mailers/note_mailer_test.rb @@ -5,10 +5,17 @@ class NoteMailerTest < ActionMailer::TestCase ActionMailer::Base.default_url_options[:host] = 'localhost:3000' end - test 'create' do - mail = NoteMailer.create Note.last + test 'notify' do + mail = NoteMailer.notify Note.last assert_match(/\[Agenda du Libre\] Demande d'informations sur l'événement .*/, mail.subject) assert_equal [Note.last.event.contact], mail.to assert_equal ["moderateurs@agendadulibre.org"], mail.from end + + test 'create' do + mail = NoteMailer.create Note.last + assert_match(/\[Agenda du Libre\] Une note a été rajoutée à l'événement .*/, mail.subject) + assert_not_equal [Note.last.event.contact], mail.to + assert_equal ["moderateurs@agendadulibre.org"], mail.from + end end diff --git a/test/mailers/previews/note_mailer_preview.rb b/test/mailers/previews/note_mailer_preview.rb index 63543b9e..997a7739 100644 --- a/test/mailers/previews/note_mailer_preview.rb +++ b/test/mailers/previews/note_mailer_preview.rb @@ -1,5 +1,11 @@ # Preview all emails at http://localhost:3000/rails/mailers/note_mailer class NoteMailerPreview < ActionMailer::Preview + # Preview this email at http://localhost:3000/rails/mailers/note_mailer/notify + def notify + ActionMailer::Base.default_url_options[:host] = 'localhost:3000' + NoteMailer.notify Note.last + end + # Preview this email at http://localhost:3000/rails/mailers/note_mailer/create def create ActionMailer::Base.default_url_options[:host] = 'localhost:3000'