Mail d'envoi de demande d'information

This commit is contained in:
echarp 2014-06-23 23:39:42 +02:00
parent c7a6f04489
commit 5e5a60c29a
14 changed files with 111 additions and 34 deletions

View File

@ -100,10 +100,6 @@ class EventsController < ApplicationController
end end
private private
def permitted_params
params.require(:event).permit(:title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags)
end
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.
def set_event def set_event
if (params[:secret].present?) if (params[:secret].present?)

View File

@ -1,12 +1,12 @@
require 'differ' require 'differ'
class ModerationsController < InheritedResources::Base class ModerationsController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
before_action :set_event, only: [:show, :edit, :update, :destroy] before_action :set_event, only: [:show, :edit, :update, :destroy]
before_filter :set_mailer_host, only: [:update, :destroy] before_filter :set_mailer_host, only: [:update, :destroy]
def index def index
@events = Event.unscoped.where moderated: 0 @events = Event.where moderated: 0
end end
# PATCH/PUT /moderations/1 # PATCH/PUT /moderations/1
@ -37,12 +37,12 @@ class ModerationsController < InheritedResources::Base
private private
def permitted_params def permitted_params
params.permit event: [:title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags] params.require(:event).permit(:title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags)
end end
# Use callbacks to share common setup or constraints between actions. # Use callbacks to share common setup or constraints between actions.
def set_event def set_event
@event = Event.unscoped.find params[:id] @event = Event.find params[:id]
@moderation = @event @moderation = @event
end end

View File

@ -1,22 +1,46 @@
class NotesController < InheritedResources::Base class NotesController < ApplicationController
belongs_to :moderation before_action :set_event, only: [:new, :create]
before_filter :set_mailer_host, only: [:create]
# GET /moderations/id/new
def new
@note = @moderation.notes.new
end
def create def create
create! do |format| @note = @moderation.notes.new(note_params)
format.html {
@note.author = current_user @note.author = current_user
create!(notice: t(:added, scope: [:notes, :actions])) { moderations_url }
} respond_to do |format|
if @note.save
if (params[:envoiParMail] == 'oui')
# Send an update mail to its author
NoteMailer.create(@note).deliver
end
format.html { redirect_to moderations_url, notice: t('.ok') }
format.json { render action: 'show', status: :created, location: @event }
else
format.html { render action: 'new' }
format.json { render json: @note.errors, status: :unprocessable_entity }
end
end end
end end
private private
def begin_of_association_chain # Use callbacks to share common setup or constraints between actions.
@moderation = Event.unscoped.find params[:moderation_id] def set_event
@event = @moderation @event = Event.find params[:moderation_id]
@moderation = @event
end end
def permitted_params # Never trust parameters from the scary internet, only allow the white list through.
params.permit note: [:contents] def note_params
params.require(:note).permit :contents
end
# Useful to manage absolute url in mails
def set_mailer_host
ActionMailer::Base.default_url_options[:host] = request.host_with_port
end end
end end

View File

@ -3,6 +3,6 @@ class EventMailer < ActionMailer::Base
def create(event) def create(event)
@event = event @event = event
mail to: "to@example.org", subject: t('event_mailer.create.subject', subject: event.title) mail to: event.contact, subject: t('event_mailer.create.subject', subject: event.title)
end end
end end

View File

@ -1,5 +1,6 @@
class ModerationMailer < ActionMailer::Base class ModerationMailer < ActionMailer::Base
default from: 'moderateurs@agendadulibre.org' default from: 'moderateurs@agendadulibre.org'
TO = 'moderateurs@agendadulibre.org'
# Subject can be set in your I18n file at config/locales/en.yml # Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup: # with the following lookup:
@ -9,7 +10,7 @@ class ModerationMailer < ActionMailer::Base
def create(event) def create(event)
@event = event @event = event
mail to: "to@example.org", subject: t('moderation_mailer.create.subject', subject: event.title) mail to: TO, subject: t('moderation_mailer.create.subject', subject: event.title)
end end
# Subject can be set in your I18n file at config/locales/en.yml # Subject can be set in your I18n file at config/locales/en.yml
@ -21,7 +22,7 @@ class ModerationMailer < ActionMailer::Base
@event = event @event = event
@current_user = current_user @current_user = current_user
mail to: "to@example.org", subject: t('moderation_mailer.update.subject', subject: event.title) mail to: TO, subject: t('moderation_mailer.update.subject', subject: event.title)
end end
# Subject can be set in your I18n file at config/locales/en.yml # Subject can be set in your I18n file at config/locales/en.yml
@ -33,6 +34,6 @@ class ModerationMailer < ActionMailer::Base
@event = event @event = event
@current_user = current_user @current_user = current_user
mail to: "to@example.org", subject: t('moderation_mailer.moderate.subject', subject: event.title) mail to: TO, subject: t('moderation_mailer.moderate.subject', subject: event.title)
end end
end end

View File

@ -0,0 +1,9 @@
class NoteMailer < ActionMailer::Base
default from: 'moderateurs@agendadulibre.org'
def create(note)
@note = note
mail to: note.event.contact, subject: t('note_mailer.create.subject', subject: note.event.title)
end
end

