2017 refactor

This commit is contained in:
Godwin
2017-04-09 11:37:16 -07:00
parent 3d00b70087
commit d1db46ffaf
302 changed files with 7100 additions and 8082 deletions
@@ -1,51 +1,51 @@
require 'geocoder/calculations'
class AdminController < ApplicationController
def new
return do_404 unless logged_in? && current_user.administrator?
@this_conference = Conference.new
@main_title = @page_title = 'articles.conferences.headings.new'
end
def edit
return do_404 unless logged_in? && current_user.administrator?
@this_conference = Conference.find_by!(slug: params[:slug])
@page_title = 'articles.conferences.headings.edit'
@main_title_vars = { vars: { title: @this_conference.title } }
render 'new'
end
def save
conference = params[:id].present? ? Conference.find_by!(id: params[:id]) : Conference.new
if params[:button] == 'save'
city = City.search(params[:city])
conference.city_id = city.id
conference.conferencetype = params[:type]
conference.year = params[:year].to_i
conference.is_public = params[:is_public].present?
conference.is_featured = params[:is_featured].present?
conference.make_slug(true)
conference.save!
elsif params[:button] == 'delete'
conference.destroy
return redirect_to conferences_url
end
redirect_to conference_url(conference.slug)
end
rescue_from ActiveRecord::PremissionDenied do |exception|
if logged_in?
redirect_to :register
else
@register_template = :confirm_email
@page_title = "articles.conference_registration.headings.#{@this_conference.registration_status == :open ? '': 'Pre_'}Registration_Details"
render :register
end
end
rescue_from ActiveRecord::RecordNotFound do |exception|
do_404
end
end
require 'geocoder/calculations'
class AdministrationController < ApplicationController
def new
return do_404 unless logged_in? && current_user.administrator?
@this_conference = Conference.new
@main_title = @page_title = 'articles.conferences.headings.new'
end
def edit
return do_404 unless logged_in? && current_user.administrator?
@this_conference = Conference.find_by!(slug: params[:slug])
@page_title = 'articles.conferences.headings.edit'
@main_title_vars = { vars: { title: @this_conference.title } }
render 'new'
end
def save
conference = params[:id].present? ? Conference.find_by!(id: params[:id]) : Conference.new
if params[:button] == 'save'
city = City.search(params[:city])
conference.city_id = city.id
conference.conferencetype = params[:type]
conference.year = params[:year].to_i
conference.is_public = params[:is_public].present?
conference.is_featured = params[:is_featured].present?
conference.make_slug(true)
conference.save!
elsif params[:button] == 'delete'
conference.destroy
return redirect_to conferences_url
end
redirect_to conference_url(conference.slug)
end
rescue_from ActiveRecord::PremissionDenied do |exception|
if logged_in?
redirect_to :register
else
@register_template = :confirm_email
@page_title = "articles.conference_registration.headings.#{@this_conference.registration_status == :open ? '': 'Pre_'}Registration_Details"
render :register
end
end
rescue_from ActiveRecord::RecordNotFound do |exception|
do_404
end
end
+88 -218
View File
@@ -1,11 +1,4 @@
module ActiveRecord
class PremissionDenied < RuntimeError
end
end
class ApplicationController < LinguaFrancaApplicationController
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
class ApplicationController < BaseController
protect_from_forgery with: :exception, :except => [:do_confirm, :js_error, :admin_update]
before_filter :capture_page_info
@@ -16,6 +9,7 @@ class ApplicationController < LinguaFrancaApplicationController
@@test_location
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 = {
@@ -27,14 +21,11 @@ class ApplicationController < LinguaFrancaApplicationController
'env' => Hash.new
}
}
request.env.each do | key, value |
request.env.each do |key, value|
request_info['request']['env'][key.to_s] = value.to_s
end
session['request_info'] = request_info
end
# set the translator to the current user if we're logged in
I18n.config.translator = current_user
I18n.config.callback = self
# get the current conferences and set them globally
status_hierarchy = {
@@ -57,11 +48,9 @@ class ApplicationController < LinguaFrancaApplicationController
@_inline_scripts ||= []
@_inline_scripts << Rails.application.assets.find_asset('main.js').to_s
ActionMailer::Base.default_url_options = {:host => "#{request.protocol}#{request.host_with_port}"}
if request.post? && params[:action] == 'do_confirm'
halt_redirection!
end
ActionMailer::Base.default_url_options = {
host: "#{request.protocol}#{request.host_with_port}"
}
@alt_lang_urls = {}
I18n.backend.enabled_locales.each do |locale|
@@ -72,17 +61,16 @@ class ApplicationController < LinguaFrancaApplicationController
# give each environment a different icon and theme colour so that we can easily see where we are. See https://css-tricks.com/give-development-domain-different-favicon-production
@favicon = Rails.env.development? || Rails.env.preview? ? "favicon-#{Rails.env.to_s}.ico" : 'favicon.ico'
@theme_colour = Rails.env.preview? ? '#EF57B4' : (Rails.env.development? ? '#D89E59' : '#00ADEF')
# call the base method to detect the language
super
end
def home
@workshops = Workshop.where(:conference_id => @conference.id)
if @conference.present? && @conference.id.present?
@workshops = Workshop.where(conference_id: @conference.id)
if @conference.workshop_schedule_published
@event_dlg = true
get_scheule_data(false)
if @conference.workshop_schedule_published
@event_dlg = true
get_scheule_data(false)
end
end
end
@@ -90,14 +78,6 @@ class ApplicationController < LinguaFrancaApplicationController
@is_policy_page = true
end
def robots
render :text => File.read("config/robots-#{Rails.env.production? ? 'live' : 'dev'}.txt"), :content_type => 'text/plain'
end
def humans
render :text => File.read("config/humans.txt"), :content_type => 'text/plain'
end
def self.set_host(host)
@@test_host = host
end
@@ -110,35 +90,6 @@ class ApplicationController < LinguaFrancaApplicationController
@@test_location
end
def do_404
error_404(status: 404)
end
def error_404(args = {})
params[:_original_action] = params[:action]
params[:action] = 'error-404'
@page_title = 'page_titles.404.Page_Not_Found'
@main_title = 'error.404.title'
render 'application/404', args
end
def do_403(template = nil)
@template = template
@page_title ||= 'page_titles.403.Access_Denied'
@main_title ||= @page_title
params[:_original_action] = params[:action]
params[:action] = 'error-403'
render 'application/permission_denied', status: 403
end
def error_500(exception = nil)
@page_title = 'page_titles.500.An_Error_Occurred'
@main_title = 'error.500.title'
params[:_original_action] = params[:action]
params[:action] = 'error-500'
render 'application/500', status: 500
end
def js_error
# send and email if this is production
report = "A JavaScript error has occurred on <code>#{params[:location]}</code>"
@@ -150,7 +101,7 @@ class ApplicationController < LinguaFrancaApplicationController
begin
# log the error
logger.info "Javascript exception: #{params[:message]}"
logger.info "A JavaScript error has occurred on #{params[:location]}:#{params[:lineNumber]}: #{params[:message]}"
UserMailer.send_mail(:error_report) do
[
@@ -163,7 +114,7 @@ class ApplicationController < LinguaFrancaApplicationController
current_user,
Time.now.strftime("%d/%m/%Y %H:%M")
]
end# if Rails.env.preview? || Rails.env.production?
end if Rails.env.preview? || Rails.env.production?
rescue Exception => exception2
logger.info exception2.to_s
logger.info exception2.backtrace.join("\n")
@@ -171,31 +122,27 @@ class ApplicationController < LinguaFrancaApplicationController
render json: {}
end
rescue_from ActiveRecord::RecordNotFound do |exception|
do_404
end
def confirmation_sent(user)
template = 'login_confirmation_sent'
@page_title ||= 'page_titles.403.Please_Check_Email'
rescue_from ActiveRecord::PremissionDenied do |exception|
do_403
end
rescue_from AbstractController::ActionNotFound do |exception|
@banner_image = 'grafitti.jpg'
if current_user
@page_title = nil#'page_titles.Please_Login'
do_403 'not_a_translator'
#return
else
@page_title = 'page_titles.403.Please_Login'
do_403 'translator_login'
if (request.present? && request.referrer.present? && conference = /^\/conferences\/(\w+)\/register\/?$/.match(request.referrer.gsub(/^https?:\/\/.*?\//, '/')))
@this_conference = Conference.find_by!(slug: conference[1])
@banner_image = @this_conference.cover_url
template = 'conferences/email_confirm'
end
do_403 template
end
def locale_not_enabled!(locale = nil)
locale_not_available!(locale)
end
def locale_not_available
locale_not_available!(params[:locale])
end
def locale_not_available!(locale = nil)
set_default_locale
params[:_original_action] = params[:action]
@@ -206,11 +153,13 @@ class ApplicationController < LinguaFrancaApplicationController
render 'application/locale_not_available', status: 404
end
rescue_from StandardError do |exception|
handle_exception exception
unless Rails.env.test?
rescue_from StandardError do |exception|
handle_exception exception
# show the error page
error_500 exception
# show the error page
error_500 exception
end
end
def handle_exception(exception)
@@ -246,37 +195,6 @@ class ApplicationController < LinguaFrancaApplicationController
end
end
def generate_confirmation(user, url, expiry = nil)
if user.is_a? String
user = User.find_user(user)
# if the user doesn't exist, just show them a 403
do_403 unless user.present?
end
expiry ||= (Time.now + 12.hours)
session[:confirm_uid] = user.id
unless user.locale.present?
user.locale = I18n.locale
user.save
end
# send the confirmation email and make sure it get sent as quickly as possible
UserMailer.send_mail :email_confirmation do
EmailConfirmation.create(user_id: user.id, expiry: expiry, url: url)
end
end
def user_settings
@conferences = Array.new
if logged_in?
Conference.all.each do | conference |
@conferences << conference if conference.host? current_user
end
end
@main_title = @page_title = 'page_titles.user_settings.Your_Account'
end
def contact
@main_title = @page_title = 'page_titles.contact.Contact_Us'
end
@@ -286,8 +204,8 @@ class ApplicationController < LinguaFrancaApplicationController
if params[:reason] == 'conference'
@conference.organizations.each do | org |
org.users.each do | user |
@conference.organizations.each do |org|
org.users.each do |user|
email_list << user.named_email
end
end
@@ -322,31 +240,8 @@ class ApplicationController < LinguaFrancaApplicationController
render 'contact'
end
def update_user_settings
return do_403 unless logged_in?
current_user.firstname = params[:name]
current_user.lastname = nil
current_user.languages = (params[:languages] || { I18n.locale.to_s => true }).keys
current_user.is_subscribed = params[:email_subscribe].present?
current_user.save
redirect_to settings_path
end
def do_confirm(settings = nil)
settings ||= {:template => 'login_confirmation_sent'}
def confirm_user
if params[:email]
# see if we've already sent the confirmation email and are just confirming
# the email address
if params[:token]
user = User.find_user(params[:email])
confirm(user)
return
end
user = User.get(params[:email])
# generate the confirmation, send the email and show the 403
referrer = params[:dest] || (request.present? && request.referer.present? ? request.referer.gsub(/^.*?\/\/.*?\//, '/') : settings_path)
generate_confirmation(params[:email], referrer)
template = 'login_confirmation_sent'
@page_title ||= 'page_titles.403.Please_Check_Email'
@@ -361,75 +256,44 @@ class ApplicationController < LinguaFrancaApplicationController
@banner_image ||= 'grafitti.jpg'
@page_title ||= 'page_titles.403.Please_Login'
do_403 (template || 'translator_login')
do_403 template
else
do_404
end
end
def confirm(uid = nil)
@confirmation = EmailConfirmation.find_by_token(params[:token])
unless @confirmation.present?
@token_not_found = true
return do_404
end
confirm_user = nil
if uid.is_a?(User)
confirm_user = uid
uid = confirm_user.id
end
# check to see if we were given a user id to confirm against
# if we were, make sure it was the same one
if (uid ||= (params[:uid] || session[:confirm_uid]))
if uid == @confirmation.user_id
session[:uid] = nil
confirm_user ||= User.find uid
auto_login(confirm_user)
else
@confirmation.delete
end
redirect_to (@confirmation.url || '/')
return
end
def error_404(args = {})
params[:_original_action] = params[:action]
params[:action] = 'error-404'
@page_title = 'page_titles.404.Page_Not_Found'
@main_title = 'error.404.title'
super(args)
end
def do_403(template = nil)
@banner_image = 'grafitti.jpg'
@page_title = 'page_titles.403.Please_Confirm_Email'
do_403 'login_confirm'
end
def translator_request
@banner_image = 'grafitti.jpg'
@page_title = 'page_titles.403.Translator_Request_Sent'
do_403 'translator_request_sent'
end
def user_logout
logout()
redirect_to (params[:url] || '/')
end
def find_user
user = User.find_user(params[:e])
if user.present?
return render json: {
name: user.name,
email: user.email,
exists: true
}
unless current_user
@page_title = 'page_titles.403.Please_Login'
end
render json: {
name: I18n.t('user.not_found'),
email: nil,
exists: false
}
@template = template
@page_title ||= 'page_titles.403.Access_Denied'
@main_title ||= @page_title
params[:_original_action] = params[:action]
params[:action] = 'error-403'
super(template)
end
def login_user(u)
auto_login(u)
def error_500(exception = nil)
@page_title = 'page_titles.500.An_Error_Occurred'
@main_title = 'error.500.title'
params[:_original_action] = params[:action]
params[:action] = 'error-500'
@exception = exception
super(exception)
end
def on_translation_change(object, data, locale, translator_id)
@@ -541,8 +405,8 @@ class ApplicationController < LinguaFrancaApplicationController
@schedule = {}
day_1 = conference.start_date.wday
@workshop_blocks.each_with_index do | info, block |
info['days'].each do | block_day |
@workshop_blocks.each_with_index do |info, block|
info['days'].each do |block_day|
day_diff = block_day.to_i - day_1
day_diff += 7 if day_diff < 0
day = (conference.start_date + day_diff.days).to_date
@@ -555,9 +419,10 @@ class ApplicationController < LinguaFrancaApplicationController
end
end
@workshops.each do | workshop |
@workshops.each do |workshop|
if workshop.block.present?
block = @workshop_blocks[workshop.block['block'].to_i]
day_diff = workshop.block['day'].to_i - day_1
day_diff += 7 if day_diff < 0
day = (conference.start_date + day_diff.days).to_date
@@ -569,7 +434,7 @@ class ApplicationController < LinguaFrancaApplicationController
end
end
@meals.each do | time, meal |
@meals.each do |time, meal|
day = meal['day'].to_date
time = meal['time'].to_f
@schedule[day] ||= {}
@@ -580,7 +445,7 @@ class ApplicationController < LinguaFrancaApplicationController
@schedule[day][:times][time][:item] = meal
end
@events.each do | event |
@events.each do |event|
if event.present? && event.start_time.present? && event.end_time.present?
day = event.start_time.midnight.to_date
time = event.start_time.hour.to_f + (event.start_time.min / 60.0)
@@ -594,13 +459,13 @@ class ApplicationController < LinguaFrancaApplicationController
end
@schedule = @schedule.sort.to_h
@schedule.each do | day, data |
@schedule.each do |day, data|
@schedule[day][:times] = data[:times].sort.to_h
end
@schedule.each do | day, data |
@schedule.each do |day, data|
last_event = nil
data[:times].each do | time, time_data |
data[:times].each do |time, time_data|
if last_event.present?
@schedule[day][:times][last_event][:next_event] = time
end
@@ -609,8 +474,8 @@ class ApplicationController < LinguaFrancaApplicationController
@schedule[day][:num_locations] = (data[:locations] || []).size
end
@schedule.deep_dup.each do | day, data |
data[:times].each do | time, time_data |
@schedule.deep_dup.each do |day, data|
data[:times].each do |time, time_data|
if time_data[:next_event].present? || time_data[:length] > 0.5
span = 0.5
length = time_data[:next_event].present? ? time_data[:next_event] - time : time_data[:length]
@@ -627,7 +492,7 @@ class ApplicationController < LinguaFrancaApplicationController
@schedule = @schedule.sort.to_h
@schedule.each do | day, data |
@schedule.each do |day, data|
@schedule[day][:times] = data[:times].sort.to_h
@schedule[day][:locations] ||= {}
@@ -635,19 +500,19 @@ class ApplicationController < LinguaFrancaApplicationController
@schedule[day][:locations][0] = :add if do_analyze || @schedule[day][:locations].empty?
if do_analyze
data[:times].each do | time, time_data |
data[:times].each do |time, time_data|
if time_data[:type] == :workshop && time_data[:item].present? && time_data[:item][:workshops].present?
ids = time_data[:item][:workshops].keys
(0..ids.length).each do | i |
(0..ids.length).each do |i|
if time_data[:item][:workshops][ids[i]].present?
workshop_i = time_data[:item][:workshops][ids[i]][:workshop]
conflicts = {}
(i+1..ids.length).each do | j |
(i+1..ids.length).each do |j|
workshop_j = time_data[:item][:workshops][ids[j]].present? ? time_data[:item][:workshops][ids[j]][:workshop] : nil
if workshop_i.present? && workshop_j.present?
workshop_i.active_facilitators.each do | facilitator_i |
workshop_j.active_facilitators.each do | facilitator_j |
workshop_i.active_facilitators.each do |facilitator_i|
workshop_j.active_facilitators.each do |facilitator_j|
if facilitator_i.id == facilitator_j.id
@schedule[day][:times][time][:status] ||= {}
@schedule[day][:times][time][:item][:workshops][ids[j]][:status][:errors] << {
@@ -669,7 +534,7 @@ class ApplicationController < LinguaFrancaApplicationController
needs = JSON.parse(workshop_i.needs || '[]').map &:to_sym
amenities = JSON.parse(location.amenities || '[]').map &:to_sym
needs.each do | need |
needs.each do |need|
@schedule[day][:times][time][:item][:workshops][ids[i]][:status][:errors] << {
name: :need_not_available,
need: need,
@@ -685,7 +550,7 @@ class ApplicationController < LinguaFrancaApplicationController
# collect common interested users
interests = []
(0..ids.length).each do | j |
(0..ids.length).each do |j|
workshop_j = time_data[:item][:workshops][ids[j]].present? ? time_data[:item][:workshops][ids[j]][:workshop] : nil
if workshop_i.present? && workshop_j.present? && workshop_i.id != workshop_j.id
interests = interests | workshop_j.interested.map { | u | u.user_id }
@@ -740,4 +605,9 @@ class ApplicationController < LinguaFrancaApplicationController
def html_value(value)
return value.present? && ActionView::Base.full_sanitizer.sanitize(value).strip.present? ? value : nil
end
# send the confirmation email and make sure it get sent as quickly as possible
def send_confirmation(confirmation)
UserMailer.send_mail(:email_confirmation) { confirmation }
end
end
@@ -62,7 +62,10 @@ class ConferenceAdministrationController < ApplicationController
set_flash_messages
# redirect to the step unless the method handled redirection itself
unless self.send(method_name)
case self.send(method_name)
when true
administration_step(@admin_step)
when false
redirect_to administration_step_path(@this_conference.slug, @admin_step)
end
end
@@ -100,6 +103,9 @@ class ConferenceAdministrationController < ApplicationController
end
def administrate_broadcast
if @this_conference.start_date.blank? || @this_conference.end_date.blank?
@warning_message = :no_date_warning
end
end
def administrate_broadcast_sent
@@ -120,6 +126,9 @@ class ConferenceAdministrationController < ApplicationController
end
def administrate_registration_status
if @this_conference.start_date.blank? || @this_conference.end_date.blank?
@warning_message = :no_date_warning
end
end
def administrate_organizations
@@ -142,7 +151,7 @@ class ConferenceAdministrationController < ApplicationController
},
data: [],
}
@organizations.each do | org |
@organizations.each do |org|
if org.present?
address = org.locations.first
@excel_data[:data] << {
@@ -158,18 +167,23 @@ class ConferenceAdministrationController < ApplicationController
}
end
end
return respond_to do | format |
return respond_to do |format|
format.xlsx { render xlsx: :stats, filename: "organizations" }
end
end
end
def administrate_registrations
if @this_conference.start_date.blank? || @this_conference.end_date.blank?
@warning_message = :no_date_warning
return
end
get_stats(!request.format.xlsx?)
if request.format.xlsx?
logger.info "Generating stats.xls"
return respond_to do | format |
return respond_to do |format|
format.xlsx { render xlsx: :stats, filename: "stats-#{DateTime.now.strftime('%Y-%m-%d')}" }
end
end
@@ -180,7 +194,7 @@ class ConferenceAdministrationController < ApplicationController
@donation_count = 0
@donations = 0
@food = { meat: 0, vegan: 0, vegetarian: 0, all: 0 }
@registrations.each do | r |
@registrations.each do |r|
if view_context.registration_status(r) == :registered
@completed_registrations += 1
@@ -200,11 +214,16 @@ class ConferenceAdministrationController < ApplicationController
end
def administrate_stats
if @this_conference.start_date.blank? || @this_conference.end_date.blank?
@warning_message = :no_date_warning
return
end
get_stats(!request.format.xlsx?)
if request.format.xlsx?
logger.info "Generating stats.xls"
return respond_to do | format |
return respond_to do |format|
format.xlsx { render xlsx: :stats, filename: "stats-#{DateTime.now.strftime('%Y-%m-%d')}" }
end
else
@@ -214,7 +233,7 @@ class ConferenceAdministrationController < ApplicationController
@donation_count = 0
@donations = 0
@food = { meat: 0, vegan: 0, vegetarian: 0, all: 0 }
@registrations.each do | r |
@registrations.each do |r|
if view_context.registration_status(r) == :registered
@completed_registrations += 1
@@ -256,7 +275,7 @@ class ConferenceAdministrationController < ApplicationController
},
data: [],
}
@hosts.each do | id, host |
@hosts.each do |id, host|
data = (host.housing_data || {})
host_data = {
name: host.user.name,
@@ -264,7 +283,7 @@ class ConferenceAdministrationController < ApplicationController
email: host.user.email,
phone: data['phone'],
availability: data['availability'].present? && data['availability'][1].present? ? view_context.date_span(data['availability'][0].to_date, data['availability'][1].to_date) : '',
considerations: ((data['considerations'] || []).map { | consideration | view_context._"articles.conference_registration.host.considerations.#{consideration}" }).join(', '),
considerations: ((data['considerations'] || []).map { |consideration| view_context._"articles.conference_registration.host.considerations.#{consideration}" }).join(', '),
empty: '',
guests: {
columns: [:name, :area, :email, :arrival_departure, :allergies, :food, :companion, :city],
@@ -285,8 +304,8 @@ class ConferenceAdministrationController < ApplicationController
}
}
@housing_data[id][:guests].each do | space, space_data |
space_data.each do | guest_id, guest_data |
@housing_data[id][:guests].each do |space, space_data|
space_data.each do |guest_id, guest_data|
guest = guest_data[:guest]
if guest.present?
companion = view_context.companion(guest)
@@ -307,7 +326,7 @@ class ConferenceAdministrationController < ApplicationController
@excel_data[:data] << host_data
end
return respond_to do | format |
return respond_to do |format|
format.xlsx { render xlsx: :stats, filename: "housing" }
end
end
@@ -439,7 +458,7 @@ class ConferenceAdministrationController < ApplicationController
},
data: []
}
User.AVAILABLE_LANGUAGES.each do | l |
User.AVAILABLE_LANGUAGES.each do |l|
@excel_data[:keys]["language_#{l}".to_sym] = "languages.#{l.to_s}"
end
ConferenceRegistration.all_spaces.each do |s|
@@ -449,7 +468,7 @@ class ConferenceAdministrationController < ApplicationController
ConferenceRegistration.all_considerations.each do |c|
@excel_data[:keys][c] = "articles.conference_registration.host.considerations.#{c.to_s}"
end
@registrations.each do | r |
@registrations.each do |r|
user = r.user_id ? User.where(id: r.user_id).first : nil
if user.present?
companion = view_context.companion(r)
@@ -509,7 +528,7 @@ class ConferenceAdministrationController < ApplicationController
last_day: availability[1].present? ? view_context.date(availability[1].to_date, :span_same_year_date_1) : ''
}
}
User.AVAILABLE_LANGUAGES.each do | l |
User.AVAILABLE_LANGUAGES.each do |l|
can_speak = ((user.languages || []).include? l.to_s)
data["language_#{l}".to_sym] = (can_speak ? (view_context._'articles.conference_registration.questions.bike.yes') : '')
data[:raw_values]["language_#{l}".to_sym] = can_speak
@@ -554,12 +573,12 @@ class ConferenceAdministrationController < ApplicationController
first_day: view_context.conference_days_options_list(:before),
last_day: view_context.conference_days_options_list(:after)
}
User.AVAILABLE_LANGUAGES.each do | l |
User.AVAILABLE_LANGUAGES.each do |l|
@column_options["language_#{l}".to_sym] = [
[(view_context._"articles.conference_registration.questions.bike.yes"), true]
]
end
ConferenceRegistration.all_considerations.each do | c |
ConferenceRegistration.all_considerations.each do |c|
@column_options[c.to_sym] = [
[(view_context._"articles.conference_registration.questions.bike.yes"), true]
]
@@ -570,7 +589,7 @@ class ConferenceAdministrationController < ApplicationController
def get_housing_data
@hosts = {}
@guests = {}
ConferenceRegistration.where(:conference_id => @this_conference.id).each do | registration |
ConferenceRegistration.where(:conference_id => @this_conference.id).each do |registration|
if registration.can_provide_housing
@hosts[registration.id] = registration
elsif registration.housing.present? && registration.housing != 'none'
@@ -584,11 +603,11 @@ class ConferenceAdministrationController < ApplicationController
@housing_data = {}
@hosts_affected_by_guests = {}
@hosts.each do | id, host |
@hosts.each do |id, host|
@hosts[id].housing_data ||= {}
@housing_data[id] = { guests: {}, space: {} }
@hosts[id].housing_data['space'] ||= {}
@hosts[id].housing_data['space'].each do | s, size |
@hosts[id].housing_data['space'].each do |s, size|
size = (size || 0).to_i
@housing_data[id][:guests][s.to_sym] = {}
@housing_data[id][:space][s.to_sym] = size
@@ -597,7 +616,7 @@ class ConferenceAdministrationController < ApplicationController
@guests_housed = 0
@guests.each do | guest_id, guest |
@guests.each do |guest_id, guest|
data = guest.housing_data || {}
@hosts_affected_by_guests[guest_id] ||= []
@@ -632,7 +651,7 @@ class ConferenceAdministrationController < ApplicationController
end
companions = data['companions'] || []
companions.each do | companion |
companions.each do |companion|
user = User.find_user(companion)
if user.present?
reg = ConferenceRegistration.find_by(
@@ -659,10 +678,10 @@ class ConferenceAdministrationController < ApplicationController
end
end
@hosts.each do | id, host |
@hosts.each do |id, host|
host_data = host.housing_data
@hosts[id].housing_data['space'].each do | space, size |
@hosts[id].housing_data['space'].each do |space, size|
# make sure the host isn't overbooked
space = space.to_sym
space_available = (size || 0).to_i
@@ -771,7 +790,7 @@ class ConferenceAdministrationController < ApplicationController
end
def admin_update_description
params[:info].each do | locale, value |
params[:info].each do |locale, value|
@this_conference.set_column_for_locale(:info, locale, html_value(value))
end
@this_conference.save
@@ -792,7 +811,7 @@ class ConferenceAdministrationController < ApplicationController
def admin_update_payment_message
begin
params[:payment_message].each do | locale, value |
params[:payment_message].each do |locale, value|
@this_conference.set_column_for_locale(:payment_message, locale, html_value(value))
end
@this_conference.save
@@ -864,7 +883,7 @@ class ConferenceAdministrationController < ApplicationController
end
user_changed = false
params.each do | key, value |
params.each do |key, value|
case key.to_sym
when :city
if value.present?
@@ -995,7 +1014,7 @@ class ConferenceAdministrationController < ApplicationController
@send_to = params[:send_to]
@register_template = :administration
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 do
[
"#{request.protocol}#{request.host_with_port}",
@@ -1108,11 +1127,11 @@ class ConferenceAdministrationController < ApplicationController
event.end_time = event.start_time + params[:time_span].to_f.hours
# save translations
(params[:info] || {}).each do | locale, value |
(params[:info] || {}).each do |locale, value|
event.set_column_for_locale(:title, locale, html_value(value), current_user.id) unless value = event._title(locale)
end
(params[:title] || {}).each do | locale, value |
(params[:title] || {}).each do |locale, value|
event.set_column_for_locale(:info, locale, value, current_user.id) unless value = event._info(locale)
end
@@ -1126,22 +1145,47 @@ class ConferenceAdministrationController < ApplicationController
do_404
return true
end
def admin_update_workshop_times
case params[:button]
when 'save_block'
empty_param = empty_params(:time, :time_span, :days)
if empty_param.present?
set_error_message "save_block_#{empty_param}_required".to_sym
else
@this_conference.workshop_blocks ||= []
@this_conference.workshop_blocks[params[:workshop_block].to_i] = {
'time' => params[:time],
'length' => params[:time_span],
'days' => params[:days].keys
}
@this_conference.save
set_success_message :block_saved
end
return false
when 'delete_block'
@this_conference.workshop_blocks ||= []
@this_conference.workshop_blocks[params[:workshop_block].to_i] = {
'time' => params[:time],
'length' => params[:time_span],
'days' => params[:days].keys
}
@this_conference.workshop_blocks.delete_at(params[:workshop_block].to_i)
@this_conference.save
set_success_message :block_deleted
return false
end
do_404
return true
return nil
end
def admin_update_publish_schedule
case params[:button]
when 'publish'
@this_conference.workshop_schedule_published = !@this_conference.workshop_schedule_published
@this_conference.save
set_success_message "schedule_#{@this_conference.workshop_schedule_published ? '' : 'un'}published".to_sym
return false
end
do_404
return false
end
def admin_update_schedule
@@ -1155,7 +1199,6 @@ class ConferenceAdministrationController < ApplicationController
@entire_page = false
get_scheule_data
render partial: 'schedule'
return true
when 'get-workshop-list'
get_scheule_data(true)
@@ -1166,12 +1209,11 @@ class ConferenceAdministrationController < ApplicationController
@location = params[:location]
@event_location = @location.present? && @location.to_i > 0 ? EventLocation.find(@location.to_i) : nil
@workshops.sort { |a, b| a.title.downcase <=> b.title.downcase }.each do | workshop |
@workshops.sort { |a, b| a.title.downcase <=> b.title.downcase }.each do |workshop|
@ordered_workshops[workshop.id] = workshop
end
render partial: 'select_workshop_table'
return true
when 'set-workshop'
workshop = Workshop.find_by!(conference_id: @this_conference.id, id: params[:workshop].to_i)
workshop.event_location_id = params[:location]
@@ -1183,23 +1225,11 @@ class ConferenceAdministrationController < ApplicationController
get_scheule_data
render partial: 'schedule'
return true
else
do_404
end
do_404
return true
end
def admin_update_schedule
case params[:button]
when 'publish'
@this_conference.workshop_schedule_published = !@this_conference.workshop_schedule_published
@this_conference.save
return false
end
do_404
return false
return nil
end
def admin_update_providers
@@ -1221,9 +1251,13 @@ class ConferenceAdministrationController < ApplicationController
def get_empty(hash, keys)
keys = [keys] unless keys.is_a?(Array)
keys.each do | key |
keys.each do |key|
return key unless hash[key].present?
end
return nil
end
def empty_params(*args)
get_empty(params, args)
end
end
+42 -29
View File
@@ -2,6 +2,7 @@ require 'geocoder/calculations'
require 'rest_client'
class ConferencesController < ApplicationController
def list
@page_title = 'articles.conferences.headings.Conference_List'
@conference_list = { future: [], passed: [] }
@@ -17,7 +18,7 @@ class ConferencesController < ApplicationController
set_conference
do_403 unless @this_conference.is_public || @this_conference.host?(current_user)
@workshops = Workshop.where(:conference_id => @conference.id)
@workshops = Workshop.where(:conference_id => @this_conference.id)
if @this_conference.workshop_schedule_published
@event_dlg = true
@@ -59,7 +60,7 @@ class ConferencesController < ApplicationController
steps = nil
return do_404 unless registration_steps.present?
@register_template = :administration if params[:admin_step].present?
# @register_template = :administration if params[:admin_step].present?
@errors = {}
@warnings = []
@@ -72,8 +73,19 @@ class ConferencesController < ApplicationController
@register_template = steps[steps.find_index($1.to_sym) - 1]
elsif form_step == :paypal_confirm
if @registration.present? && @registration.payment_confirmation_token == params[:confirmation_token]
@amount = PayPal!.details(params[:token]).amount.total
@registration.payment_info = {:payer_id => params[:PayerID], :token => params[:token], :amount => @amount}.to_yaml
if Rails.env.test?
@amount = params[:amount].to_f
info = YAML.load(@registration.payment_info)
info[:amount] = @amount
@registration.payment_info = info.to_yaml
else
@amount = PayPal!.details(params[:token]).amount.total
@registration.payment_info = {
payer_id: params[:PayerID],
token: params[:token],
amount: @amount
}.to_yaml
end
@amount = (@amount * 100).to_i.to_s.gsub(/^(.*)(\d\d)$/, '\1.\2')
@@ -86,7 +98,7 @@ class ConferencesController < ApplicationController
info = YAML.load(@registration.payment_info)
@amount = nil
status = nil
if ENV['RAILS_ENV'] == 'test'
if Rails.env.test?
status = info[:status]
@amount = info[:amount]
else
@@ -114,7 +126,7 @@ class ConferencesController < ApplicationController
case form_step
when :confirm_email
return do_confirm
return confirm_email(params[:email], params[:token], register_path(@this_conference.slug))
when :contact_info
if params[:name].present? && params[:name].gsub(/[\s\W]/, '').present?
current_user.firstname = params[:name].squish
@@ -188,18 +200,23 @@ class ConferencesController < ApplicationController
amount = params[:amount].to_f
if amount > 0
@registration.payment_confirmation_token = ENV['RAILS_ENV'] == 'test' ? 'token' : Digest::SHA256.hexdigest(rand(Time.now.to_f * 1000000).to_i.to_s)
@registration.save
host = "#{request.protocol}#{request.host_with_port}"
response = PayPal!.setup(
PayPalRequest(amount),
register_paypal_confirm_url(@this_conference.slug, :paypal_confirm, @registration.payment_confirmation_token),
register_paypal_confirm_url(@this_conference.slug, :paypal_cancel, @registration.payment_confirmation_token),
noshipping: true,
version: 204
)
if ENV['RAILS_ENV'] != 'test'
# we can't really test paypal integration in our tests, so we'll fake it instead
if Rails.env.test?
@registration.payment_confirmation_token = 'token'
@registration.payment_info = {amount: amount}.to_yaml
@registration.save!
redirect_to 'https://www.paypal.com'
else
@registration.payment_confirmation_token = Digest::SHA256.hexdigest(rand(Time.now.to_f * 1000000).to_i.to_s)
@registration.save!
pp = PayPal!
response = pp.setup(
PayPalRequest(amount),
register_paypal_confirm_url(@this_conference.slug, :paypal_confirm, @registration.payment_confirmation_token),
register_paypal_confirm_url(@this_conference.slug, :paypal_cancel, @registration.payment_confirmation_token),
noshipping: true,
version: 204
)
redirect_to response.redirect_uri
end
return
@@ -219,7 +236,7 @@ class ConferencesController < ApplicationController
# this step is only completed if a payment has been made
if form_step != :payment || (@registration.registration_fees_paid || 0) > 0
@registration.steps_completed ||= []
@registration.steps_completed << form_step
@registration.steps_completed << form_step.to_s
@registration.steps_completed.uniq!
end
end
@@ -334,9 +351,7 @@ class ConferencesController < ApplicationController
steps -= [:questions]
# if this is a housing provider that is not attending the conference, remove these steps
if @registration.is_attending == 'n'
steps -= [:payment, :workshops]
end
steps -= [:payment, :workshops] if @registration.is_attending == 'n'
else
steps -= [:hosting]
end
@@ -344,8 +359,6 @@ class ConferencesController < ApplicationController
steps -= [:hosting, :questions]
end
steps += [:administration] if conference.host?(current_user)
return steps
end
@@ -394,11 +407,11 @@ class ConferencesController < ApplicationController
def PayPalRequest(amount)
Paypal::Payment::Request.new(
:currency_code => 'USD', # if nil, PayPal use USD as default
:description => 'Conference Registration', # item description
:quantity => 1, # item quantity
:amount => amount.to_f, # item value
:custom_fields => {
currency_code: 'USD', # if nil, PayPal use USD as default
description: 'Conference Registration', # item description
quantity: 1, # item quantity
amount: amount.to_f, # item value
custom_fields: {
CARTBORDERCOLOR: "00ADEF",
LOGOIMG: "https://en.bikebike.org/assets/bblogo-paypal.png"
}
-101
View File
@@ -1,101 +0,0 @@
class OauthsController < ApplicationController
skip_before_filter :require_login
# sends the user on a trip to the provider,
# and after authorizing there back to the callback url.
def oauth
set_callback
session[:oauth_last_url] = params[:dest] || request.referer
login_at(auth_params[:provider])
end
def callback
set_callback
user_info = (sorcery_fetch_user_hash auth_params[:provider] || {})[:user_info]
email = user_info['email']
fb_id = user_info['id']
# try to find the user by facebook id
user = User.find_by_fb_id(fb_id)
# otherwise find the user by email
unless user.present?
# only look if the email address is present
user = User.find_user(email) if email.present?
end
# create the user if the email is not recognized
if user.nil?
if email.present?
user = User.create(email: email, firstname: user_info['name'], fb_id: fb_id, locale: I18n.locale)
else
session[:oauth_update_user_info] = user_info
return redirect_to oauth_update_path
end
elsif user.fb_id.blank? || user.email.blank?
user.email = email
user.fb_id = fb_id
user.save!
end
if user.present? && user.email.present?
# log in the user
auto_login(user)
end
oauth_last_url = (session[:oauth_last_url] || home_path)
session.delete(:oauth_last_url)
redirect_to oauth_last_url
end
def update
@main_title = @page_title = 'articles.conference_registration.headings.email_confirm'
@errors = { email: flash[:error] } if flash[:error].present?
render 'application/update_user'
end
def save
unless params[:email].present?
return redirect_to oauth_update_path
end
user = User.find_user(params[:email])
if user.present?
flash[:error] = :exists
return redirect_to oauth_update_path
end
# create the user
user = User.new(email: params[:email], firstname: session[:oauth_update_user_info]['name'], fb_id: session[:oauth_update_user_info]['id'])
user.save!
# log in
auto_login(user)
# clear out the session
oauth_last_url = (session[:oauth_last_url] || home_path)
session.delete(:oauth_last_url)
session.delete(:oauth_update_user_info)
# go to our final destination
redirect_to oauth_last_url
end
private
def auth_params
params.permit(:code, :provider)
end
def set_callback
# force https for prod
protocol = Rails.env.preview? || Rails.env.production? ? 'https://' : request.protocol
# build the callback url
Sorcery::Controller::Config.send(params[:provider]).callback_url =
"#{protocol}#{request.env['HTTP_HOST']}/oauth/callback?provider=facebook"
end
end
+4 -4
View File
@@ -1,10 +1,10 @@
class WorkshopsController < ApplicationController
def workshops
set_conference
set_conference_registration!
@workshops = Workshop.where(:conference_id => @this_conference.id)
@my_workshops = Workshop.joins(:workshop_facilitators).where(:workshop_facilitators => {:user_id => current_user.id}, :conference_id => @this_conference.id)
@workshops = Workshop.where(conference_id: @this_conference.id)
@my_workshops = @workshops.select { |w| w.active_facilitator?(current_user) }
render 'workshops/index'
end
@@ -58,7 +58,7 @@ class WorkshopsController < ApplicationController
@is_translating ||= false
if @is_translating
return do_404 if @translation.to_s == @workshop.locale.to_s || !I18n.backend.enabled_locales.include?(@translation.to_s)
return do_404 unless @translation.to_s != @workshop.locale.to_s && LinguaFranca.locale_enabled?(@translation.to_sym)
return do_403 unless @workshop.can_translate?(current_user, @translation)
@title = @workshop._title(@translation)