From c56ecc0c7f02a460908c7ac46c46eafcaf046493 Mon Sep 17 00:00:00 2001 From: Godwin Date: Sun, 10 Jul 2016 17:13:29 -0700 Subject: [PATCH] Adjusted email inputs to play nicely with sidekiq --- app/mailers/user_mailer.rb | 89 ++++++------------- .../user_mailer/contact_details.html.haml | 16 ++-- app/views/user_mailer/error_report.html.haml | 16 ++-- 3 files changed, 42 insertions(+), 79 deletions(-) diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 544eb81..a51ffee 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -8,44 +8,6 @@ class UserMailer < ActionMailer::Base default from: "Bike!Bike! " - # Subject can be set in your I18n file at config/locales/en.yml - # with the following lookup: - # - # en.user_mailer.activation_needed_email.subject - # - def activation_needed_email(email_address) - @greeting = "Hi" - - mail to: email_address - end - - # Subject can be set in your I18n file at config/locales/en.yml - # with the following lookup: - # - # en.user_mailer.activation_success_email.subject - # - def activation_success_email - @greeting = "Hi" - - mail to: "to@example.org" - end - - def conference_registration_email(conference, data, conference_registration) - @data = data - @conference = conference - @url = "https://bikebike.org"#UserMailer.default_url_options[:host] - @confirmation_url = UserMailer.default_url_options[:host] + "/#{@conference.url}/register/confirm/#{conference_registration.confirmation_token}/".gsub(/\/\/+/, '/') - mail to: data[:email], subject: (I18n.t 'register.email.registration.subject',"Please confirm your registration for #{conference.title}", vars: {:conference_title => conference.title}) - end - - def conference_registration_confirmed_email(conference, data, conference_registration) - @data = data - @conference = conference - @url = "https://bikebike.org"#UserMailer.default_url_options[:host] - @confirmation_url = UserMailer.default_url_options[:host] + "/#{@conference.url}/register/pay-registration/#{conference_registration.confirmation_token}/".gsub(/\/\/+/, '/') - mail to: data[:email], subject: (I18n.t 'register.email.registration_confirmed.subject',"Thanks for confirming your registration for #{conference.title}", vars: {:conference_title => conference.title}) - end - def email_confirmation(confirmation) @confirmation = confirmation @subject = _'email.subject.confirm_email','Please confirm your email address' @@ -53,9 +15,9 @@ class UserMailer < ActionMailer::Base end def registration_confirmation(registration) - @registration = registration - @conference = Conference.find(@registration.conference_id) - @user = User.find(@registration.user_id) + @registration = ConferenceRegistration.find(registration) + @conference = @registration.conference + @user = @registration.user @subject = @conference.registration_status.to_sym == :pre ? _( 'email.subject.pre_registration_confirmed', @@ -72,17 +34,18 @@ class UserMailer < ActionMailer::Base def broadcast(host, subject, content, user, conference) @host = host @content = content - @banner = nil#(@host || 'http://localhost/') + (conference ? (conference.poster.preview.url || '') : image_url('logo.png')) + @banner = nil + @conference = Conference.find(conference) + @user = Conference.find(user) if user.present? @subject = "[#{conference ? conference.title : 'Bike!Bike!'}] #{subject}" - if user && user.named_email - email = user.named_email - mail to: email, subject: @subject + if @user && @user.named_email + mail to: @user.named_email, subject: @subject end end def workshop_facilitator_request(workshop, requester, message) - @workshop = workshop - @requester = requester + @workshop = Workshop.find(workshop) + @requester = User.find(requester) addresses = [] @workshop.active_facilitators.each do |f| addresses << f.named_email @@ -96,9 +59,9 @@ class UserMailer < ActionMailer::Base end def workshop_facilitator_request_approved(workshop, user) - @workshop = workshop + @workshop = Workshop.find(workshop) @conference = Conference.find(@workshop.conference_id) - @user = user + @user = User.find(user) @subject = (_'email.subject.workshop_request_approved', "You have been added as a facilitator of #{@workshop.title}", :vars => {:workshop_title => @workshop.title}) @@ -106,9 +69,9 @@ class UserMailer < ActionMailer::Base end def workshop_facilitator_request_denied(workshop, user) - @workshop = workshop - @conference = Conference.find(@workshop.conference_id) - @user = user + @workshop = Workshop.find(workshop) + @conference = @workshop.conference + @user = User.find(user) @subject = (_'email.subject.workshop_request_denied', "Your request to facilitate #{@workshop.title} has been denied", :vars => {:workshop_title => @workshop.title}) @@ -116,12 +79,12 @@ class UserMailer < ActionMailer::Base end def workshop_translated(workshop, data, locale, user, translator) - @workshop = workshop + @workshop = Workshop.find(workshop) @data = data @locale = locale @locale_name = language_name(locale) - @user = user - @translator = translator + @user = User.find(user) + @translator = User.find(translator) @subject = (_'email.subject.workshop_translated', "The #{@locale_name} translation for #{@workshop.title} has been modified", vars: {language: @language_name, workshop_title: @workshop.title}) @@ -139,10 +102,10 @@ class UserMailer < ActionMailer::Base end def workshop_original_content_changed(workshop, data, user, translator) - @workshop = workshop + @workshop = Workshop.find(workshop) @data = data - @user = user - @translator = translator + @user = User.find(user) + @translator = User.find(translator) @subject = (_'email.subject.workshop_original_content_changed', "Original content for #{@workshop.title} has been modified", vars: {workshop_title: @workshop.title}) @@ -160,9 +123,9 @@ class UserMailer < ActionMailer::Base end def workshop_comment(workshop, comment, user) - @workshop = workshop + @workshop = Workshop.find(workshop) @comment = comment - @user = user + @user = User.find(user) if comment.reply? @subject = (_'email.subject.workshop_comment.reply', vars: { user_name: comment.user.name }) @@ -180,20 +143,20 @@ class UserMailer < ActionMailer::Base @exception = exception @request = request @params = params - @user = user + @user = User.find(user) mail to: 'goodgodwin@hotmail.com', subject: @subject end def contact(from, subject, message, email_list) @message = message - @from = from + @from = from.is_a?(Integer) ? User.find(from) : from mail to: email_list.join(', '), subject: @subject, reply_to: from.is_a?(User) ? from.named_email : from end def contact_details(from, subject, message, request, params) @message = message - @from = from + @from = from.is_a?(Integer) ? User.find(from) : from @request = request @params = params diff --git a/app/views/user_mailer/contact_details.html.haml b/app/views/user_mailer/contact_details.html.haml index c1248f9..1c48094 100644 --- a/app/views/user_mailer/contact_details.html.haml +++ b/app/views/user_mailer/contact_details.html.haml @@ -14,13 +14,13 @@ %td=@from.is_a?(User) ? @from.email : @from %tr %td IP Address - %td=@request.remote_ip + %td=@request['remote_ip'] %tr %td UUID - %td=@request.uuid + %td=@request['uuid'] %tr %td URL - %td=@request.original_url + %td=@request['original_url'] %h1 Message %blockquote=markdown(@message) @@ -32,15 +32,15 @@ %th Value - @params.each do | key, value | %tr - %td=key.to_s - %td=value.to_s + %td=key + %td=value %h1 Request Environment %table.error-report %tr %th Key %th Value - - @request.env.each do | key, value | + - @request['env'].each do | key, value | %tr - %td=key.to_s - %td=value.to_s \ No newline at end of file + %td=key + %td=value \ No newline at end of file diff --git a/app/views/user_mailer/error_report.html.haml b/app/views/user_mailer/error_report.html.haml index 8c2ca0f..8ff2302 100644 --- a/app/views/user_mailer/error_report.html.haml +++ b/app/views/user_mailer/error_report.html.haml @@ -21,13 +21,13 @@ %td=@user.present? ? @user.email : '' %tr %td IP Address - %td=@request.remote_ip + %td=@request['remote_ip'] %tr %td UUID - %td=@request.uuid + %td=@request['uuid'] %tr %td URL - %td=@request.original_url + %td=@request['original_url'] %h1 Params %table.error-report @@ -36,15 +36,15 @@ %th Value - @params.each do | key, value | %tr - %td=key.to_s - %td=value.to_s + %td=key + %td=value %h1 Request Environment %table.error-report %tr %th Key %th Value - - @request.env.each do | key, value | + - @request['env'].each do | key, value | %tr - %td=key.to_s - %td=value.to_s \ No newline at end of file + %td=key + %td=value \ No newline at end of file