Updates in functios to send emails to submitters and/or moderators

This commit is contained in:
Paulo Henrique de Lima Santana 2016-10-28 15:14:24 -02:00
parent 9b2039f5f8
commit 369d7015df
10 changed files with 113 additions and 8 deletions

View File

@ -5,7 +5,7 @@ img.favicon
form#orga_search form#orga_search
right: 5% right: 5%
width: 12em width: 15em
position: absolute position: absolute
font-size: larger font-size: larger
text-align: right text-align: right
@ -23,6 +23,7 @@ form#orga_search
padding-left: 1.5em padding-left: 1.5em
padding-right: 1.2em padding-right: 1.2em
background-color: transparent background-color: transparent
width: 14em
button.search button.search
color: #258 color: #258

View File

@ -12,6 +12,18 @@ class EventMailer < ApplicationMailer
subject: event.title}" subject: event.title}"
end 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' =>
"<event-#{event.id}@#{ActionMailer::Base.default_url_options[:host]}>",
to: event.submitter,
subject: "#{t 'mail_prefix'}#{t 'event_mailer.update.subject',
subject: event.title}"
end
def accept(event) def accept(event)
@event = event @event = event
@current_user = User.find_by id: event.paper_trail.originator @current_user = User.find_by id: event.paper_trail.originator

View File

@ -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' =>
"<orga-#{orga.id}@#{ActionMailer::Base.default_url_options[:host]}>",
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' =>
"<orga-#{orga.id}@#{ActionMailer::Base.default_url_options[:host]}>",
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' =>
"<orga-#{orga.id}@#{ActionMailer::Base.default_url_options[:host]}>",
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' =>
"<orga-#{orga.id}@#{ActionMailer::Base.default_url_options[:host]}>",
subject: "#{t 'mail_prefix'}#{t 'moderationorga_mailer.destroy.subject',
subject: orga.name}"
end
end

View File

@ -39,6 +39,9 @@ class EventCallbacks
elsif ActionMailer::Base.default_url_options[:host] elsif ActionMailer::Base.default_url_options[:host]
# Send an update mail to moderators # Send an update mail to moderators
ModerationMailer.update(event).deliver_now ModerationMailer.update(event).deliver_now
# Included to Send an update mail to its author
EventMailer.update(event).deliver_now
end end
end end

View File

@ -51,18 +51,26 @@ class Orga < ActiveRecord::Base
if moderated_changed? if moderated_changed?
OrgaMailer.accept(self).deliver_now! OrgaMailer.accept(self).deliver_now!
# Send email to moderators when an orga is accepted
ModerationorgaMailer.accept(self).deliver_now!
else else
OrgaMailer.update(self).deliver_now! OrgaMailer.update(self).deliver_now!
# Send email to moderators when an orga is updated
ModerationorgaMailer.update(self).deliver_now!
end end
end end
end end
before_destroy do before_destroy do
OrgaMailer.destroy(self).deliver_now! unless submitter.blank? 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 end
def send_secret def send_secret
OrgaMailer.create(self).deliver_now! OrgaMailer.create(self).deliver_now!
# Send email to moderators when an new orga is received
ModerationorgaMailer.create(self).deliver_now!
end end
def name_as_tag def name_as_tag

View File

@ -19,6 +19,7 @@
= surround '<'.html_safe, '>'.html_safe do = surround '<'.html_safe, '>'.html_safe do
= cancel_event_url e, secret: e.secret = cancel_event_url e, secret: e.secret
\ \
= t '.reminder'
= render file: '/events/show' = render file: '/events/show'
\ \
= t '.signature' = t '.signature'

View File

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

View File

@ -1,5 +1,6 @@
= t '.body', author: @current_user = t '.body', author: @current_user
\ \
= t '.reminder
= render file: '/events/show' = render file: '/events/show'
\ \
= t '.access' = t '.access'

View File

@ -14,9 +14,6 @@
= Differ.diff new, prev = Differ.diff new, prev
\ \
= surround '<'.html_safe, '>'.html_safe do = surround '<'.html_safe, '>'.html_safe do
- if @current_user = edit_moderation_url @event
= edit_moderation_url @event
- else
= edit_event_url @event, secret: @event.secret
\ \
= t '.signature' = t '.signature'

View File

@ -12,9 +12,8 @@
require 'differ/format/patch' require 'differ/format/patch'
Differ.format = Differ::Format::Patch Differ.format = Differ::Format::Patch
= Differ.diff new, prev = Differ.diff new, prev
\
= t '.access'
= surround '<'.html_safe, '>'.html_safe do = surround '<'.html_safe, '>'.html_safe do
= orga_url @orga = edit_orga_url @orga, secret: @orga.secret
\ \
= t '.signature' = t '.signature'