Merge pull request #932 from hennevogel/bugfix_email_settings

Fix email notifications
This commit is contained in:
Henne Vogelsang 2016-04-26 14:33:43 +02:00
commit aabbd35063
22 changed files with 182 additions and 123 deletions

View file

@ -56,6 +56,6 @@ class Comment < ActiveRecord::Base
private
def send_notification
Mailbot.delay.send_notification_email_for_comment(self)
EventCommentMailJob.perform_later(self)
end
end

View file

@ -514,10 +514,11 @@ class Conference < ActiveRecord::Base
# * +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
def notify_on_dates_changed?
(self.start_date_changed? || self.end_date_changed?) &&
self.email_settings.send_on_conference_dates_updated &&
!self.email_settings.conference_dates_updated_subject.blank? &&
self.email_settings.conference_dates_updated_body
return false unless self.email_settings.send_on_conference_dates_updated
# do not notify unless one of the dates changed
return false unless self.start_date_changed? || self.end_date_changed?
# 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
##
@ -527,11 +528,13 @@ class Conference < ActiveRecord::Base
# * +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
def notify_on_registration_dates_changed?
registration_period &&
(registration_period.start_date_changed? || registration_period.end_date_changed?) &&
email_settings.send_on_conference_registration_dates_updated &&
!email_settings.conference_registration_dates_updated_subject.blank? &&
email_settings.conference_registration_dates_updated_body
return false unless self.email_settings.send_on_conference_registration_dates_updated
# do not notify unless we allow a registration
return false unless self.registration_period
# do not notify unless one of the dates changed
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
def registration_limit_exceeded?

View file

@ -112,7 +112,7 @@ class Event < ActiveRecord::Base
program.conference.email_settings.confirmed_without_registration_body &&
program.conference.email_settings.confirmed_without_registration_subject
if program.conference.registrations.where(user_id: submitter.id).first.nil?
Mailbot.delay.confirm_reminder_mail(self)
Mailbot.confirm_reminder_mail(self).deliver_later
end
end
end
@ -122,8 +122,7 @@ class Event < ActiveRecord::Base
program.conference.email_settings.accepted_body &&
program.conference.email_settings.accepted_subject &&
!options[:send_mail].blank?
Rails.logger.debug 'Sending event acceptance mail'
Mailbot.delay.acceptance_mail(self)
Mailbot.acceptance_mail(self).deliver_later
end
end
@ -132,8 +131,7 @@ class Event < ActiveRecord::Base
program.conference.email_settings.rejected_body &&
program.conference.email_settings.rejected_subject &&
!options[:send_mail].blank?
Rails.logger.debug 'Sending rejected mail'
Mailbot.delay.rejection_mail(self)
Mailbot.rejection_mail(self).deliver_later
end
end

View file

@ -64,6 +64,14 @@ class Program < ActiveRecord::Base
cfp.present? && (cfp.start_date..cfp.end_date).cover?(Date.current)
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
##

View file

@ -45,7 +45,7 @@ class Registration < ActiveRecord::Base
def send_registration_mail
if conference.email_settings.send_on_registration?
Mailbot.delay.registration_mail(conference, user)
Mailbot.registration_mail(conference, user).deliver_later
end
end

View file

@ -14,7 +14,7 @@ class Venue < ActiveRecord::Base
content_type: [/jpg/, /jpeg/, /png/, /gif/],
size: { in: 0..500.kilobytes }
after_update :send_mail_notification
before_save :send_mail_notification
def address
"#{street}, #{city}, #{country_name}"
@ -32,15 +32,15 @@ class Venue < ActiveRecord::Base
private
def send_mail_notification
Mailbot.delay.send_email_on_venue_updated(conference) if venue_notify?(conference)
ConferenceVenueUpdateMailJob.perform_later(conference) if notify_on_venue_changed?
end
def venue_notify?(conference)
(self.name_changed? || self.street_changed?) &&
(!self.name.blank? && !self.street.blank?) &&
(conference.email_settings.send_on_venue_updated &&
!conference.email_settings.venue_updated_subject.blank? &&
conference.email_settings.venue_updated_body)
def notify_on_venue_changed?
return false unless conference.email_settings.send_on_venue_updated
# do not notify unless the address changed
return false unless self.name_changed? || self.street_changed? || self.city_changed? || self.country_changed?
# do not notify unless the mail content is set up
(!conference.email_settings.venue_updated_subject.blank? && !conference.email_settings.venue_updated_body.blank?)
end
# TODO: create a module to be mixed into model to perform same operation