]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/changeset_controller.rb
Apply a timeout to most changeset API calls
[rails.git] / app / controllers / changeset_controller.rb
index d2740f7f33e13aa3c89605e546535fa0d69b7d16..31004e8ee38659ce67a478b9161c0bacd6ecc770 100644 (file)
@@ -14,8 +14,8 @@ class ChangesetController < ApplicationController
   before_action :check_api_writable, :only => [:create, :update, :delete, :upload, :include, :comment, :subscribe, :unsubscribe, :hide_comment, :unhide_comment]
   before_action :check_api_readable, :except => [:create, :update, :delete, :upload, :download, :query, :list, :feed, :comment, :subscribe, :unsubscribe, :comments_feed]
   before_action(:only => [:list, :feed, :comments_feed]) { |c| c.check_database_readable(true) }
-  after_action :compress_output
   around_action :api_call_handle_error, :except => [:list, :feed, :comments_feed]
+  around_action :api_call_timeout, :except => [:list, :feed, :comments_feed, :upload]
   around_action :web_timeout, :only => [:list, :feed, :comments_feed]
 
   # Helper methods for checking consistency
@@ -96,8 +96,10 @@ class ChangesetController < ApplicationController
     lat << cs.max_lat unless cs.max_lat.nil?
 
     # collapse the arrays to minimum and maximum
-    cs.min_lon, cs.min_lat, cs.max_lon, cs.max_lat =
-      lon.min, lat.min, lon.max, lat.max
+    cs.min_lon = lon.min
+    cs.min_lat = lat.min
+    cs.max_lon = lon.max
+    cs.max_lat = lat.max
 
     # save the larger bounding box and return the changeset, which
     # will include the bigger bounding box.
@@ -242,20 +244,16 @@ class ChangesetController < ApplicationController
     changeset = Changeset.find(params[:id])
     new_changeset = Changeset.from_xml(request.raw_post)
 
-    if new_changeset.nil?
-      render :text => "", :status => :bad_request
-    else
-      check_changeset_consistency(changeset, @user)
-      changeset.update_from(new_changeset, @user)
-      render :text => changeset.to_xml, :mime_type => "text/xml"
-    end
+    check_changeset_consistency(changeset, @user)
+    changeset.update_from(new_changeset, @user)
+    render :text => changeset.to_xml, :mime_type => "text/xml"
   end
 
   ##
   # list edits (open changesets) in reverse chronological order
   def list
     if request.format == :atom && params[:max_id]
-      redirect_to params.merge(:max_id => nil), :status => :moved_permanently
+      redirect_to url_for(params.merge(:max_id => nil)), :status => :moved_permanently
       return
     end
 
@@ -267,7 +265,7 @@ class ChangesetController < ApplicationController
       end
     end
 
-    if (params[:friends] || params[:nearby]) && !@user && request.format == :html
+    if (params[:friends] || params[:nearby]) && !@user
       require_user
       return
     end
@@ -443,6 +441,8 @@ class ChangesetController < ApplicationController
     respond_to do |format|
       format.rss
     end
+  rescue OSM::APIBadUserInput
+    render :text => "", :status => :bad_request
   end
 
   private