Mails pour la modération

This commit is contained in:
echarp 2014-06-09 12:18:40 +02:00
parent 6a786a16c1
commit dfe1934c90
15 changed files with 171 additions and 28 deletions

View File

@ -60,6 +60,8 @@ gem 'i18n-active_record',
require: 'i18n/active_record'
gem 'font-awesome-rails'
gem 'email_validator'
# To display a patched diff for event descriptions
gem 'differ'
gem 'simple_calendar', github: 'echarp/simple_calendar'
#gem 'simple_calendar', github: 'excid3/simple_calendar', branch: '1.0'

View File

@ -7,7 +7,7 @@ GIT
GIT
remote: git://github.com/gregbell/active_admin.git
revision: 021843bd48627d19ab63a2f08c6d7f12b62c3714
revision: 3d7605f82706c8e107852f44c61ba6d8e9f2100d
specs:
activeadmin (1.0.0.pre)
arbre (~> 1.0)
@ -91,6 +91,7 @@ GEM
thread_safe (~> 0.1)
warden (~> 1.2.3)
devise-i18n (0.10.3)
differ (0.1.2)
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
@ -136,9 +137,9 @@ GEM
hike (1.2.3)
http_parser.rb (0.6.0)
i18n (0.6.9)
inherited_resources (1.4.1)
inherited_resources (1.5.0)
has_scope (~> 0.6.0.rc)
responders (~> 1.0.0.rc)
responders (~> 1.0)
jbuilder (2.0.7)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
@ -154,7 +155,7 @@ GEM
kaminari (0.15.1)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
listen (2.7.5)
listen (2.7.6)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
@ -214,7 +215,7 @@ GEM
rdoc (4.1.1)
json (~> 1.4)
redcarpet (3.1.2)
responders (1.0.0)
responders (1.1.0)
railties (>= 3.2, < 5)
sass (3.2.19)
sass-rails (4.0.3)
@ -245,7 +246,7 @@ GEM
polyglot (>= 0.3.1)
turbolinks (2.2.2)
coffee-rails
tzinfo (1.2.0)
tzinfo (1.2.1)
thread_safe (~> 0.1)
uglifier (2.5.0)
execjs (>= 0.3.0)
@ -263,6 +264,7 @@ DEPENDENCIES
compass-rails
devise
devise-i18n
differ
email_validator
font-awesome-rails
gritter

View File

@ -1,6 +1,9 @@
require 'differ'
class ModerationsController < InheritedResources::Base
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
@ -45,4 +48,9 @@ class ModerationsController < InheritedResources::Base
params.require(:event)
.permit :title, :start_time, :end_time, :description, :city, :locality, :url, :contact, :submitter, :tags
end
# Useful to manage absolute url in mails
def set_mailer_host
ActionMailer::Base.default_url_options[:host] = request.host_with_port
end
end

View File

@ -1,11 +1,6 @@
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)

View File

@ -0,0 +1,38 @@
class ModerationMailer < 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.moderation_mailer.create.subject
#
def create(event)
@event = event
mail to: "to@example.org", subject: t('moderation_mailer.create.subject', subject: event.title)
end
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.moderation_mailer.update.subject
#
def update(event, current_user)
@event = event
@current_user = current_user
mail to: "to@example.org", subject: t('moderation_mailer.update.subject', subject: event.title)
end
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.moderation_mailer.moderate.subject
#
def moderate(event, current_user)
@event = event
@current_user = current_user
mail to: "to@example.org", subject: t('moderation_mailer.moderate.subject', subject: event.title)
end
end

View File

@ -18,7 +18,7 @@ class Event < ActiveRecord::Base
.order(:start_time)
}
scope :year, -> year {
where "end_time >= ? and start_time < ?",
where 'end_time >= ? and start_time < ?',
"#{year}-1-1", "#{year.to_i+1}-1-1"
}
scope :month, -> year, month {

View File

@ -2,4 +2,8 @@ class Region < ActiveRecord::Base
has_many :lugs, foreign_key: :region
default_scope { order :name }
def to_s
name
end
end

View File

@ -29,6 +29,10 @@ class User < ActiveRecord::Base
encrypted_password == password_digest(password)
end
def to_s
"#{firstname} #{lastname}"
end
protected
def password_digest(password)
Digest::MD5.hexdigest password

View File

@ -1,21 +1,9 @@
=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'

View File

@ -0,0 +1,17 @@
=t '.title'
\
=t '.body', subject: @event.title, start_time: l(@event.start_time, format: :at)
= edit_moderation_url @event
\
#{Event.human_attribute_name(:title)}: #{@event.title}
#{Event.human_attribute_name(:start_time)}: #{l @event.start_time, format: :at}
#{Event.human_attribute_name(:end_time)}: #{l @event.end_time, format: :at}
#{Event.human_attribute_name(:region)}: #{@event.region}
#{Event.human_attribute_name(:city)}: #{@event.city}
#{Event.human_attribute_name(:url)}: #{@event.url}
#{Event.human_attribute_name(:contact)}: #{@event.contact}
#{Event.human_attribute_name(:submitter)}: #{@event.submitter}
#{Event.human_attribute_name(:tags)}: #{@event.tags}
#{Event.human_attribute_name(:description)}: #{raw @event.description}
\
=t '.signature'

View File

@ -0,0 +1,7 @@
=t '.title'
\
=t '.body', author: @current_user
\
=====================================================
\
=t '.signature'

View File

@ -0,0 +1,13 @@
=t '.title'
\
=t '.body', subject: @event.title, author: @current_user
- Differ.format = :ascii
= raw Differ.diff(@event.description, @event.description_was).to_s |
.gsub(/\[31m/, '') |
.gsub(/\[32m/, '') |
.gsub(/\[0m/, '') |
\
= edit_moderation_url @event
\
=t '.signature'

View File

@ -191,10 +191,6 @@ fr:
new:
title: Identification
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"
@ -205,3 +201,19 @@ fr:
\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"
moderation_mailer:
create:
subject: "[Agenda du Libre] Nouvel évènement à modérer: '%{subject}'"
title: Bonjour,
body: Un nouvel évènement est à modérer sur
signature: "Merci!\n\n-- \nAgenda du Libre"
update:
subject: "[Agenda du Libre] Édition de l'évènement '%{subject}'"
title: Bonjour,
body: "L'évènement '%{subject}' a été modifié par\n%{author}\n\nModifications apportées:"
signature: "Bonne journée\n\n-- \nL'équipe de modération"
moderate:
subject: "[Agenda du Libre] Évènement '%{subject}' modéré"
title: Bonjour,
body: L'évènement a été modéré par %{author}
signature: "Merci!\n\n-- \nAgenda du Libre"

View File

@ -0,0 +1,28 @@
require 'test_helper'
class ModerationMailerTest < ActionMailer::TestCase
setup do
ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
end
test "create" do
mail = ModerationMailer.create(Event.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.from
end
test "update" do
mail = ModerationMailer.update(Event.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.from
end
test "moderate" do
mail = ModerationMailer.moderate(Event.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.from
end
end

View File

@ -0,0 +1,25 @@
require 'differ'
# Preview all emails at http://localhost:3000/rails/mailers/moderation_mailer
class ModerationMailerPreview < ActionMailer::Preview
# Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/create
def create
ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
ModerationMailer.create(Event.last)
end
# Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/update
def update
ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
event = Event.last
event.description = event.description + '
hello world'
ModerationMailer.update(event, User.last)
end
# Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/moderate
def moderate
ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
ModerationMailer.moderate(Event.last, User.last)
end
end