]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/api/notes_controller.rb
Merge pull request #3676 from harry-wood/notes-disappear-time
[rails.git] / app / controllers / api / notes_controller.rb
index 4d49774bad2f734a69f39b986b7d15647a563466..5e24532e79bf7f31594a82db9143465aa502dcbf 100644 (file)
@@ -9,6 +9,7 @@ module Api
 
     before_action :set_locale
     around_action :api_call_handle_error, :api_call_timeout
+    before_action :set_request_formats, :except => [:feed]
 
     ##
     # Return a list of notes in a given area
@@ -34,6 +35,10 @@ module Api
 
       # Check the the bounding box is not too big
       bbox.check_size(Settings.max_note_request_area)
+      @min_lon = bbox.min_lon
+      @min_lat = bbox.min_lat
+      @max_lon = bbox.max_lon
+      @max_lat = bbox.max_lat
 
       # Find the notes we want to return
       @notes = notes.bbox(bbox).order("updated_at DESC").limit(result_limit).preload(:comments)
@@ -47,6 +52,26 @@ module Api
       end
     end
 
+    ##
+    # Read a note
+    def show
+      # Check the arguments are sane
+      raise OSM::APIBadUserInput, "No id was given" unless params[:id]
+
+      # Find the note and check it is valid
+      @note = Note.find(params[:id])
+      raise OSM::APINotFoundError unless @note
+      raise OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible? || current_user&.moderator?
+
+      # Render the result
+      respond_to do |format|
+        format.xml
+        format.rss
+        format.json
+        format.gpx
+      end
+    end
+
     ##
     # Create a new note
     def create
@@ -83,6 +108,36 @@ module Api
       end
     end
 
+    ##
+    # Delete (hide) a note
+    def destroy
+      # Check the arguments are sane
+      raise OSM::APIBadUserInput, "No id was given" unless params[:id]
+
+      # Extract the arguments
+      id = params[:id].to_i
+      comment = params[:text]
+
+      # Find the note and check it is valid
+      @note = Note.find(id)
+      raise OSM::APINotFoundError unless @note
+      raise OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible?
+
+      # Mark the note as hidden
+      Note.transaction do
+        @note.status = "hidden"
+        @note.save
+
+        add_comment(@note, comment, "hidden", :notify => false)
+      end
+
+      # Return a copy of the updated note
+      respond_to do |format|
+        format.xml { render :action => :show }
+        format.json { render :action => :show }
+      end
+    end
+
     ##
     # Add a comment to an existing note
     def comment
@@ -189,6 +244,10 @@ module Api
         bbox.check_size(Settings.max_note_request_area)
 
         notes = notes.bbox(bbox)
+        @min_lon = bbox.min_lon
+        @min_lat = bbox.min_lat
+        @max_lon = bbox.max_lon
+        @max_lat = bbox.max_lat
       end
 
       # Find the comments we want to return
@@ -200,56 +259,6 @@ module Api
       end
     end
 
-    ##
-    # Read a note
-    def show
-      # Check the arguments are sane
-      raise OSM::APIBadUserInput, "No id was given" unless params[:id]
-
-      # Find the note and check it is valid
-      @note = Note.find(params[:id])
-      raise OSM::APINotFoundError unless @note
-      raise OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible? || current_user&.moderator?
-
-      # Render the result
-      respond_to do |format|
-        format.xml
-        format.rss
-        format.json
-        format.gpx
-      end
-    end
-
-    ##
-    # Delete (hide) a note
-    def destroy
-      # Check the arguments are sane
-      raise OSM::APIBadUserInput, "No id was given" unless params[:id]
-
-      # Extract the arguments
-      id = params[:id].to_i
-      comment = params[:text]
-
-      # Find the note and check it is valid
-      @note = Note.find(id)
-      raise OSM::APINotFoundError unless @note
-      raise OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible?
-
-      # Mark the note as hidden
-      Note.transaction do
-        @note.status = "hidden"
-        @note.save
-
-        add_comment(@note, comment, "hidden", :notify => false)
-      end
-
-      # Return a copy of the updated note
-      respond_to do |format|
-        format.xml { render :action => :show }
-        format.json { render :action => :show }
-      end
-    end
-
     ##
     # Return a list of notes matching a given string
     def search