Browse Source

Another fix for emails

development
Godwin 8 years ago
parent
commit
bebdbefaba
  1. 24
      app/controllers/application_controller.rb
  2. 4
      app/controllers/conference_administration_controller.rb
  3. 12
      app/controllers/workshops_controller.rb
  4. 8
      app/mailers/user_mailer.rb

24
app/controllers/application_controller.rb

@ -118,7 +118,7 @@ class ApplicationController < BaseController
requestHash['env'][key.to_s] = value.to_s requestHash['env'][key.to_s] = value.to_s
end end
UserMailer.send_mail(:error_report, send_mail(:error_report,
"A JavaScript error has occurred", "A JavaScript error has occurred",
report, report,
params[:message], params[:message],
@ -193,7 +193,7 @@ class ApplicationController < BaseController
request.env.each do | key, value | request.env.each do | key, value |
requestHash['env'][key.to_s] = value.to_s requestHash['env'][key.to_s] = value.to_s
end end
UserMailer.send_mail(:error_report, send_mail(:error_report,
"An error has occurred in #{Rails.env}", "An error has occurred in #{Rails.env}",
nil, nil,
exception.to_s, exception.to_s,
@ -234,7 +234,7 @@ class ApplicationController < BaseController
end end
end end
UserMailer.send_mail(:contact, send_mail(:contact,
current_user || params[:email], current_user || params[:email],
params[:subject], params[:subject],
params[:message], params[:message],
@ -242,7 +242,7 @@ class ApplicationController < BaseController
) )
request_info = session['request_info'] || { 'request' => request, 'params' => params } request_info = session['request_info'] || { 'request' => request, 'params' => params }
UserMailer.send_mail(:contact_details, send_mail(:contact_details,
current_user || params[:email], current_user || params[:email],
params[:subject], params[:subject],
params[:message], params[:message],
@ -323,7 +323,7 @@ class ApplicationController < BaseController
object.get_translators(data, locale).each do |id, user| object.get_translators(data, locale).each do |id, user|
if user.id != current_user.id && user.id != translator_id if user.id != current_user.id && user.id != translator_id
LinguaFranca.with_locale user.locale do LinguaFranca.with_locale user.locale do
UserMailer.send_mail(:send, mailer, object.id, data, locale, user.id, translator.id) send_mail(:send, mailer, object.id, data, locale, user.id, translator.id)
end end
end end
end end
@ -337,7 +337,7 @@ class ApplicationController < BaseController
object.get_translators(data).each do |id, user| object.get_translators(data).each do |id, user|
if user.id != current_user.id if user.id != current_user.id
LinguaFranca.with_locale user.locale do LinguaFranca.with_locale user.locale do
UserMailer.send_mail(:send, mailer, object.id, data, user.id, current_user.id) send_mail(:send, mailer, object.id, data, user.id, current_user.id)
end end
end end
end end
@ -360,7 +360,7 @@ class ApplicationController < BaseController
request.env.each do | key, value | request.env.each do | key, value |
requestHash['env'][key.to_s] = value.to_s requestHash['env'][key.to_s] = value.to_s
end end
UserMailer.send_mail(:error_report, send_mail(:error_report,
"A missing translation found in #{Rails.env}", "A missing translation found in #{Rails.env}",
"<p>A translation for <code>#{key}</code> in <code>#{locale.to_s}</code> was found. The text that was rendered to the user was:</p><blockquote>#{str || 'nil'}</blockquote>", "<p>A translation for <code>#{key}</code> in <code>#{locale.to_s}</code> was found. The text that was rendered to the user was:</p><blockquote>#{str || 'nil'}</blockquote>",
exception.to_s, exception.to_s,
@ -636,6 +636,14 @@ class ApplicationController < BaseController
# send the confirmation email and make sure it get sent as quickly as possible # send the confirmation email and make sure it get sent as quickly as possible
def send_confirmation(confirmation) def send_confirmation(confirmation)
UserMailer.send_mail(:email_confirmation, confirmation.id) send_mail(:email_confirmation, confirmation.id)
end
def send_mail(*args)
if Rails.env.preview? || Rails.env.production?
UserMailer.delay(queue: Rails.env.to_s).send(*args)
else
UserMailer.send(*args).deliver_now
end
end end
end end

4
app/controllers/conference_administration_controller.rb

@ -1015,7 +1015,7 @@ class ConferenceAdministrationController < ApplicationController
@register_template = :administration @register_template = :administration
if params[:button] == 'send' if params[:button] == 'send'
view_context.broadcast_to(@send_to).each do |user| view_context.broadcast_to(@send_to).each do |user|
UserMailer.send_mail(:broadcast, send_mail(:broadcast,
"#{request.protocol}#{request.host_with_port}", "#{request.protocol}#{request.host_with_port}",
@subject, @subject,
@body, @body,
@ -1030,7 +1030,7 @@ class ConferenceAdministrationController < ApplicationController
@broadcast_step = :preview @broadcast_step = :preview
elsif params[:button] == 'test' elsif params[:button] == 'test'
@broadcast_step = :test @broadcast_step = :test
UserMailer.send_mail(:broadcast, send_mail(:broadcast,
"#{request.protocol}#{request.host_with_port}", "#{request.protocol}#{request.host_with_port}",
@subject, @subject,
@body, @body,

12
app/controllers/workshops_controller.rb

@ -217,7 +217,7 @@ class WorkshopsController < ApplicationController
# create the request by making the user a facilitator but making their role 'requested' # create the request by making the user a facilitator but making their role 'requested'
WorkshopFacilitator.create(user_id: current_user.id, workshop_id: workshop.id, role: :requested) WorkshopFacilitator.create(user_id: current_user.id, workshop_id: workshop.id, role: :requested)
UserMailer.send_mail(:workshop_facilitator_request, workshop.id, current_user.id, params[:message]) send_mail(:workshop_facilitator_request, workshop.id, current_user.id, params[:message])
redirect_to sent_facilitate_workshop_url(@this_conference.slug, workshop.id) redirect_to sent_facilitate_workshop_url(@this_conference.slug, workshop.id)
end end
@ -251,7 +251,7 @@ class WorkshopsController < ApplicationController
f.role = :collaborator f.role = :collaborator
f.save f.save
LinguaFranca.with_locale(user.locale) do LinguaFranca.with_locale(user.locale) do
UserMailer.send_mail(:workshop_facilitator_request_approved, workshop.id, user.id) send_mail(:workshop_facilitator_request_approved, workshop.id, user.id)
end end
return redirect_to view_workshop_url(@this_conference.slug, workshop.id) return redirect_to view_workshop_url(@this_conference.slug, workshop.id)
end end
@ -261,7 +261,7 @@ class WorkshopsController < ApplicationController
:workshop_id => workshop.id, :workshop_id => workshop.id,
:user_id => user_id) :user_id => user_id)
LinguaFranca.with_locale user.locale do LinguaFranca.with_locale user.locale do
UserMailer.send_mail(:workshop_facilitator_request_denied, workshop.id, user.id) send_mail(:workshop_facilitator_request_denied, workshop.id, user.id)
end end
return redirect_to view_workshop_url(@this_conference.slug, workshop.id) return redirect_to view_workshop_url(@this_conference.slug, workshop.id)
end end
@ -309,7 +309,7 @@ class WorkshopsController < ApplicationController
WorkshopFacilitator.create(user_id: user.id, workshop_id: workshop.id, role: :collaborator) WorkshopFacilitator.create(user_id: user.id, workshop_id: workshop.id, role: :collaborator)
LinguaFranca.with_locale user.locale do LinguaFranca.with_locale user.locale do
UserMailer.send_mail(:workshop_facilitator_request_approved, workshop.id, user.id) send_mail(:workshop_facilitator_request_approved, workshop.id, user.id)
end end
end end
@ -329,7 +329,7 @@ class WorkshopsController < ApplicationController
unless comment.user.id == current_user.id unless comment.user.id == current_user.id
LinguaFranca.with_locale comment.user.locale do LinguaFranca.with_locale comment.user.locale do
UserMailer.send_mail(:workshop_comment, workshop.id, new_comment.id, comment.user.id) send_mail(:workshop_comment, workshop.id, new_comment.id, comment.user.id)
end end
end end
elsif params[:button] = 'add_comment' elsif params[:button] = 'add_comment'
@ -338,7 +338,7 @@ class WorkshopsController < ApplicationController
workshop.active_facilitators.each do | u | workshop.active_facilitators.each do | u |
unless u.id == current_user.id unless u.id == current_user.id
LinguaFranca.with_locale u.locale do LinguaFranca.with_locale u.locale do
UserMailer.send_mail(:workshop_comment, workshop.id, new_comment.id, u.id) send_mail(:workshop_comment, workshop.id, new_comment.id, u.id)
end end
end end
end end

8
app/mailers/user_mailer.rb

@ -167,14 +167,6 @@ class UserMailer < ActionMailer::Base
mail to: 'goodgodwin@hotmail.com', subject: @subject mail to: 'goodgodwin@hotmail.com', subject: @subject
end end
def self.send_mail(*args)
if Rails.env.preview? || Rails.env.production?
delay(queue: Rails.env.to_s).send(*args)
else
send(*args).deliver_now
end
end
private private
def set_host(*args) def set_host(*args)
if Rails.env.production? if Rails.env.production?

Loading…
Cancel
Save