From 4a65f1d483e019b93188f7be40c4c63fb99f28fd Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 21 Nov 2012 16:37:34 +0000 Subject: Make sure notifications only get sent on Alert#save if the state has changed in a sane way. --- lib/mauve/alert.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'lib/mauve') diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb index ac164ed..703f54a 100644 --- a/lib/mauve/alert.rb +++ b/lib/mauve/alert.rb @@ -319,18 +319,32 @@ module Mauve # @attributes_before_save ||= Hash.new - is_a_new_alert = @attributes_before_save.values.all?{|a| a.nil?} # # Do not alert about changes, for now. # is_a_change = false # [:subject, :summary].any?{|k| @attributes_before_save.keys.include?(k)} # - # We notify if the update type has changed (but not from nil), or if the update type is + # Work out what state the alert was in before the update. + # + if @attributes_before_save.has_key?(:update_type) + original_update_type = @attributes_before_save[:update_type] + # + # If the original update type is nil, then it was cleared. + # + original_update_type ||= "cleared" + else + # + # If there was no update, the original type is the same as the current type. + # + original_update_type = self.update_type + end + + # + # We notify if the update type has changed, or if the update type is # "raised", and the above is_a_change condition is true # - if (@attributes_before_save.has_key?(:update_type) and !is_a_new_alert) or - (self.update_type == "raised" and (is_a_new_alert or is_a_change)) + if (self.update_type != original_update_type) or (is_a_change and self.raised?) self.notify -- cgit v1.2.1