Fix email notifications
This commit is contained in:
parent
2e79f65989
commit
14011f8828
9 changed files with 43 additions and 28 deletions
|
|
@ -31,7 +31,7 @@ module Admin
|
||||||
send_mail_on_cfp_dates_updates = @cfp.notify_on_cfp_date_update?
|
send_mail_on_cfp_dates_updates = @cfp.notify_on_cfp_date_update?
|
||||||
|
|
||||||
if @cfp.update_attributes(cfp_params)
|
if @cfp.update_attributes(cfp_params)
|
||||||
Mailbot.delay.send_on_cfps_dates_updates(@conference) if send_mail_on_cfp_dates_updates
|
Mailbot.delay.send_on_cfp_dates_updates(@conference) if send_mail_on_cfp_dates_updates
|
||||||
redirect_to admin_conference_program_cfp_path(@conference.short_title),
|
redirect_to admin_conference_program_cfp_path(@conference.short_title),
|
||||||
notice: 'Call for papers successfully updated.'
|
notice: 'Call for papers successfully updated.'
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,15 @@ module Admin
|
||||||
load_and_authorize_resource class: EmailSettings
|
load_and_authorize_resource class: EmailSettings
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@conference.email_settings.update_attributes(email_params)
|
if @conference.email_settings.update(email_params)
|
||||||
redirect_to admin_conference_emails_path(
|
redirect_to admin_conference_emails_path(
|
||||||
@conference.short_title),
|
@conference.short_title),
|
||||||
notice: 'Settings have been successfully updated.'
|
notice: 'Email settings have been successfully updated.'
|
||||||
|
else
|
||||||
|
redirect_to admin_conference_emails_path(
|
||||||
|
@conference.short_title),
|
||||||
|
error: "Updating email settings failed. #{@conference.email_settings.errors.to_a.join('. ')}."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
|
@ -24,8 +29,8 @@ module Admin
|
||||||
:send_on_conference_dates_updated, :conference_dates_updated_subject, :conference_dates_updated_body,
|
:send_on_conference_dates_updated, :conference_dates_updated_subject, :conference_dates_updated_body,
|
||||||
:send_on_conference_registration_dates_updated, :conference_registration_dates_updated_subject, :conference_registration_dates_updated_body,
|
:send_on_conference_registration_dates_updated, :conference_registration_dates_updated_subject, :conference_registration_dates_updated_body,
|
||||||
:send_on_venue_updated, :venue_updated_subject, :venue_updated_body,
|
:send_on_venue_updated, :venue_updated_subject, :venue_updated_body,
|
||||||
:send_on_call_for_papers_dates_updated, :call_for_papers_dates_updated_subject, :call_for_papers_dates_updated_body,
|
:send_on_cfp_dates_updated, :cfp_dates_updated_subject, :cfp_dates_updated_body,
|
||||||
:send_on_call_for_papers_schedule_public, :call_for_papers_schedule_public_subject, :call_for_papers_schedule_public_body)
|
:send_on_program_schedule_public, :program_schedule_public_subject, :program_schedule_public_body)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ module Admin
|
||||||
authorize! :update, @conference.program
|
authorize! :update, @conference.program
|
||||||
@program = @conference.program
|
@program = @conference.program
|
||||||
@program.assign_attributes(program_params)
|
@program.assign_attributes(program_params)
|
||||||
# send_mail_on_schedule_public = @program.notify_on_schedule_public?
|
send_mail_on_schedule_public = @program.notify_on_schedule_public?
|
||||||
|
|
||||||
if @program.update_attributes(program_params)
|
if @program.update_attributes(program_params)
|
||||||
# Mailbot.delay.send_on_schedule_public(@conference) if send_mail_on_schedule_public
|
Mailbot.delay.send_on_schedule_public(@conference) if send_mail_on_schedule_public
|
||||||
redirect_to admin_conference_program_path(@conference.short_title),
|
redirect_to admin_conference_program_path(@conference.short_title),
|
||||||
notice: 'The program was successfully updated.'
|
notice: 'The program was successfully updated.'
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,7 @@ class Mailbot < ActionMailer::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_email(conference, to, subject, body)
|
def build_email(conference, to, subject, body)
|
||||||
|
logger.debug "Sending mail about #{subject} to #{to}"
|
||||||
mail(to: to,
|
mail(to: to,
|
||||||
from: conference.contact.email,
|
from: conference.contact.email,
|
||||||
reply_to: conference.contact.email,
|
reply_to: conference.contact.email,
|
||||||
|
|
|
||||||
|
|
@ -514,10 +514,11 @@ class Conference < ActiveRecord::Base
|
||||||
# * +True+ -> If conference is updated and all other parameters are set
|
# * +True+ -> If conference is updated and all other parameters are set
|
||||||
# * +False+ -> Either conference is not updated or one or more parameter is not set
|
# * +False+ -> Either conference is not updated or one or more parameter is not set
|
||||||
def notify_on_dates_changed?
|
def notify_on_dates_changed?
|
||||||
(self.start_date_changed? || self.end_date_changed?) &&
|
return false unless self.email_settings.send_on_conference_dates_updated
|
||||||
self.email_settings.send_on_conference_dates_updated &&
|
# do not notify unless one of the dates changed
|
||||||
!self.email_settings.conference_dates_updated_subject.blank? &&
|
return false unless self.start_date_changed? || self.end_date_changed?
|
||||||
self.email_settings.conference_dates_updated_body
|
# do not notify unless the mail content is set up
|
||||||
|
(!email_settings.conference_dates_updated_subject.blank? && !email_settings.conference_dates_updated_body.blank?)
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
@ -527,11 +528,13 @@ class Conference < ActiveRecord::Base
|
||||||
# * +True+ -> If registration dates is updated and all other parameters are set
|
# * +True+ -> If registration dates is updated and all other parameters are set
|
||||||
# * +False+ -> Either registration date is not updated or one or more parameter is not set
|
# * +False+ -> Either registration date is not updated or one or more parameter is not set
|
||||||
def notify_on_registration_dates_changed?
|
def notify_on_registration_dates_changed?
|
||||||
registration_period &&
|
return false unless self.email_settings.send_on_conference_registration_dates_updated
|
||||||
(registration_period.start_date_changed? || registration_period.end_date_changed?) &&
|
# do not notify unless we allow a registration
|
||||||
email_settings.send_on_conference_registration_dates_updated &&
|
return false unless self.registration_period
|
||||||
!email_settings.conference_registration_dates_updated_subject.blank? &&
|
# do not notify unless one of the dates changed
|
||||||
email_settings.conference_registration_dates_updated_body
|
return false unless registration_period.start_date_changed? || registration_period.end_date_changed?
|
||||||
|
# do not notify unless the mail content is set up
|
||||||
|
(!email_settings.conference_registration_dates_updated_subject.blank? && !email_settings.conference_registration_dates_updated_body.blank?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def registration_limit_exceeded?
|
def registration_limit_exceeded?
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,6 @@ class Event < ActiveRecord::Base
|
||||||
program.conference.email_settings.accepted_body &&
|
program.conference.email_settings.accepted_body &&
|
||||||
program.conference.email_settings.accepted_subject &&
|
program.conference.email_settings.accepted_subject &&
|
||||||
!options[:send_mail].blank?
|
!options[:send_mail].blank?
|
||||||
Rails.logger.debug 'Sending event acceptance mail'
|
|
||||||
Mailbot.delay.acceptance_mail(self)
|
Mailbot.delay.acceptance_mail(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -132,7 +131,6 @@ class Event < ActiveRecord::Base
|
||||||
program.conference.email_settings.rejected_body &&
|
program.conference.email_settings.rejected_body &&
|
||||||
program.conference.email_settings.rejected_subject &&
|
program.conference.email_settings.rejected_subject &&
|
||||||
!options[:send_mail].blank?
|
!options[:send_mail].blank?
|
||||||
Rails.logger.debug 'Sending rejected mail'
|
|
||||||
Mailbot.delay.rejection_mail(self)
|
Mailbot.delay.rejection_mail(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,14 @@ class Program < ActiveRecord::Base
|
||||||
cfp.present? && (cfp.start_date..cfp.end_date).cover?(Date.current)
|
cfp.present? && (cfp.start_date..cfp.end_date).cover?(Date.current)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notify_on_schedule_public?
|
||||||
|
return false unless conference.email_settings.send_on_program_schedule_public
|
||||||
|
# do not notify if the schedule is not public
|
||||||
|
return false unless schedule_public
|
||||||
|
# do not notify unless the mail content is set up
|
||||||
|
(!conference.email_settings.program_schedule_public_subject.blank? && !conference.email_settings.program_schedule_public_body.blank?)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
||||||
|
|
@ -30,15 +30,15 @@ class Venue < ActiveRecord::Base
|
||||||
private
|
private
|
||||||
|
|
||||||
def send_mail_notification
|
def send_mail_notification
|
||||||
Mailbot.delay.send_email_on_venue_updated(conference) if venue_notify?(conference)
|
Mailbot.delay.send_email_on_venue_updated(conference) if notify_on_venue_changed?
|
||||||
end
|
end
|
||||||
|
|
||||||
def venue_notify?(conference)
|
def notify_on_venue_changed?
|
||||||
(self.name_changed? || self.street_changed?) &&
|
return false unless conference.email_settings.send_on_venue_updated
|
||||||
(!self.name.blank? && !self.street.blank?) &&
|
# do not notify unless the address changed
|
||||||
(conference.email_settings.send_on_venue_updated &&
|
return false unless self.name_changed? || self.street_changed? || self.city_changed? || self.country_changed?
|
||||||
!conference.email_settings.venue_updated_subject.blank? &&
|
# do not notify unless the mail content is set up
|
||||||
conference.email_settings.venue_updated_body)
|
(!conference.email_settings.venue_updated_subject.blank? && !conference.email_settings.venue_updated_body.blank?)
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: create a module to be mixed into model to perform same operation
|
# TODO: create a module to be mixed into model to perform same operation
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ feature EmailSettings do
|
||||||
click_button 'Update Email settings'
|
click_button 'Update Email settings'
|
||||||
|
|
||||||
expect(flash).
|
expect(flash).
|
||||||
to eq('Settings have been successfully updated.')
|
to eq('Email settings have been successfully updated.')
|
||||||
|
|
||||||
expect(find('#email_settings_registration_subject').
|
expect(find('#email_settings_registration_subject').
|
||||||
value).to eq('Registration subject')
|
value).to eq('Registration subject')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue