diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index c8e3c332730f9e38fcfa986a40c66a97086267d5..2df4eb1659a1601cb2ed1970b97cbcace2cb9431 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -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 diff --git a/app/controllers/moderations_controller.rb b/app/controllers/moderations_controller.rb index bb031cd45a84fada63b531e88951baaae3029301..6070cd62b22496cbd92e55d392bf93fe83010132 100644 --- a/app/controllers/moderations_controller.rb +++ b/app/controllers/moderations_controller.rb @@ -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 diff --git a/app/mailers/moderation_mailer.rb b/app/mailers/moderation_mailer.rb index ac4535dbf5bd2500429a4c743da302b5114d5166..59e413c59bd7f0d2e88cb4ca0217e52283f2230a 100644 --- a/app/mailers/moderation_mailer.rb +++ b/app/mailers/moderation_mailer.rb @@ -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 diff --git a/app/models/orga.rb b/app/models/orga.rb index 8a9db50801d49b77a3ea3fc8c861e59a2db4deb7..b157062228899b653d4091f21d2446be95d18b39 100644 --- a/app/models/orga.rb +++ b/app/models/orga.rb @@ -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 diff --git a/app/views/moderation_mailer/update.text.haml b/app/views/moderation_mailer/update.text.haml index cb2ca126567ae768a1d38dcac4c90c1074e9b313..189b81b6adbff0101a8349320b96423c3ae0e66a 100644 --- a/app/views/moderation_mailer/update.text.haml +++ b/app/views/moderation_mailer/update.text.haml @@ -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 diff --git a/app/views/orga_mailer/update.text.haml b/app/views/orga_mailer/update.text.haml index 402f6a3b0494c84d709fadb10ffaebe31f5bd738..22a0e00d86729b9ae5a4204ff2181ede416657ba 100644 --- a/app/views/orga_mailer/update.text.haml +++ b/app/views/orga_mailer/update.text.haml @@ -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 \ diff --git a/config/locales/views/en.yml b/config/locales/views/en.yml index 695bf29909d89c4ee9da0b72457e1eea9b975b29..79d50b52b5d96c8fa5811d09a217ac21fefad776 100644 --- a/config/locales/views/en.yml +++ b/config/locales/views/en.yml @@ -239,6 +239,7 @@ description." links: Links actions: Actions edit: Edit + cancel: Delete future: Coming past: In the past count: diff --git a/config/locales/views/fr.yml b/config/locales/views/fr.yml index 7dc40b0f45723baa5d51d94ac8a5122abc6d70c3..2a2521524a2c7b22993b3f530d23dd9af8d3e736 100644 --- a/config/locales/views/fr.yml +++ b/config/locales/views/fr.yml @@ -242,6 +242,7 @@ description plus complète." links: Liens actions: Actions edit: Éditer + cancel: Supprimer future: Prochainement past: Dans le passé count: diff --git a/test/controllers/moderations_controller_test.rb b/test/controllers/moderations_controller_test.rb index 1b590ce0bc9680a5f5b8a25cc6bd81cf20215b25..5fc71cd9d33414b3a5e3003c65e6a5c62de5fe49 100644 --- a/test/controllers/moderations_controller_test.rb +++ b/test/controllers/moderations_controller_test.rb @@ -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, diff --git a/test/controllers/orgas_controller_test.rb b/test/controllers/orgas_controller_test.rb index 8748cb0a16095ea86668df568d4f6f696918fcc5..a1d1b0aad55bff08e7c320897cd10492ef1534d8 100644 --- a/test/controllers/orgas_controller_test.rb +++ b/test/controllers/orgas_controller_test.rb @@ -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 diff --git a/test/mailers/moderation_mailer_test.rb b/test/mailers/moderation_mailer_test.rb index 23646fb5e309d818c627b3165913a17551d2f8a3..1204fbbe7acaa31f08de20f3ef79be86bc055954 100644 --- a/test/mailers/moderation_mailer_test.rb +++ b/test/mailers/moderation_mailer_test.rb @@ -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 diff --git a/test/mailers/orga_mailer_test.rb b/test/mailers/orga_mailer_test.rb index c98e2d6641a59f25a1915277eb1a2bb8a824635c..befa5f67f9b1e1b26019fa0980c0419b87a56e37 100644 --- a/test/mailers/orga_mailer_test.rb +++ b/test/mailers/orga_mailer_test.rb @@ -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]], diff --git a/test/mailers/previews/moderation_mailer_preview.rb b/test/mailers/previews/moderation_mailer_preview.rb index 55cfcc4a0cf9c7fcb00bb0b85568632c944631a8..325647b96b8f494d4ad34fb3418c6ec0207d0ca0 100644 --- a/test/mailers/previews/moderation_mailer_preview.rb +++ b/test/mailers/previews/moderation_mailer_preview.rb @@ -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 diff --git a/test/mailers/previews/orga_mailer_preview.rb b/test/mailers/previews/orga_mailer_preview.rb index 6a91fbcd9c4d7e102422de592705d1323251adf2..e2e23188856447b2bdd48769a0e75e0ebbfc8a98 100644 --- a/test/mailers/previews/orga_mailer_preview.rb +++ b/test/mailers/previews/orga_mailer_preview.rb @@ -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