View File

@ -38,7 +38,7 @@
\- \-
= link_to t('refuse'), edit_moderation_path(event), class: 'fa-thumbs-down' = link_to t('refuse'), edit_moderation_path(event), class: 'fa-thumbs-down'
%br/ %br/
= link_to t('.askInfos'), edit_moderation_path(event), class: 'fa-bullhorn' = link_to t('.askInfos'), new_moderation_note_path(event, envoiParMail: :oui), class: 'fa-bullhorn'
%br/ %br/
= link_to t('.createNote'), new_moderation_note_path(event), class: 'fa-files-o' = link_to t('.createNote'), new_moderation_note_path(event), class: 'fa-files-o'

View File

@ -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_moderation_url @note.event
\
=t '.signature'

View File

@ -1,4 +1,5 @@
= form_for [:moderation, @note] do |f| = form_for [:moderation, @note] do |f|
= hidden_field_tag :envoiParMail, params[:envoiParMail]
- if @note.errors.any? - if @note.errors.any?
#error_explanation #error_explanation
%h2= "#{pluralize(@note.errors.count, "error")} prohibited this note from being saved:" %h2= "#{pluralize(@note.errors.count, "error")} prohibited this note from being saved:"

View File

@ -178,8 +178,8 @@ fr:
new: new:
back: Modération back: Modération
title: Ajout d'une note de modération title: Ajout d'une note de modération
actions: create:
added: La note a bien été ajoutée, merci! ok: La note a bien été ajoutée, merci!
maps: maps:
index: index:
title: Carte des évènements title: Carte des évènements
@ -220,3 +220,14 @@ fr:
title: Bonjour, title: Bonjour,
body: L'évènement a été modéré par %{author} body: L'évènement a été modéré par %{author}
signature: "-- \nL'équipe de modération" signature: "-- \nL'équipe de modération"
note_mailer:
create:
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}',
\net celui-ci a toute sa place dans l'Agenda du Libre. Néanmoins, avant
\nd'être validé, nous avons besoin de quelques informations
\ncomplémentaires sur cet évènement:"
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"

View File

@ -8,7 +8,7 @@ class EventMailerTest < ActionMailer::TestCase
test "create" do test "create" do
mail = EventMailer.create(Event.last) mail = EventMailer.create(Event.last)
assert_match(/\[Agenda du Libre\] Votre évènement: .* est en attente de modération/, mail.subject) assert_match(/\[Agenda du Libre\] Votre évènement: .* est en attente de modération/, mail.subject)
assert_equal ["to@example.org"], mail.to assert_equal [Event.last.contact], mail.to
assert_equal ["moderateurs@agendadulibre.org"], mail.from assert_equal ["moderateurs@agendadulibre.org"], mail.from
assert_match(/Bonjour.*/, mail.body.encoded) assert_match(/Bonjour.*/, mail.body.encoded)
end end

View File

@ -6,23 +6,23 @@ class ModerationMailerTest < ActionMailer::TestCase
end end
test "create" do test "create" do
mail = ModerationMailer.create(Event.last) mail = ModerationMailer.create(Event.unscoped.last)
assert_match(/\[Agenda du Libre\] Nouvel évènement à modérer: .*/, mail.subject) assert_match(/\[Agenda du Libre\] Nouvel évènement à modérer: .*/, mail.subject)
assert_equal ["to@example.org"], mail.to assert_equal ["moderateurs@agendadulibre.org"], mail.to
assert_equal ["moderateurs@agendadulibre.org"], mail.from assert_equal ["moderateurs@agendadulibre.org"], mail.from
end end
test "update" do test "update" do
mail = ModerationMailer.update(Event.last, User.last) mail = ModerationMailer.update(Event.unscoped.last, User.last)
assert_match(/\[Agenda du Libre\] Édition de l'évènement .*/, mail.subject) assert_match(/\[Agenda du Libre\] Édition de l'évènement .*/, mail.subject)
assert_equal ["to@example.org"], mail.to assert_equal ["moderateurs@agendadulibre.org"], mail.to
assert_equal ["moderateurs@agendadulibre.org"], mail.from assert_equal ["moderateurs@agendadulibre.org"], mail.from
end end
test "moderate" do test "moderate" do
mail = ModerationMailer.moderate(Event.last, User.last) mail = ModerationMailer.moderate(Event.unscoped.last, User.last)
assert_match(/\[Agenda du Libre\] Évènement .* modéré/, mail.subject) assert_match(/\[Agenda du Libre\] Évènement .* modéré/, mail.subject)
assert_equal ["to@example.org"], mail.to assert_equal ["moderateurs@agendadulibre.org"], mail.to
assert_equal ["moderateurs@agendadulibre.org"], mail.from assert_equal ["moderateurs@agendadulibre.org"], mail.from
end end
end end

View File

@ -0,0 +1,14 @@
require 'test_helper'
class NoteMailerTest < ActionMailer::TestCase
setup do
ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
end
test "create" do
mail = NoteMailer.create(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
end

View File

@ -0,0 +1,8 @@
# 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/create
def create
ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
NoteMailer.create(Note.last)
end
end