Envoi de mail pour chaque création d'événement
This commit is contained in:
parent
0bbfe114be
commit
b13af2ea6a
|
@ -94,11 +94,20 @@ main
|
||||||
hr
|
hr
|
||||||
margin: 10px 20px
|
margin: 10px 20px
|
||||||
|
|
||||||
input, textarea, select
|
input, textarea, select, a.button
|
||||||
margin: 3px 0
|
margin: 3px 0
|
||||||
border: 1px solid #868686
|
border: 1px solid #868686
|
||||||
&:focus
|
&:focus
|
||||||
background-color: #F0F8FF
|
background-color: #F0F8FF
|
||||||
|
&[type=submit], &.button
|
||||||
|
color: black
|
||||||
|
padding: 0.2em 0.6em
|
||||||
|
font-size: larger
|
||||||
|
line-height: 1.1em
|
||||||
|
font-weight: normal
|
||||||
|
vertical-align: baseline
|
||||||
|
background-color: buttonface
|
||||||
|
|
||||||
/*
|
/*
|
||||||
input, textarea, select
|
input, textarea, select
|
||||||
color: black
|
color: black
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
.moderations, .notes
|
.events.edit, .events.update, .events.cancel, .moderations, .notes
|
||||||
table.list
|
table.list
|
||||||
width: 100%
|
width: 100%
|
||||||
margin-top: 15px
|
margin-top: 15px
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
class EventsController < InheritedResources::Base
|
class EventsController < InheritedResources::Base
|
||||||
before_action :set_event, only: [:show, :edit, :update, :destroy]
|
before_action :set_event, only: [:show, :edit, :update, :cancel, :destroy]
|
||||||
|
before_action :check_secret, only: [:edit, :update, :cancel, :destroy]
|
||||||
|
before_filter :set_mailer_host
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@events = Event
|
@events = Event
|
||||||
|
@ -43,6 +45,9 @@ class EventsController < InheritedResources::Base
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @event.save
|
if @event.save
|
||||||
|
# Send an event creation mail to its author
|
||||||
|
EventMailer.create(@event).deliver
|
||||||
|
|
||||||
format.html { redirect_to @event, notice: 'Event was successfully created.' }
|
format.html { redirect_to @event, notice: 'Event was successfully created.' }
|
||||||
format.json { render action: 'show', status: :created, location: @event }
|
format.json { render action: 'show', status: :created, location: @event }
|
||||||
else
|
else
|
||||||
|
@ -55,15 +60,16 @@ class EventsController < InheritedResources::Base
|
||||||
# PATCH/PUT /events/1
|
# PATCH/PUT /events/1
|
||||||
# PATCH/PUT /events/1.json
|
# PATCH/PUT /events/1.json
|
||||||
def update
|
def update
|
||||||
|
# This is a special case, required to handle the region attribute with same foreign key name
|
||||||
|
@event.region = Region.find(params[:event][:region])
|
||||||
|
|
||||||
if params[:visu]
|
if params[:visu]
|
||||||
@event.attributes = params[:event]
|
@event.attributes = event_params
|
||||||
render action: :edit
|
render action: :edit
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
# This is a special case, required to handle the region attribute with same foreign key name
|
|
||||||
@event.region = Region.find(params[:event][:region])
|
|
||||||
if @event.update(event_params)
|
if @event.update(event_params)
|
||||||
format.html { redirect_to @event, notice: 'Event was successfully updated.' }
|
format.html { redirect_to @event, notice: 'Event was successfully updated.' }
|
||||||
format.json { head :no_content }
|
format.json { head :no_content }
|
||||||
|
@ -81,7 +87,11 @@ class EventsController < InheritedResources::Base
|
||||||
|
|
||||||
# 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.find(params[:id])
|
if (params[:secret].present?)
|
||||||
|
@event = Event.unscoped.where(secret: params[:secret]).find(params[:id])
|
||||||
|
else
|
||||||
|
@event = Event.find(params[:id])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
|
@ -89,4 +99,15 @@ class EventsController < InheritedResources::Base
|
||||||
params.require(:event)
|
params.require(:event)
|
||||||
.permit :title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags
|
.permit :title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_secret
|
||||||
|
if (params[:secret] != @event.secret)
|
||||||
|
redirect_to @event, notice: t(:forbidden, scope: [:events, :edit])
|
||||||
|
end
|
||||||
|
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
|
||||||
|
|
|
@ -9,6 +9,9 @@ class ModerationsController < InheritedResources::Base
|
||||||
# PATCH/PUT /moderations/1
|
# PATCH/PUT /moderations/1
|
||||||
# PATCH/PUT /moderations/1.json
|
# PATCH/PUT /moderations/1.json
|
||||||
def update
|
def update
|
||||||
|
# This is a special case, required to handle the region attribute with same foreign key name
|
||||||
|
@event.region = Region.find(params[:event][:region])
|
||||||
|
|
||||||
if params[:visu]
|
if params[:visu]
|
||||||
@event.attributes = event_params
|
@event.attributes = event_params
|
||||||
render action: 'edit'
|
render action: 'edit'
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
class EventMailer < ActionMailer::Base
|
||||||
|
default from: 'moderateurs@agendadulibre.org'
|
||||||
|
|
||||||
|
# Subject can be set in your I18n file at config/locales/en.yml
|
||||||
|
# with the following lookup:
|
||||||
|
#
|
||||||
|
# en.event_mailer.create.subject
|
||||||
|
#
|
||||||
|
def create(event)
|
||||||
|
@event = event
|
||||||
|
mail to: "to@example.org", subject: t('event_mailer.create.subject', subject: event.title)
|
||||||
|
end
|
||||||
|
end
|
|
@ -30,6 +30,12 @@ class Event < ActiveRecord::Base
|
||||||
self.decision_time = Date.today
|
self.decision_time = Date.today
|
||||||
end
|
end
|
||||||
|
|
||||||
|
before_create do
|
||||||
|
self.secret = SecureRandom.urlsafe_base64(32)[0...32]
|
||||||
|
self.moderator_mail_id = SecureRandom.urlsafe_base64(32)[0...32]
|
||||||
|
self.submitter_mail_id = SecureRandom.urlsafe_base64(32)[0...32]
|
||||||
|
end
|
||||||
|
|
||||||
def same_day?
|
def same_day?
|
||||||
start_time.to_date == end_time.to_date
|
start_time.to_date == end_time.to_date
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
=t '.title'
|
||||||
|
|
||||||
|
\
|
||||||
|
|
||||||
|
=t '.body', subject: @event.title, start_time: l(@event.start_time, format: :at)
|
||||||
|
|
||||||
|
\
|
||||||
|
|
||||||
|
= edit_event_url @event, secret: @event.secret
|
||||||
|
|
||||||
|
\
|
||||||
|
|
||||||
|
=t '.delete_link'
|
||||||
|
|
||||||
|
\
|
||||||
|
|
||||||
|
= cancel_event_url @event, secret: @event.secret
|
||||||
|
|
||||||
|
\
|
||||||
|
|
||||||
|
=t '.signature'
|
|
@ -13,6 +13,9 @@
|
||||||
|
|
||||||
#advises= raw markdown.render t '.advises'
|
#advises= raw markdown.render t '.advises'
|
||||||
|
|
||||||
|
- else
|
||||||
|
= hidden_field_tag :secret, params[:secret]
|
||||||
|
|
||||||
.field
|
.field
|
||||||
.helper= raw markdown.render t '.title_helper'
|
.helper= raw markdown.render t '.title_helper'
|
||||||
= f.label :title
|
= f.label :title
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
%h3
|
||||||
|
>>>
|
||||||
|
=t '.title'
|
||||||
|
|
||||||
|
.box
|
||||||
|
- if @event.moderated
|
||||||
|
%h3=t '.already_moderated'
|
||||||
|
|
||||||
|
= form_for @event, method: :delete do |f|
|
||||||
|
= hidden_field_tag :secret, params[:secret]
|
||||||
|
.confirm=t '.confirm'
|
||||||
|
%br/
|
||||||
|
|
||||||
|
= f.submit t('.ok'), name: :yes
|
||||||
|
= link_to t('.ko'), @event, class: :button
|
||||||
|
|
||||||
|
%h3
|
||||||
|
>>>
|
||||||
|
=t '.preview'
|
||||||
|
|
||||||
|
.box= render file: '/events/show'
|
|
@ -1,5 +1,15 @@
|
||||||
%h2=t '.title'
|
%h3
|
||||||
|
>>>
|
||||||
|
=t '.preview'
|
||||||
|
|
||||||
= render 'form'
|
.box
|
||||||
|
%h3=t '.warning'
|
||||||
|
|
||||||
= link_to 'Show', @event
|
.box= render file: '/events/show'
|
||||||
|
|
||||||
|
%h3
|
||||||
|
= link_to t('.moderation'), moderations_path
|
||||||
|
>>>
|
||||||
|
=t '.edit'
|
||||||
|
|
||||||
|
.box= render '/events/form'
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
- if request.format == 'text/html' && controller.controller_name != 'moderations' && controller.controller_name != 'notes'
|
- if request.format == 'text/html' && controller.controller_name != 'moderations' && controller.controller_name != 'notes'
|
||||||
%p#notice= notice
|
|
||||||
|
|
||||||
#lug-list
|
#lug-list
|
||||||
%h1=t '.lug-list'
|
%h1=t '.lug-list'
|
||||||
- if @event.region
|
- if @event.region
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
%p#notice= notice
|
|
||||||
|
|
||||||
%p
|
%p
|
||||||
%b Login:
|
%b Login:
|
||||||
= @user.login
|
= @user.login
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
# config/initializers/override_mail_recipient.rb
|
||||||
|
if Rails.env.development?
|
||||||
|
class OverrideMailRecipient
|
||||||
|
def self.delivering_email(mail)
|
||||||
|
mail.to = 'manu@localhost'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
ActionMailer::Base.register_interceptor(OverrideMailRecipient)
|
||||||
|
end
|
|
@ -116,9 +116,20 @@ fr:
|
||||||
title: Soumettre un évènement
|
title: Soumettre un évènement
|
||||||
edit:
|
edit:
|
||||||
title: Éditer un évènement
|
title: Éditer un évènement
|
||||||
|
preview: Prévisualisation de l'évènement
|
||||||
|
warning: Attention, cet évènement est déjà modéré. Toute modification sera immédiatement visible sur le site.
|
||||||
|
forbidden: Vous n'êtes pas authorisé à modifier cet événement
|
||||||
|
edit: Édition de l'évènement
|
||||||
form:
|
form:
|
||||||
save: Valider
|
save: Valider
|
||||||
visualise: Visualiser
|
visualise: Visualiser
|
||||||
|
cancel:
|
||||||
|
title: Annulation de l'événement
|
||||||
|
already_moderated: Attention, cet évènement est déjà modéré. Cette annulation le fera disparaître de l'Agenda du Libre.
|
||||||
|
confirm: Confirmez-vous l'annulation de cet évènement?
|
||||||
|
preview: Visualisation de l'évènement
|
||||||
|
ok: Oui
|
||||||
|
ko: Non
|
||||||
regions:
|
regions:
|
||||||
index:
|
index:
|
||||||
title: Liste des flux RSS
|
title: Liste des flux RSS
|
||||||
|
@ -180,3 +191,17 @@ fr:
|
||||||
new:
|
new:
|
||||||
title: Identification
|
title: Identification
|
||||||
sign_in: Identifier
|
sign_in: Identifier
|
||||||
|
event_mailer:
|
||||||
|
create:
|
||||||
|
title: Nouvel événement
|
||||||
|
|
||||||
|
event_mailer:
|
||||||
|
create:
|
||||||
|
subject: "[Agenda du Libre] Votre évènement: '%{subject}' est en attente de modération"
|
||||||
|
title: Bonjour,
|
||||||
|
body: "Votre évènement intitulé '%{subject}',
|
||||||
|
\nqui aura lieu le '%{start_time}' a bien été enregistré dans l'Agenda du Libre.
|
||||||
|
\n\nL'équipe de modération le prendra en charge très prochainement.
|
||||||
|
\n\nPendant la modération et après celle-ci si votre évènement est validé, vous pouvez éditer votre évènement à l'adresse:"
|
||||||
|
delete_link: "et vous pouvez l'annuler en utilisant l'adresse:"
|
||||||
|
signature: "Merci de votre participation!\n\n-- \nAgenda du Libre"
|
||||||
|
|
|
@ -7,7 +7,9 @@ Rails.application.routes.draw do
|
||||||
get 'application/contact'
|
get 'application/contact'
|
||||||
|
|
||||||
resources :users
|
resources :users
|
||||||
resources :events
|
resources :events do
|
||||||
|
get :cancel, on: :member
|
||||||
|
end
|
||||||
resources :moderations do
|
resources :moderations do
|
||||||
resources :notes, only: [:new, :create]
|
resources :notes, only: [:new, :create]
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,12 +64,17 @@ class EventsControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get edit" do
|
test "should get edit" do
|
||||||
get :edit, id: @event
|
get :edit, id: @event, secret: 'MyString'
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should not get edit" do
|
||||||
|
get :edit, id: @event
|
||||||
|
assert_redirected_to event_path(assigns(:event))
|
||||||
|
end
|
||||||
|
|
||||||
test "should update event" do
|
test "should update event" do
|
||||||
patch :update, id: @event, event: {
|
patch :update, id: @event, secret: 'MyString', event: {
|
||||||
title: @event.title,
|
title: @event.title,
|
||||||
start_time: @event.start_time,
|
start_time: @event.start_time,
|
||||||
end_time: @event.end_time,
|
end_time: @event.end_time,
|
||||||
|
@ -89,9 +94,14 @@ class EventsControllerTest < ActionController::TestCase
|
||||||
assert_redirected_to event_path(assigns(:event))
|
assert_redirected_to event_path(assigns(:event))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "should get cancel page" do
|
||||||
|
get :cancel, id: @event, secret: 'MyString'
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
test "should destroy event" do
|
test "should destroy event" do
|
||||||
assert_difference('Event.count', -1) do
|
assert_difference('Event.count', -1) do
|
||||||
delete :destroy, id: @event
|
delete :destroy, id: @event, secret: 'MyString'
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_redirected_to events_path
|
assert_redirected_to events_path
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class EventMailerTest < ActionMailer::TestCase
|
||||||
|
setup do
|
||||||
|
ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
|
||||||
|
end
|
||||||
|
|
||||||
|
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 ["moderateurs@agendadulibre.org"], mail.from
|
||||||
|
assert_match(/Bonjour.*/, mail.body.encoded)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,10 @@
|
||||||
|
# Preview all emails at http://localhost:3000/rails/mailers/event_mailer
|
||||||
|
class EventMailerPreview < ActionMailer::Preview
|
||||||
|
|
||||||
|
# Preview this email at http://localhost:3000/rails/mailers/event_mailer/create
|
||||||
|
def create
|
||||||
|
ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
|
||||||
|
EventMailer.create(Event.last)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -1,7 +1,19 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class EventTest < ActiveSupport::TestCase
|
class EventTest < ActiveSupport::TestCase
|
||||||
# test "the truth" do
|
test "basic event" do
|
||||||
# assert true
|
@event = Event.new(
|
||||||
# end
|
title: 'hello world',
|
||||||
|
start_time: Time.new(),
|
||||||
|
end_time: Time.new() + 1,
|
||||||
|
description: 'et hop!',
|
||||||
|
region: Region.first()
|
||||||
|
)
|
||||||
|
assert @event.save()
|
||||||
|
|
||||||
|
assert_equal 32, @event.secret.size()
|
||||||
|
assert_equal 32, @event.moderator_mail_id.size()
|
||||||
|
assert_equal 32, @event.submitter_mail_id.size()
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue