osem-fcy/app/models/email_settings.rb
AEtherC0r3 efaf07178f Upgrade to Rails 5
Update config with rails app:update
Update schema.rb rails db:migrate
Add puma
Make jobs and models inherit from ApplicationJob and ApplicationRecord
Update acts_as_list to 0.9.7 in order to fix
"undefined method `sanitize_sql_hash_for_conditions'" error
Update web-console to 2.3.0 to fix a 500 internal server error
Replace before_filter with before_action
Add rails-controller-testing gem
Add prepend: :true to protect_from_forgery in ApplicationController to
avoid ActionController::InvalidAuthenticityToken exceptions
Remove activeuuid
Update formtastic to 3.1.5 to fix deprecation warnings and issues
with the Input class
Update ahoy_matey to 1.6.0
Update cancancan to 2.0.0 to fix issues with malformed sql queries
Fix program spec
Fix issue with the picture being nil in admin/Organizations#new and #edit
and Organizations#show
Fix ActiveRecord::Base.raise_in_transactional_callbacks= deprecation
warning by removing an unnecessary line in application.rb
Fix failing versions specs
2017-12-11 20:58:04 +02:00

82 lines
2.8 KiB
Ruby

class EmailSettings < ApplicationRecord
belongs_to :conference
has_paper_trail on: [:update], ignore: [:updated_at], meta: { conference_id: :conference_id }
def get_values(conference, user, event = nil, booth = nil)
h = {
'email' => user.email,
'name' => user.name,
'conference' => conference.title,
'conference_start_date' => conference.start_date,
'conference_end_date' => conference.end_date,
'registrationlink' => Rails.application.routes.url_helpers.conference_conference_registration_url(
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')),
'conference_splash_link' => Rails.application.routes.url_helpers.conference_url(
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000')),
'schedule_link' => Rails.application.routes.url_helpers.conference_schedule_url(
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000'))
}
if conference.program.cfp
h['cfp_start_date'] = conference.program.cfp.start_date
h['cfp_end_date'] = conference.program.cfp.end_date
else
h['cfp_start_date'] = 'Unknown'
h['cfp_end_date'] = 'Unknown'
end
if conference.venue
h['venue'] = conference.venue.name
h['venue_address'] = conference.venue.address
else
h['venue'] = 'Unknown'
h['venue_address'] = 'Unknown'
end
if conference.registration_period
h['registration_start_date'] = conference.registration_period.start_date
h['registration_end_date'] = conference.registration_period.end_date
end
if event
h['eventtitle'] = event.title
h['proposalslink'] = Rails.application.routes.url_helpers.conference_program_proposals_url(
conference.short_title, host: (ENV['OSEM_HOSTNAME'] || 'localhost:3000'))
end
if booth
h['booth_title'] = booth.title
end
h
end
def generate_event_mail(event, event_template)
values = get_values(event.program.conference, event.submitter, event)
parse_template(event_template, values)
end
def generate_email_on_conf_updates(conference, user, conf_update_template)
values = get_values(conference, user)
parse_template(conf_update_template, values)
end
def generate_booth_mail(booth, booth_template)
values = get_values(booth.conference, booth.submitter, nil, booth)
parse_template(booth_template, values)
end
private
def parse_template(text, values)
values.each do |key, value|
if value.kind_of?(Date)
text = text.gsub "{#{key}}", value.strftime('%Y-%m-%d') unless text.blank?
else
text = text.gsub "{#{key}}", value unless text.blank? || value.blank?
end
end
text
end
end