Browse Source

Mails pour la modération

recurrent
echarp 8 years ago
parent
commit
dfe1934c90
  1. 2
      Gemfile
  2. 14
      Gemfile.lock
  3. 8
      app/controllers/moderations_controller.rb
  4. 5
      app/mailers/event_mailer.rb
  5. 38
      app/mailers/moderation_mailer.rb
  6. 2
      app/models/event.rb
  7. 4
      app/models/region.rb
  8. 4
      app/models/user.rb
  9. 12
      app/views/event_mailer/create.text.haml
  10. 17
      app/views/moderation_mailer/create.text.haml
  11. 7
      app/views/moderation_mailer/moderate.text.haml
  12. 13
      app/views/moderation_mailer/update.text.haml
  13. 20
      config/locales/fr.yml
  14. 28
      test/mailers/moderation_mailer_test.rb
  15. 25
      test/mailers/previews/moderation_mailer_preview.rb

2
Gemfile

@ -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'

14
Gemfile.lock

@ -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

8
app/controllers/moderations_controller.rb

@ -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

5
app/mailers/event_mailer.rb

@ -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)

38
app/mailers/moderation_mailer.rb

@ -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

2
app/models/event.rb

@ -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 {

4
app/models/region.rb

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

4
app/models/user.rb

@ -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

12
app/views/event_mailer/create.text.haml

@ -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'

17
app/views/moderation_mailer/create.text.haml

@ -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'

7
app/views/moderation_mailer/moderate.text.haml

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

13
app/views/moderation_mailer/update.text.haml

@ -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'

20
config/locales/fr.yml

@ -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"

28
test/mailers/moderation_mailer_test.rb

@ -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

25
test/mailers/previews/moderation_mailer_preview.rb

@ -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
Loading…
Cancel
Save