From: Tom Hughes Date: Thu, 27 Oct 2011 20:36:16 +0000 (+0100) Subject: Stop the API changeset query accepting min_lon etc X-Git-Tag: live~6033 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/9c28a626cbefd289d17556747979bd73ee3a77cd Stop the API changeset query accepting min_lon etc --- diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index f6d35b440..07a123bf8 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -196,14 +196,19 @@ class ChangesetController < ApplicationController ## # query changesets by bounding box, time, user or open/closed status. def query + # find any bounding box + if params['bbox'] + bbox = BoundingBox.from_bbox_params(params) + end + # create the conditions that the user asked for. some or all of # these may be nil. changesets = Changeset.scoped - changesets, bbox = conditions_bbox(changesets, params) - changesets = conditions_user(changesets, params['user'], params['display_name']) - changesets = conditions_time(changesets, params['time']) - changesets = conditions_open(changesets, params['open']) - changesets = conditions_closed(changesets, params['closed']) + changesets = conditions_bbox(changesets, bbox) + changesets = conditions_user(changesets, params['user'], params['display_name']) + changesets = conditions_time(changesets, params['time']) + changesets = conditions_open(changesets, params['open']) + changesets = conditions_closed(changesets, params['closed']) # create the results document results = OSM::API.new.get_xml_doc @@ -266,10 +271,15 @@ class ChangesetController < ApplicationController render :template => 'user/no_such_user', :status => :not_found end end - - changesets, bbox = conditions_bbox(changesets, params) + + if params[:bbox] + bbox = BoundingBox.from_bbox_params(params) + elsif params[:minlon] and params[:minlat] and params[:maxlon] and params[:maxlat] + bbox = BoundingBox.from_lon_lat_params(params) + end if bbox + changesets = conditions_bbox(changesets, bbox) bbox_link = render_to_string :partial => "bbox", :object => bbox end @@ -313,21 +323,15 @@ private # if a bounding box was specified do some sanity checks. # restrict changesets to those enclosed by a bounding box # we need to return both the changesets and the bounding box - def conditions_bbox(changesets, params) - if params[:bbox] - bbox = BoundingBox.from_bbox_params(params) - elsif params[:minlon] and params[:minlat] and params[:maxlon] and params[:maxlat] - bbox = BoundingBox.from_lon_lat_params(params) - end + def conditions_bbox(changesets, bbox) if bbox bbox.check_boundaries bbox = bbox.to_scaled return changesets.where("min_lon < ? and max_lon > ? and min_lat < ? and max_lat > ?", bbox.max_lon.to_i, bbox.min_lon.to_i, - bbox.max_lat.to_i, bbox.min_lat.to_i), - bbox + bbox.max_lat.to_i, bbox.min_lat.to_i) else - return changesets, bbox + return changesets end end