From e057e1c479fb92a8fe693e940f4ba8eb404dff7e Mon Sep 17 00:00:00 2001 From: Harry Wood Date: Wed, 7 Sep 2022 15:03:27 +0100 Subject: [PATCH] Define a DEFAULT_FRESHLY_CLOSED_LIMIT constant 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 | 6 +++--- app/models/note.rb | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/notes_controller.rb b/app/controllers/api/notes_controller.rb index d21a64497..4d49774ba 100644 --- a/app/controllers/api/notes_controller.rb +++ b/app/controllers/api/notes_controller.rb @@ -351,9 +351,9 @@ module Api # 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 - 7 + Note::DEFAULT_FRESHLY_CLOSED_LIMIT end if closed_since.negative? @@ -361,7 +361,7 @@ module Api 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 diff --git a/app/models/note.rb b/app/models/note.rb index c3e0d776c..0b0597434 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -37,6 +37,8 @@ class Note < ApplicationRecord 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? @@ -75,7 +77,7 @@ class Note < ApplicationRecord 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 -- 2.39.5