]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/changeset_controller.rb
Extend API to allow changesets to be queried by ids
[rails.git] / app / controllers / changeset_controller.rb
index 6a0ad40a7c02643a4cb096de6a24dc14ffd63d30..735fa73a88c31a1820515aa9e4677011946be8b3 100644 (file)
@@ -210,6 +210,7 @@ class ChangesetController < ApplicationController
     changesets = conditions_time(changesets, params['time'])
     changesets = conditions_open(changesets, params['open'])
     changesets = conditions_closed(changesets, params['closed'])
+    changesets = conditions_ids(changesets, params['changesets'])
 
     # create the results document
     results = OSM::API.new.get_xml_doc
@@ -250,8 +251,8 @@ class ChangesetController < ApplicationController
   ##
   # list edits (open changesets) in reverse chronological order
   def list
-    if request.format == :atom and params[:page]
-      redirect_to params.merge({ :page => nil }), :status => :moved_permanently
+    if request.format == :atom and params[:max_id]
+      redirect_to params.merge({ :max_id => nil }), :status => :moved_permanently
       return
     end
 
@@ -268,7 +269,8 @@ class ChangesetController < ApplicationController
       return
     end
 
-    if request.format == :html and !params[:bbox]
+    if request.format == :html and !params[:list]
+      require_oauth
       render :action => :history, :layout => map_layout
     else
       changesets = conditions_nonempty(Changeset.all)
@@ -279,25 +281,19 @@ class ChangesetController < ApplicationController
         else
           changesets = changesets.where("false")
         end
-      end
-
-      if params[:friends] && @user
+      elsif params[:bbox]
+        changesets = conditions_bbox(changesets, BoundingBox.from_bbox_params(params))
+      elsif params[:friends] && @user
         changesets = changesets.where(:user_id => @user.friend_users.public)
-      end
-
-      if params[:nearby] && @user
+      elsif params[:nearby] && @user
         changesets = changesets.where(:user_id => @user.nearby)
       end
 
-      if params[:bbox]
-        changesets = conditions_bbox(changesets, BoundingBox.from_bbox_params(params))
-      end
-
       if params[:max_id]
         changesets = changesets.where("changesets.id <= ?", params[:max_id])
       end
 
-      @edits = changesets.order("changesets.created_at DESC").limit(20).preload(:user, :changeset_tags)
+      @edits = changesets.order("changesets.id DESC").limit(20).preload(:user, :changeset_tags)
 
       render :action => :list, :layout => false
     end
@@ -418,6 +414,20 @@ private
     end
   end
 
+  ##
+  # query changesets by a list of ids
+  # (either specified as array or comma-separated string)
+  def conditions_ids(changesets, ids)
+    if ids.nil?
+      return changesets
+    elsif ids.empty?
+      raise OSM::APIBadUserInput.new("No changesets were given to search for")
+    else
+      ids = ids.split(',').collect { |n| n.to_i }
+      return changesets.where(:id => ids)
+    end
+  end
+
   ##
   # eliminate empty changesets (where the bbox has not been set)
   # this should be applied to all changeset list displays