about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-06-30 16:11:21 +0200
committerEugen Rochko <eugen@zeonfederated.com>2019-06-30 16:11:21 +0200
commit082b3b282f7863e4b10e9cb34624b4b167b75588 (patch)
tree63a203c8c5e0225574e33c5e5757f3ac1753465b /app
parent06424786a140e03fcb899232c3c418b7eaf26d5e (diff)
Fix expiration date of filters being set to “Never” when editing them (#11204)
When editing a custom filter, select the shortest preset duration that
still covers the remaining time of that filter.

Fixes #9506
Diffstat (limited to 'app')
-rw-r--r--app/models/custom_filter.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/app/models/custom_filter.rb b/app/models/custom_filter.rb
index 342207a55..382562fb8 100644
--- a/app/models/custom_filter.rb
+++ b/app/models/custom_filter.rb
@@ -35,6 +35,13 @@ class CustomFilter < ApplicationRecord
   before_validation :clean_up_contexts
   after_commit :remove_cache
 
+  def expires_in
+    return @expires_in if defined?(@expires_in)
+    return nil if expires_at.nil?
+
+    [30.minutes, 1.hour, 6.hours, 12.hours, 1.day, 1.week].find { |expires_in| expires_in.from_now >= expires_at }
+  end
+
   private
 
   def clean_up_contexts