aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2012-11-21 16:37:34 +0000
committerPatrick J Cherry <patrick@bytemark.co.uk>2012-11-21 16:37:34 +0000
commit4a65f1d483e019b93188f7be40c4c63fb99f28fd (patch)
tree3ce489a61b4faed4b7416d3c363ffff2e3c6f109 /lib/mauve
parentfb09cd3b24863a12f9bea9387db4bfbe635c5826 (diff)
Make sure notifications only get sent on Alert#save if the state has
changed in a sane way.
Diffstat (limited to 'lib/mauve')
-rw-r--r--lib/mauve/alert.rb22
1 files changed, 18 insertions, 4 deletions
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