From 369d7015df383ee9098f1ecbd55ecd767990147d Mon Sep 17 00:00:00 2001 From: Paulo Henrique de Lima Santana Date: Fri, 28 Oct 2016 15:14:24 -0200 Subject: [PATCH] Updates in functios to send emails to submitters and/or moderators --- app/assets/stylesheets/orgas.sass | 3 +- app/mailers/event_mailer.rb | 12 ++++ app/mailers/moderationorga_mailer.rb | 64 ++++++++++++++++++++ app/models/event_callbacks.rb | 3 + app/models/orga.rb | 8 +++ app/views/event_mailer/accept.text.haml | 1 + app/views/event_mailer/update.text.haml | 19 ++++++ app/views/moderation_mailer/accept.text.haml | 1 + app/views/moderation_mailer/update.text.haml | 5 +- app/views/orga_mailer/update.text.haml | 5 +- 10 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 app/mailers/moderationorga_mailer.rb create mode 100644 app/views/event_mailer/update.text.haml diff --git a/app/assets/stylesheets/orgas.sass b/app/assets/stylesheets/orgas.sass index f1ab0a0b..b3edd3c1 100644 --- a/app/assets/stylesheets/orgas.sass +++ b/app/assets/stylesheets/orgas.sass @@ -5,7 +5,7 @@ img.favicon form#orga_search right: 5% - width: 12em + width: 15em position: absolute font-size: larger text-align: right @@ -23,6 +23,7 @@ form#orga_search padding-left: 1.5em padding-right: 1.2em background-color: transparent + width: 14em button.search color: #258 diff --git a/app/mailers/event_mailer.rb b/app/mailers/event_mailer.rb index e8d213e8..3626c164 100644 --- a/app/mailers/event_mailer.rb +++ b/app/mailers/event_mailer.rb @@ -12,6 +12,18 @@ class EventMailer < ApplicationMailer subject: event.title}" end +# Send email to submitter too. Before, only moderators were receiving emails when an event was updated + def update(event) + @event = event + @current_user = User.find_by id: event.paper_trail.originator + + mail 'In-Reply-To' => + "", + to: event.submitter, + subject: "#{t 'mail_prefix'}#{t 'event_mailer.update.subject', + subject: event.title}" + end + def accept(event) @event = event @current_user = User.find_by id: event.paper_trail.originator diff --git a/app/mailers/moderationorga_mailer.rb b/app/mailers/moderationorga_mailer.rb new file mode 100644 index 00000000..60a71fe2 --- /dev/null +++ b/app/mailers/moderationorga_mailer.rb @@ -0,0 +1,64 @@ +# Send mails to check on organisations life cycle +class ModerationorgaMailer < ApplicationMailer + helper :events + + # Subject can be set in your I18n file at config/locales/en.yml + # with the following lookup: + # + # en.orga_mailer.create.subject + # + def create(orga) + @orga = orga + + mail 'Message-ID' => + "", + subject: "#{t 'mail_prefix'}#{t 'moderationorga_mailer.create.subject', + subject: orga.name}" + end + + # Subject can be set in your I18n file at config/locales/en.yml + # with the following lookup: + # + # en.orga_mailer.update.subject + # + def update(orga) + @orga = orga + @current_user = User.find_by id: orga.paper_trail.originator + + mail 'In-Reply-To' => + "", + subject: "#{t 'mail_prefix'}#{t 'moderationorga_mailer.update.subject', + subject: orga.name}" + end + + # Subject can be set in your I18n file at config/locales/en.yml + # with the following lookup: + # + # en.orga_mailer.accept.subject + # + def accept(orga) + @orga = orga + @current_user = User.find_by id: orga.paper_trail.originator + + mail 'In-Reply-To' => + "", + subject: "#{t 'mail_prefix'}#{t 'moderationorga_mailer.accept.subject', + subject: orga.name}" + end + + # Subject can be set in your I18n file at config/locales/en.yml + # with the following lookup: + # + # en.orga_mailer.destroy.subject + # + def destroy(orga, reason = '') + @orga = orga + @current_user = User.find_by id: orga.paper_trail.originator + @reason = reason + + mail 'In-Reply-To' => + "", + subject: "#{t 'mail_prefix'}#{t 'moderationorga_mailer.destroy.subject', + subject: orga.name}" + end +end diff --git a/app/models/event_callbacks.rb b/app/models/event_callbacks.rb index e390b5b4..16090ffe 100644 --- a/app/models/event_callbacks.rb +++ b/app/models/event_callbacks.rb @@ -39,6 +39,9 @@ class EventCallbacks elsif ActionMailer::Base.default_url_options[:host] # Send an update mail to moderators ModerationMailer.update(event).deliver_now + + # Included to Send an update mail to its author + EventMailer.update(event).deliver_now end end diff --git a/app/models/orga.rb b/app/models/orga.rb index 61d7ecb2..37189637 100644 --- a/app/models/orga.rb +++ b/app/models/orga.rb @@ -51,18 +51,26 @@ class Orga < ActiveRecord::Base if moderated_changed? OrgaMailer.accept(self).deliver_now! +# Send email to moderators when an orga is accepted + ModerationorgaMailer.accept(self).deliver_now! else OrgaMailer.update(self).deliver_now! +# Send email to moderators when an orga is updated + ModerationorgaMailer.update(self).deliver_now! end end end before_destroy do OrgaMailer.destroy(self).deliver_now! unless submitter.blank? +# Send email to moderators when an orga is deleted + ModerationorgaMailer.destroy(self).deliver_now! unless submitter.blank? end def send_secret OrgaMailer.create(self).deliver_now! +# Send email to moderators when an new orga is received + ModerationorgaMailer.create(self).deliver_now! end def name_as_tag diff --git a/app/views/event_mailer/accept.text.haml b/app/views/event_mailer/accept.text.haml index 87867ac4..27eabbec 100644 --- a/app/views/event_mailer/accept.text.haml +++ b/app/views/event_mailer/accept.text.haml @@ -19,6 +19,7 @@ = surround '<'.html_safe, '>'.html_safe do = cancel_event_url e, secret: e.secret \ += t '.reminder' = render file: '/events/show' \ = t '.signature' diff --git a/app/views/event_mailer/update.text.haml b/app/views/event_mailer/update.text.haml new file mode 100644 index 00000000..36473891 --- /dev/null +++ b/app/views/event_mailer/update.text.haml @@ -0,0 +1,19 @@ += t '.body', subject: @event.title, author: @current_user || t('.submitter') + +:ruby + new = render file: '/events/show' + + former = @event + @event = @event.paper_trail.previous_version || @event + + prev = render file: '/events/show' + @event = former + + require 'differ/format/patch' + Differ.format = Differ::Format::Patch += Differ.diff new, prev +\ += surround '<'.html_safe, '>'.html_safe do + = edit_event_url @event, secret: @event.secret +\ += t '.signature' diff --git a/app/views/moderation_mailer/accept.text.haml b/app/views/moderation_mailer/accept.text.haml index e18ae90d..7fd241db 100644 --- a/app/views/moderation_mailer/accept.text.haml +++ b/app/views/moderation_mailer/accept.text.haml @@ -1,5 +1,6 @@ = t '.body', author: @current_user \ += t '.reminder = render file: '/events/show' \ = t '.access' diff --git a/app/views/moderation_mailer/update.text.haml b/app/views/moderation_mailer/update.text.haml index c195b996..0751b56b 100644 --- a/app/views/moderation_mailer/update.text.haml +++ b/app/views/moderation_mailer/update.text.haml @@ -14,9 +14,6 @@ = Differ.diff new, prev \ = surround '<'.html_safe, '>'.html_safe do - - if @current_user - = edit_moderation_url @event - - else - = edit_event_url @event, secret: @event.secret + = edit_moderation_url @event \ = t '.signature' diff --git a/app/views/orga_mailer/update.text.haml b/app/views/orga_mailer/update.text.haml index b447f31b..416ee740 100644 --- a/app/views/orga_mailer/update.text.haml +++ b/app/views/orga_mailer/update.text.haml @@ -12,9 +12,8 @@ require 'differ/format/patch' Differ.format = Differ::Format::Patch = Differ.diff new, prev - -= t '.access' +\ = surround '<'.html_safe, '>'.html_safe do - = orga_url @orga + = edit_orga_url @orga, secret: @orga.secret \ = t '.signature'