]> git.openstreetmap.org Git - rails.git/commitdiff
Define a DEFAULT_FRESHLY_CLOSED_LIMIT constant
authorHarry Wood <github@harrywood.co.uk>
Wed, 7 Sep 2022 14:03:27 +0000 (15:03 +0100)
committerHarry Wood <github@harrywood.co.uk>
Wed, 14 Sep 2022 22:59:41 +0000 (23:59 +0100)
Define DEFAULT_FRESHLY_CLOSED_LIMIT in the Note model to allow the 7 day limit to be referenced in the API controller and in the new `freshy_closed_until` logic. The default value is `7.days`. API users can still override this, but the website uses that default for the duration of the green "freshly closed" notes markers.

app/controllers/api/notes_controller.rb
app/models/note.rb

index d21a6449781e8779009e7bedb7be71159a887630..4d49774bad2f734a69f39b986b7d15647a563466 100644 (file)
@@ -351,9 +351,9 @@ module Api
     # on their status and the user's request parameters
     def closed_condition(notes)
       closed_since = if params[:closed]
     # on their status and the user's request parameters
     def closed_condition(notes)
       closed_since = if params[:closed]
-                       params[:closed].to_i
+                       params[:closed].to_i.days
                      else
                      else
-                       7
+                       Note::DEFAULT_FRESHLY_CLOSED_LIMIT
                      end
 
       if closed_since.negative?
                      end
 
       if closed_since.negative?
@@ -361,7 +361,7 @@ module Api
       elsif closed_since.positive?
         notes.where(:status => "open")
              .or(notes.where(:status => "closed")
       elsif closed_since.positive?
         notes.where(:status => "open")
              .or(notes.where(:status => "closed")
-                      .where(notes.arel_table[:closed_at].gt(Time.now.utc - closed_since.days)))
+                      .where(notes.arel_table[:closed_at].gt(Time.now.utc - closed_since)))
       else
         notes.where(:status => "open")
       end
       else
         notes.where(:status => "open")
       end
index c3e0d776c61416fb32ed29d0af81c05279cff1e6..0b0597434f0fa5842f31862da19bdf9ec1711da6 100644 (file)
@@ -37,6 +37,8 @@ class Note < ApplicationRecord
 
   after_initialize :set_defaults
 
 
   after_initialize :set_defaults
 
+  DEFAULT_FRESHLY_CLOSED_LIMIT = 7.days
+
   # Sanity check the latitude and longitude and add an error if it's broken
   def validate_position
     errors.add(:base, "Note is not in the world") unless in_world?
   # Sanity check the latitude and longitude and add an error if it's broken
   def validate_position
     errors.add(:base, "Note is not in the world") unless in_world?
@@ -75,7 +77,7 @@ class Note < ApplicationRecord
   def freshly_closed_until
     return nil unless closed?
 
   def freshly_closed_until
     return nil unless closed?
 
-    closed_at + 7.days
+    closed_at + DEFAULT_FRESHLY_CLOSED_LIMIT
   end
 
   # Return the author object, derived from the first comment
   end
 
   # Return the author object, derived from the first comment