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

@ -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