Browse Source

Fixed email issues

development
Godwin 8 years ago
parent
commit
8e90f4545b
  1. 129
      app/controllers/application_controller.rb
  2. 169
      app/controllers/conference_administration_controller.rb
  3. 28
      app/controllers/workshops_controller.rb
  4. 96
      features/support/location_cache.yml

129
app/controllers/application_controller.rb

@ -3,7 +3,7 @@ class ApplicationController < BaseController
before_filter :capture_page_info
helper_method :protect
helper_method :protect, :policies
# @@test_host
# @@test_location
@ -14,22 +14,22 @@ class ApplicationController < BaseController
def capture_page_info
# capture request info in case an error occurs
if request.method == "GET" && (params[:controller] != 'application' || params[:action] != 'contact')
session[:last_request]
request_info = {
'params' => params,
'request' => {
'remote_ip' => request.remote_ip,
'uuid' => request.uuid,
'original_url' => request.original_url,
'env' => Hash.new
}
}
request.env.each do |key, value|
request_info['request']['env'][key.to_s] = value.to_s
end
session['request_info'] = request_info
end
# if request.method == "GET" && (params[:controller] != 'application' || params[:action] != 'contact')
# session[:last_request]
# request_info = {
# 'params' => params,
# 'request' => {
# 'remote_ip' => request.remote_ip,
# 'uuid' => request.uuid,
# 'original_url' => request.original_url,
# 'env' => Hash.new
# }
# }
# request.env.each do |key, value|
# request_info['request']['env'][key.to_s] = value.to_s
# end
# # session['request_info'] = request_info
# end
# get the current conferences and set them globally
status_hierarchy = {
@ -57,7 +57,7 @@ class ApplicationController < BaseController
}
@alt_lang_urls = {}
I18n.backend.enabled_locales.each do |locale|
I18n.backend.enabled_locales.sort.each do |locale|
locale = locale.to_s
@alt_lang_urls[locale] = view_context.url_for_locale(locale) # don't show the current locale
end
@ -82,18 +82,6 @@ class ApplicationController < BaseController
@is_policy_page = true
end
# def self.set_host(host)
# @@test_host = host
# end
# def self.set_location(location)
# @@test_location = location
# end
# def self.get_location()
# @@test_location
# end
def js_error
# send and email if this is production
report = "A JavaScript error has occurred on <code>#{params[:location]}</code>"
@ -108,14 +96,14 @@ class ApplicationController < BaseController
logger.info "A JavaScript error has occurred on #{params[:location]}:#{params[:lineNumber]}: #{params[:message]}"
if Rails.env.preview? || Rails.env.production?
requestHash = {
'remote_ip' => arg.remote_ip,
'uuid' => arg.uuid,
'original_url' => arg.original_url,
request_info = {
'remote_ip' => request.remote_ip,
'uuid' => request.uuid,
'original_url' => request.original_url,
'env' => Hash.new
}
request.env.each do | key, value |
requestHash['env'][key.to_s] = value.to_s
request.env.each do |key, value|
request_info['env'][key.to_s] = value.to_s
end
send_mail(:error_report,
@ -123,7 +111,7 @@ class ApplicationController < BaseController
report,
params[:message],
nil,
requestHash,
request_info,
params,
current_user,
Time.now.strftime("%d/%m/%Y %H:%M")
@ -164,6 +152,15 @@ class ApplicationController < BaseController
@page_title = 'page_titles.404.Locale_Not_Available'
@main_title_vars = { vars: { language: view_context.language_name(locale) } }
@main_title = 'error.locale_not_available.title'
unless @alt_lang_urls.present?
@alt_lang_urls = {}
I18n.backend.enabled_locales.sort.each do |locale|
locale = locale.to_s
@alt_lang_urls[locale] = view_context.url_for_locale(locale) # don't show the current locale
end
end
render 'application/locale_not_available', status: 404
end
@ -184,21 +181,21 @@ class ApplicationController < BaseController
# send and email if this is production
if Rails.env.preview? || Rails.env.production?
suppress(Exception) do
requestHash = {
'remote_ip' => arg.remote_ip,
'uuid' => arg.uuid,
'original_url' => arg.original_url,
request_info = {
'remote_ip' => request.remote_ip,
'uuid' => request.uuid,
'original_url' => request.original_url,
'env' => Hash.new
}
request.env.each do | key, value |
requestHash['env'][key.to_s] = value.to_s
request.env.each do |key, value|
request_info['env'][key.to_s] = value.to_s
end
send_mail(:error_report,
"An error has occurred in #{Rails.env}",
nil,
exception.to_s,
exception.backtrace.join("\n"),
requestHash,
request_info,
params,
current_user,
Time.now.strftime("%d/%m/%Y %H:%M")
@ -234,6 +231,16 @@ class ApplicationController < BaseController
end
end
request_info = {
'remote_ip' => request.remote_ip,
'uuid' => request.uuid,
'original_url' => request.original_url,
'env' => Hash.new
}
request.env.each do |key, value|
request_info['env'][key.to_s] = value.to_s
end
send_mail(:contact,
current_user || params[:email],
params[:subject],
@ -241,13 +248,12 @@ class ApplicationController < BaseController
email_list
)
request_info = session['request_info'] || { 'request' => request, 'params' => params }
send_mail(:contact_details,
current_user || params[:email],
params[:subject],
params[:message],
request_info['request'],
request_info['params']
request_info,
params
)
redirect_to contact_sent_path
@ -351,21 +357,21 @@ class ApplicationController < BaseController
# send an email if this is production
if Rails.env.preview? || Rails.env.production?
begin
requestHash = {
'remote_ip' => arg.remote_ip,
'uuid' => arg.uuid,
'original_url' => arg.original_url,
request_info = {
'remote_ip' => request.remote_ip,
'uuid' => request.uuid,
'original_url' => request.original_url,
'env' => Hash.new
}
request.env.each do | key, value |
requestHash['env'][key.to_s] = value.to_s
request.env.each do |key, value|
request_info['env'][key.to_s] = value.to_s
end
send_mail(:error_report,
"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>",
exception.to_s,
nil,
requestHash,
request_info,
params,
current_user.id,
Time.now.strftime("%d/%m/%Y %H:%M")
@ -646,4 +652,19 @@ class ApplicationController < BaseController
UserMailer.send(*args).deliver_now
end
end
def policies
[
:commitment,
:respect,
:empowerment,
:accessible,
:peaceful,
:spaces,
:hearing,
:intent,
:open_minds,
:learning
]
end
end

169
app/controllers/conference_administration_controller.rb

@ -70,6 +70,17 @@ class ConferenceAdministrationController < ApplicationController
end
end
def previous_stats
set_conference
conference = Conference.find_by_slug(params[:conference_slug])
return do_403 unless conference.is_public
get_stats(false, nil, conference)
logger.info "Generating #{conference.slug}.xls"
return respond_to do |format|
format.xlsx { render xlsx: '../conferences/stats', filename: "stats-#{conference.slug}" }
end
end
rescue_from ActiveRecord::PremissionDenied do |exception|
do_403
end
@ -99,6 +110,9 @@ class ConferenceAdministrationController < ApplicationController
def administrate_description
end
def administrate_group_ride
end
def administrate_poster
end
@ -119,6 +133,30 @@ class ConferenceAdministrationController < ApplicationController
def administrate_payment_message
end
def administrate_housing_info
end
def administrate_workshop_info
end
def administrate_schedule_info
end
def administrate_travel_info
end
def administrate_city_info
end
def administrate_what_to_bring
end
def administrate_volunteering_info
end
def administrate_additional_details
end
def administrate_suggested_amounts
end
@ -168,7 +206,7 @@ class ConferenceAdministrationController < ApplicationController
end
end
return respond_to do |format|
format.xlsx { render xlsx: :stats, filename: "organizations" }
format.xlsx { render xlsx: '../conferences/stats', filename: "organizations" }
end
end
end
@ -184,7 +222,7 @@ class ConferenceAdministrationController < ApplicationController
if request.format.xlsx?
logger.info "Generating stats.xls"
return respond_to do |format|
format.xlsx { render xlsx: :stats, filename: "stats-#{DateTime.now.strftime('%Y-%m-%d')}" }
format.xlsx { render xlsx: '../conferences/stats', filename: "stats-#{DateTime.now.strftime('%Y-%m-%d')}" }
end
end
@ -224,7 +262,7 @@ class ConferenceAdministrationController < ApplicationController
if request.format.xlsx?
logger.info "Generating stats.xls"
return respond_to do |format|
format.xlsx { render xlsx: :stats, filename: "stats-#{DateTime.now.strftime('%Y-%m-%d')}" }
format.xlsx { render xlsx: '../conferences/stats', filename: "stats-#{DateTime.now.strftime('%Y-%m-%d')}" }
end
else
@registration_count = @registrations.size
@ -250,6 +288,11 @@ class ConferenceAdministrationController < ApplicationController
end
end
end
@past_conferences = []
Conference.all.order("start_date DESC").each do |conference|
@past_conferences << conference if conference.is_public && @this_conference.id != conference.id
end
end
end
@ -327,7 +370,7 @@ class ConferenceAdministrationController < ApplicationController
@excel_data[:data] << host_data
end
return respond_to do |format|
format.xlsx { render xlsx: :stats, filename: "housing" }
format.xlsx { render xlsx: '../conferences/stats', filename: "housing" }
end
end
end
@ -379,8 +422,8 @@ class ConferenceAdministrationController < ApplicationController
def administrate_publish_schedule
end
def get_stats(html_format = false, id = nil)
@registrations = ConferenceRegistration.where(:conference_id => @this_conference.id).sort { |a,b| (a.user.present? ? (a.user.firstname || '') : '').downcase <=> (b.user.present? ? (b.user.firstname || '') : '').downcase }
def get_stats(html_format = false, id = nil, conference = @this_conference)
@registrations = ConferenceRegistration.where(conference_id: conference.id).sort { |a,b| (a.user.present? ? (a.user.firstname || '') : '').downcase <=> (b.user.present? ? (b.user.firstname || '') : '').downcase }
@excel_data = {
columns: [
:name,
@ -402,7 +445,6 @@ class ConferenceAdministrationController < ApplicationController
:food,
:companion,
:companion_email,
:allergies,
:other,
:can_provide_housing,
:first_day,
@ -421,7 +463,6 @@ class ConferenceAdministrationController < ApplicationController
arrival: [:date, :day],
departure: [:date, :day],
registration_fees_paid: :money,
allergies: :text,
other: :text,
first_day: [:date, :day],
last_day: [:date, :day],
@ -443,7 +484,6 @@ class ConferenceAdministrationController < ApplicationController
food: 'forms.labels.generic.food',
companion: 'articles.conference_registration.terms.companion',
companion_email: 'articles.conference_registration.terms.companion_email',
allergies: 'forms.labels.generic.allergies',
registration_fees_paid: 'articles.conference_registration.headings.fees_paid',
other: 'forms.labels.generic.other_notes',
can_provide_housing: 'articles.conference_registration.can_provide_housing',
@ -458,6 +498,11 @@ class ConferenceAdministrationController < ApplicationController
},
data: []
}
if conference.id != @this_conference.id
@excel_data[:columns] -= [:name, :email]
end
User.AVAILABLE_LANGUAGES.each do |l|
@excel_data[:keys]["language_#{l}".to_sym] = "languages.#{l.to_s}"
end
@ -497,10 +542,9 @@ class ConferenceAdministrationController < ApplicationController
bike: r.bike.present? ? (view_context._"articles.conference_registration.questions.bike.#{r.bike}") : '',
food: r.food.present? ? (view_context._"articles.conference_registration.questions.food.#{r.food}") : '',
companion: companion,
companion_email: (housing_data['companions'] || ['']).first,
allergies: r.allergies,
companion_email: (housing_data['companion'] || { 'email' => ''})['email'],
registration_fees_paid: r.registration_fees_paid,
other: r.other,
other: r.allergies.present? ? "#{r.allergies}\n\n#{r.other}" : r.other,
can_provide_housing: r.can_provide_housing ? (view_context._'articles.conference_registration.questions.bike.yes') : '',
first_day: availability[0].present? ? availability[0].strftime("%F %T") : '',
last_day: availability[1].present? ? availability[1].strftime("%F %T") : '',
@ -650,12 +694,16 @@ class ConferenceAdministrationController < ApplicationController
@housing_data[host_id][:guest_data][guest_id][:warnings][:space] = { actual: (view_context._"forms.labels.generic.#{space.to_s}"), expected: (view_context._"articles.conference_registration.questions.housing.#{guest.housing}")}
end
companions = data['companions'] || []
companions.each do |companion|
user = User.find_user(companion)
if user.present?
if data['companion'].present?
companion = if data['companion']['id'].present?
User.find(data['companion']['id'])
else
User.find_user(data['companion']['email'])
end
if companion.present?
reg = ConferenceRegistration.find_by(
user_id: user.id,
user_id: companion.id,
conference_id: @this_conference.id
)
if reg.present? && @guests[reg.id].present?
@ -798,6 +846,87 @@ class ConferenceAdministrationController < ApplicationController
return false
end
def admin_update_group_ride
params[:group_ride_info].each do |locale, value|
@this_conference.set_column_for_locale(:group_ride_info, locale, html_value(value))
end
@this_conference.save
set_success_message @admin_step
return false
end
def admin_update_housing_info
params[:housing_info].each do |locale, value|
@this_conference.set_column_for_locale(:housing_info, locale, html_value(value))
end
@this_conference.save
set_success_message @admin_step
return false
end
def admin_update_workshop_info
params[:workshop_info].each do |locale, value|
@this_conference.set_column_for_locale(:workshop_info, locale, html_value(value))
end
@this_conference.save
set_success_message @admin_step
return false
end
def admin_update_schedule_info
params[:schedule_info].each do |locale, value|
@this_conference.set_column_for_locale(:schedule_info, locale, html_value(value))
end
@this_conference.save
set_success_message @admin_step
return false
end
def admin_update_travel_info
params[:travel_info].each do |locale, value|
@this_conference.set_column_for_locale(:travel_info, locale, html_value(value))
end
@this_conference.save
set_success_message @admin_step
return false
end
def admin_update_city_info
params[:city_info].each do |locale, value|
@this_conference.set_column_for_locale(:city_info, locale, html_value(value))
end
@this_conference.save
set_success_message @admin_step
return false
end
def admin_update_what_to_bring
params[:what_to_bring].each do |locale, value|
@this_conference.set_column_for_locale(:what_to_bring, locale, html_value(value))
end
@this_conference.save
set_success_message @admin_step
return false
end
def admin_update_volunteering_info
params[:volunteering_info].each do |locale, value|
@this_conference.set_column_for_locale(:volunteering_info, locale, html_value(value))
end
@this_conference.save
set_success_message @admin_step
return false
end
def admin_update_additional_details
params[:additional_details].each do |locale, value|
@this_conference.set_column_for_locale(:additional_details, locale, html_value(value))
end
@this_conference.save
set_success_message @admin_step
return false
end
def admin_update_poster
begin
@this_conference.poster = params[:poster]
@ -902,7 +1031,9 @@ class ConferenceAdministrationController < ApplicationController
registration.send("#{key.to_s}=", value.present? ? Date.parse(value) : nil)
when :companion_email
registration.housing_data ||= {}
registration.housing_data['companions'] = [value]
registration.housing_data['companion'] ||= {}
registration.housing_data['companion']['email'] = value
registration.housing_data['companion']['id'] = User.find_user(value)
when :preferred_language
registration.user.locale = value
user_changed = true
@ -1004,7 +1135,7 @@ class ConferenceAdministrationController < ApplicationController
do_404
end
return true
return nil
end
def admin_update_broadcast

28
app/controllers/workshops_controller.rb

@ -217,11 +217,7 @@ class WorkshopsController < ApplicationController
# 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)
UserMailer.send_mail :workshop_facilitator_request do
{
:args => [ workshop, current_user, params[:message] ]
}
end
UserMailer.workshop_facilitator_request(workshop.id, current_user.id, params[:message]).deliver_later
redirect_to sent_facilitate_workshop_url(@this_conference.slug, workshop.id)
end
@ -254,18 +250,18 @@ class WorkshopsController < ApplicationController
workshop.id, user_id)
f.role = :collaborator
f.save
UserMailer.send_mail :workshop_facilitator_request_approved, user.locale do
[ workshop, user ]
LinguaFranca.with_locale(user.locale) do
UserMailer.workshop_facilitator_request_approved(workshop.id, user.id).deliver_later
end
return redirect_to view_workshop_url(@this_conference.slug, workshop.id)
return redirect_to view_workshop_url(@this_conference.slug, workshop.id)
end
when :deny
if workshop.active_facilitator?(current_user) && workshop.requested_collaborator?(User.find(user_id))
WorkshopFacilitator.delete_all(
:workshop_id => workshop.id,
:user_id => user_id)
UserMailer.send_mail :workshop_facilitator_request_denied, user.locale do
[ workshop, user ]
LinguaFranca.with_locale user.locale do
UserMailer.workshop_facilitator_request_denied(workshop.id, user.id).deliver_later
end
return redirect_to view_workshop_url(@this_conference.slug, workshop.id)
end
@ -312,8 +308,8 @@ class WorkshopsController < ApplicationController
unless workshop.facilitator?(user)
WorkshopFacilitator.create(user_id: user.id, workshop_id: workshop.id, role: :collaborator)
UserMailer.send_mail :workshop_facilitator_request_approved, user.locale do
[ workshop, user ]
LinguaFranca.with_locale user.locale do
UserMailer.workshop_facilitator_request_approved(workshop.id, user.id).deliver_later
end
end
@ -332,8 +328,8 @@ class WorkshopsController < ApplicationController
new_comment = comment.add_comment(current_user, params[:reply])
unless comment.user.id == current_user.id
UserMailer.send_mail :workshop_comment, comment.user.locale do
[ workshop, new_comment, comment.user ]
LinguaFranca.with_locale comment.user.locale do
UserMailer.workshop_comment(workshop.id, new_comment.id, comment.user.id).deliver_later
end
end
elsif params[:button] = 'add_comment'
@ -341,8 +337,8 @@ class WorkshopsController < ApplicationController
workshop.active_facilitators.each do | u |
unless u.id == current_user.id
UserMailer.send_mail :workshop_comment, u.locale do
[ workshop, new_comment, u ]
LinguaFranca.with_locale u.locale do
UserMailer.workshop_comment(workshop.id, new_comment.id, u.id).deliver_later
end
end
end

96
features/support/location_cache.yml

@ -251,6 +251,54 @@ Portland OR: !ruby/object:Geocoder::Result::Google
- locality
- political
cache_hit:
Prince Rupert BC: !ruby/object:Geocoder::Result::Google
data:
address_components:
- long_name: Prince Rupert
short_name: Prince Rupert
types:
- locality
- political
- long_name: Skeena-Queen Charlotte
short_name: Skeena-Queen Charlotte
types:
- administrative_area_level_2
- political
- long_name: British Columbia
short_name: BC
types:
- administrative_area_level_1
- political
- long_name: Canada
short_name: CA
types:
- country
- political
formatted_address: Prince Rupert, BC, Canada
geometry:
bounds:
northeast:
lat: 54.338083
lng: -130.2437961
southwest:
lat: 54.19392
lng: -130.3634291
location:
lat: 54.3150367
lng: -130.3208187
location_type: APPROXIMATE
viewport:
northeast:
lat: 54.3343706
lng: -130.2478032
southwest:
lat: 54.202669
lng: -130.3608029
place_id: ChIJaUV_axPVclQRElbZTQ_jB3E
types:
- locality
- political
cache_hit:
Regina, SK: !ruby/object:Geocoder::Result::Google
data:
address_components:
@ -453,51 +501,3 @@ Eldorado, MX: !ruby/object:Geocoder::Result::Google
- locality
- political
cache_hit:
Prince Rupert BC: !ruby/object:Geocoder::Result::Google
data:
address_components:
- long_name: Prince Rupert
short_name: Prince Rupert
types:
- locality
- political
- long_name: Skeena-Queen Charlotte
short_name: Skeena-Queen Charlotte
types:
- administrative_area_level_2
- political
- long_name: British Columbia
short_name: BC
types:
- administrative_area_level_1
- political
- long_name: Canada
short_name: CA
types:
- country
- political
formatted_address: Prince Rupert, BC, Canada
geometry:
bounds:
northeast:
lat: 54.338083
lng: -130.2437961
southwest:
lat: 54.19392
lng: -130.3634291
location:
lat: 54.3150367
lng: -130.3208187
location_type: APPROXIMATE
viewport:
northeast:
lat: 54.3343706
lng: -130.2478032
southwest:
lat: 54.202669
lng: -130.3608029
place_id: ChIJaUV_axPVclQRElbZTQ_jB3E
types:
- locality
- political
cache_hit:

Loading…
Cancel
Save