Mail d'envoi de demande d'information
This commit is contained in:
parent
c7a6f04489
commit
5e5a60c29a
@ -100,10 +100,6 @@ class EventsController < ApplicationController
|
||||
end
|
||||
|
||||
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.
|
||||
def set_event
|
||||
if (params[:secret].present?)
|
||||
|
@ -1,12 +1,12 @@
|
||||
require 'differ'
|
||||
|
||||
class ModerationsController < InheritedResources::Base
|
||||
class ModerationsController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
before_action :set_event, only: [:show, :edit, :update, :destroy]
|
||||
before_filter :set_mailer_host, only: [:update, :destroy]
|
||||
|
||||
def index
|
||||
@events = Event.unscoped.where moderated: 0
|
||||
@events = Event.where moderated: 0
|
||||
end
|
||||
|
||||
# PATCH/PUT /moderations/1
|
||||
@ -37,12 +37,12 @@ class ModerationsController < InheritedResources::Base
|
||||
|
||||
private
|
||||
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
|
||||
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_event
|
||||
@event = Event.unscoped.find params[:id]
|
||||
@event = Event.find params[:id]
|
||||
@moderation = @event
|
||||
end
|
||||
|
||||
|
@ -1,22 +1,46 @@
|
||||
class NotesController < InheritedResources::Base
|
||||
belongs_to :moderation
|
||||
class NotesController < ApplicationController
|
||||
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
|
||||
create! do |format|
|
||||
format.html {
|
||||
@note = @moderation.notes.new(note_params)
|
||||
@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
|
||||
|
||||
private
|
||||
def begin_of_association_chain
|
||||
@moderation = Event.unscoped.find params[:moderation_id]
|
||||
@event = @moderation
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_event
|
||||
@event = Event.find params[:moderation_id]
|
||||
@moderation = @event
|
||||
end
|
||||
|
||||
def permitted_params
|
||||
params.permit note: [:contents]
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
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
|
||||
|
@ -3,6 +3,6 @@ class EventMailer < ActionMailer::Base
|
||||
|
||||
def create(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
|
||||
|
@ -1,5 +1,6 @@
|
||||
class ModerationMailer < ActionMailer::Base
|
||||
default from: 'moderateurs@agendadulibre.org'
|
||||
TO = 'moderateurs@agendadulibre.org'
|
||||
|
||||
# Subject can be set in your I18n file at config/locales/en.yml
|
||||
# with the following lookup:
|
||||
@ -9,7 +10,7 @@ class ModerationMailer < ActionMailer::Base
|
||||
def create(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
|
||||
|
||||
# Subject can be set in your I18n file at config/locales/en.yml
|
||||
@ -21,7 +22,7 @@ class ModerationMailer < ActionMailer::Base
|
||||
@event = event
|
||||
@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
|
||||
|
||||
# Subject can be set in your I18n file at config/locales/en.yml
|
||||
@ -33,6 +34,6 @@ class ModerationMailer < ActionMailer::Base
|
||||
@event = event
|
||||
@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
|
||||
|
9
app/mailers/note_mailer.rb
Normal file
9
app/mailers/note_mailer.rb
Normal 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
|
@ -38,7 +38,7 @@
|
||||
\-
|
||||
= link_to t('refuse'), edit_moderation_path(event), class: 'fa-thumbs-down'
|
||||
%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/
|
||||
= link_to t('.createNote'), new_moderation_note_path(event), class: 'fa-files-o'
|
||||
|
||||
|
13
app/views/note_mailer/create.text.haml
Normal file
13
app/views/note_mailer/create.text.haml
Normal 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'
|
@ -1,4 +1,5 @@
|
||||
= form_for [:moderation, @note] do |f|
|
||||
= hidden_field_tag :envoiParMail, params[:envoiParMail]
|
||||
- if @note.errors.any?
|
||||
#error_explanation
|
||||
%h2= "#{pluralize(@note.errors.count, "error")} prohibited this note from being saved:"
|
||||
|
@ -178,8 +178,8 @@ fr:
|
||||
new:
|
||||
back: Modération
|
||||
title: Ajout d'une note de modération
|
||||
actions:
|
||||
added: La note a bien été ajoutée, merci!
|
||||
create:
|
||||
ok: La note a bien été ajoutée, merci!
|
||||
maps:
|
||||
index:
|
||||
title: Carte des évènements
|
||||
@ -220,3 +220,14 @@ fr:
|
||||
title: Bonjour,
|
||||
body: L'évènement a été modéré par %{author}
|
||||
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"
|
||||
|
@ -8,7 +8,7 @@ class EventMailerTest < ActionMailer::TestCase
|
||||
test "create" do
|
||||
mail = EventMailer.create(Event.last)
|
||||
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_match(/Bonjour.*/, mail.body.encoded)
|
||||
end
|
||||
|
@ -6,23 +6,23 @@ class ModerationMailerTest < ActionMailer::TestCase
|
||||
end
|
||||
|
||||
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_equal ["to@example.org"], mail.to
|
||||
assert_equal ["moderateurs@agendadulibre.org"], mail.to
|
||||
assert_equal ["moderateurs@agendadulibre.org"], mail.from
|
||||
end
|
||||
|
||||
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_equal ["to@example.org"], mail.to
|
||||
assert_equal ["moderateurs@agendadulibre.org"], mail.to
|
||||
assert_equal ["moderateurs@agendadulibre.org"], mail.from
|
||||
end
|
||||
|
||||
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_equal ["to@example.org"], mail.to
|
||||
assert_equal ["moderateurs@agendadulibre.org"], mail.to
|
||||
assert_equal ["moderateurs@agendadulibre.org"], mail.from
|
||||
end
|
||||
end
|
||||
|
14
test/mailers/note_mailer_test.rb
Normal file
14
test/mailers/note_mailer_test.rb
Normal 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
|
8
test/mailers/previews/note_mailer_preview.rb
Normal file
8
test/mailers/previews/note_mailer_preview.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user