aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/mauve/alert.rb15
-rw-r--r--lib/mauve/history.rb8
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index 76e79cd..3810d25 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -85,6 +85,7 @@ module Mauve
before :save, :do_sanitize_html
before :save, :take_copy_of_changes
after :save, :notify_if_needed
+ after :destroy, :destroy_associations
validates_with_method :check_dates
@@ -171,15 +172,15 @@ module Mauve
html_permitted_in = [:detail]
attributes.each do |key, val|
- next if html_permitted_in.include?(key)
next unless val.is_a?(String)
+ next if html_permitted_in.include?(key)
attribute_set(key, Alert.remove_html(val))
end
html_permitted_in.each do |key|
- val = attribute_get(key)
next unless val.is_a?(String)
+ val = attribute_get(key)
attribute_set(key, Alert.clean_html(val))
end
end
@@ -240,6 +241,10 @@ module Mauve
true
end
+ def destroy_associations
+ AlertHistory.all(:alert_id => self.id).destroy
+ end
+
public
def notify
@@ -254,6 +259,12 @@ module Mauve
raise ArgumentError unless person.is_a?(Person)
raise ArgumentError unless ack_until.is_a?(Time)
raise ArgumentError, "Cannot acknowledge a cleared alert" if self.cleared?
+
+ #
+ # Limit acknowledgment time.
+ #
+ limit = Time.now + 15.days
+ ack_until = limit if ack_until > limit
self.acknowledged_by = person.username
self.acknowledged_at = Time.now
diff --git a/lib/mauve/history.rb b/lib/mauve/history.rb
index 74c5e3a..5a0caff 100644
--- a/lib/mauve/history.rb
+++ b/lib/mauve/history.rb
@@ -13,6 +13,8 @@ module Mauve
belongs_to :alert
belongs_to :history
+ after :destroy, :remove_unreferenced_histories
+
def self.migrate!
#
# This copies the alert IDs from the old History table to the new AlertHistories thing, but only if there are no AertHistories
@@ -41,6 +43,12 @@ module Mauve
end
end
+ private
+
+ def remove_unreferenced_histories
+ self.history.destroy unless self.history.alerts.count > 0
+ end
+
end
class History