Using paper trail event version to present the mail diff
This commit is contained in:
parent
be7145539c
commit
650d5b2aae
@ -7,7 +7,6 @@ class EventsController < ApplicationController
|
||||
before_action :set_event, except: [:index, :new, :preview_create, :create]
|
||||
before_action :set_create_event, only: [:preview_create, :create]
|
||||
before_action :check_secret, only: [:edit, :preview, :update, :destroy]
|
||||
before_action :set_old_event, only: [:update]
|
||||
before_action :set_mailer_host
|
||||
rescue_from ActiveRecord::StaleObjectError, with: :locked
|
||||
|
||||
@ -100,10 +99,6 @@ class EventsController < ApplicationController
|
||||
@event = Event.new event_params
|
||||
end
|
||||
|
||||
def set_old_event
|
||||
@older_event = Event.new @event.attributes
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list
|
||||
# through
|
||||
def event_params
|
||||
@ -128,7 +123,7 @@ class EventsController < ApplicationController
|
||||
|
||||
def send_update_mails
|
||||
# Send an update mail to moderators
|
||||
ModerationMailer.update(@older_event, @event, nil).deliver_now
|
||||
ModerationMailer.update(@event, nil).deliver_now
|
||||
end
|
||||
|
||||
def locked
|
||||
|
@ -3,7 +3,6 @@ class ModerationsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :set_moderation, :set_mailer_host, only:
|
||||
[:show, :edit, :preview, :update, :validate, :accept, :refuse, :destroy]
|
||||
before_action :set_old_mod, only: [:update]
|
||||
rescue_from ActiveRecord::StaleObjectError, with: :locked
|
||||
|
||||
def index
|
||||
@ -61,10 +60,6 @@ class ModerationsController < ApplicationController
|
||||
@moderation = @event
|
||||
end
|
||||
|
||||
def set_old_mod
|
||||
@older_mod = Event.new @event.attributes
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list
|
||||
# through.
|
||||
def moderation_params
|
||||
@ -81,7 +76,7 @@ class ModerationsController < ApplicationController
|
||||
|
||||
def send_mails
|
||||
# Send an update mail to moderators
|
||||
ModerationMailer.update(@older_mod, @moderation, current_user).deliver_now
|
||||
ModerationMailer.update(@moderation, current_user).deliver_now
|
||||
end
|
||||
|
||||
def send_accept_mails
|
||||
|
@ -11,8 +11,7 @@ class ModerationMailer < ApplicationMailer
|
||||
subject: event.title}"
|
||||
end
|
||||
|
||||
def update(older_event, event, current_user)
|
||||
@older_event = older_event
|
||||
def update(event, current_user)
|
||||
@event = event
|
||||
@current_user = current_user
|
||||
|
||||
|
@ -28,12 +28,12 @@ class Orga < ActiveRecord::Base
|
||||
send_secret
|
||||
end
|
||||
|
||||
before_update do
|
||||
after_update do
|
||||
send_secret if secret_changed?
|
||||
|
||||
if moderated_changed?
|
||||
OrgaMailer.accept(self).deliver_now!
|
||||
elsif previous_changes
|
||||
else
|
||||
OrgaMailer.update(self).deliver_now!
|
||||
end
|
||||
end
|
||||
|
@ -4,7 +4,7 @@
|
||||
new = render file: '/events/show'
|
||||
|
||||
former = @event
|
||||
@event = @older_event
|
||||
@event = @event.versions.last.reify
|
||||
|
||||
prev = render file: '/events/show'
|
||||
@event = former
|
||||
|
@ -1,7 +1,18 @@
|
||||
= t '.body', subject: @orga.name, author: @current_user || t('.submitter')
|
||||
\
|
||||
= render file: '/orgas/show'
|
||||
\
|
||||
:ruby
|
||||
new = render file: '/orgas/show'
|
||||
|
||||
former = @orga
|
||||
@orga = @orga.versions.last.reify
|
||||
|
||||
prev = render file: '/orgas/show'
|
||||
@orga = former
|
||||
|
||||
require 'differ/format/patch'
|
||||
Differ.format = Differ::Format::Patch
|
||||
= Differ.diff new, prev
|
||||
|
||||
= t '.access'
|
||||
= orga_url @orga
|
||||
\
|
||||
|
@ -239,6 +239,7 @@ description."
|
||||
links: Links
|
||||
actions: Actions
|
||||
edit: Edit
|
||||
cancel: Delete
|
||||
future: Coming
|
||||
past: In the past
|
||||
count:
|
||||
|
@ -242,6 +242,7 @@ description plus complète."
|
||||
links: Liens
|
||||
actions: Actions
|
||||
edit: Éditer
|
||||
cancel: Supprimer
|
||||
future: Prochainement
|
||||
past: Dans le passé
|
||||
count:
|
||||
|
@ -58,6 +58,8 @@ class ModerationsControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test 'should update event' do
|
||||
# Added so paper trail can have some bit of history
|
||||
patch :update, id: @moderation, event: { title: 'hop hop' }
|
||||
patch :update, id: @moderation, event: {
|
||||
title: @moderation.title,
|
||||
start_time: @moderation.start_time,
|
||||
|
@ -53,7 +53,9 @@ class OrgasControllerTest < ActionController::TestCase
|
||||
end
|
||||
|
||||
test 'should update orga' do
|
||||
sign_in users(:one)
|
||||
# Necessary to have the proper paper_trail version
|
||||
@orga.update_attributes name: 'My Title'
|
||||
|
||||
patch :update, id: @orga, orga: { name: @orga.name }
|
||||
|
||||
assert_empty assigns(:orga).errors.messages
|
||||
|
@ -16,14 +16,16 @@ class ModerationMailerTest < ActionMailer::TestCase
|
||||
|
||||
test 'update' do
|
||||
event = Event.last
|
||||
older_event = Event.new event.attributes
|
||||
|
||||
# Added so paper trail can have some bit of history
|
||||
event.save
|
||||
|
||||
event.tags += ' ho'
|
||||
event.start_time += 1.day
|
||||
event.description = event.description + '
|
||||
hello world'
|
||||
|
||||
mail = ModerationMailer.update older_event, event, User.last
|
||||
mail = ModerationMailer.update event, User.last
|
||||
assert_match(/Édition de l'événement .*/, mail.subject)
|
||||
assert_equal ['moderateurs@agendadulibre.org'], mail.to
|
||||
assert_equal ['moderateurs@agendadulibre.org'], mail.from
|
||||
|
@ -19,7 +19,10 @@ class OrgaMailerTest < ActionMailer::TestCase
|
||||
end
|
||||
|
||||
test 'update' do
|
||||
mail = OrgaMailer.update Orga.last
|
||||
@orga = Orga.last
|
||||
# Necessary to have the proper paper_trail version
|
||||
@orga.update_attributes name: 'My Title'
|
||||
mail = OrgaMailer.update @orga
|
||||
assert_match(/Organisation .* modifiée/, mail.subject)
|
||||
assert_equal [Orga.last.submitter], mail.to
|
||||
assert_equal [@config.action_mailer.default_options[:from]],
|
||||
|
@ -10,14 +10,13 @@ class ModerationMailerPreview < ActionMailer::Preview
|
||||
def update
|
||||
ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
|
||||
event = Event.last
|
||||
older_event = Event.new event.attributes
|
||||
|
||||
event.tags += ' ho'
|
||||
event.start_time += 1.day
|
||||
event.description = event.description + '
|
||||
hello world'
|
||||
|
||||
ModerationMailer.update older_event, event, nil
|
||||
ModerationMailer.update event, nil
|
||||
end
|
||||
|
||||
# Preview this email at http://localhost:3000/rails/mailers/moderation_mailer/accept
|
||||
|
@ -9,7 +9,10 @@ class OrgaMailerPreview < ActionMailer::Preview
|
||||
# Preview this email at http://localhost:3000/rails/mailers/orga_mailer/update
|
||||
def update
|
||||
ActionMailer::Base.default_url_options[:host] = 'localhost:3000'
|
||||
OrgaMailer.update Orga.last
|
||||
orga = Orga.last
|
||||
orga.name += ' et hop'
|
||||
orga.save!
|
||||
OrgaMailer.update orga
|
||||
end
|
||||
|
||||
# Preview this email at http://localhost:3000/rails/mailers/orga_mailer/accept
|
||||
|
Loading…
Reference in New Issue
Block a user