X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/160429e62d88810ec49ccc9c504edee675dca080..c20b31b54ed3043e9ebf3964aa7c08f5ddc73a95:/app/controllers/changeset_controller.rb diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index d0a357c85..0aeaf200d 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -4,15 +4,17 @@ class ChangesetController < ApplicationController layout 'site' require 'xml/libxml' - before_filter :authorize_web, :only => [:list, :list_user, :list_bbox] - before_filter :set_locale, :only => [:list, :list_user, :list_bbox] + before_filter :authorize_web, :only => [:list] + before_filter :set_locale, :only => [:list] before_filter :authorize, :only => [:create, :update, :delete, :upload, :include, :close] before_filter :require_allow_write_api, :only => [:create, :update, :delete, :upload, :include, :close] before_filter :require_public_data, :only => [:create, :update, :delete, :upload, :include, :close] before_filter :check_api_writable, :only => [:create, :update, :delete, :upload, :include] - before_filter :check_api_readable, :except => [:create, :update, :delete, :upload, :download, :query] + before_filter :check_api_readable, :except => [:create, :update, :delete, :upload, :download, :query, :list] + before_filter(:only => [:list]) { |c| c.check_database_readable(true) } after_filter :compress_output - around_filter :api_call_handle_error + around_filter :api_call_handle_error, :except => [:list] + around_filter :web_timeout, :only => [:list] filter_parameter_logging " { :status => ["active", "confirmed"] }) + if request.format == :atom and params[:page] + redirect_to params.merge({ :page => nil }), :status => :moved_permanently + else + conditions = conditions_nonempty - if user - if user.data_public? or user == @user - conditions = cond_merge conditions, ['user_id = ?', user.id] - else - conditions = cond_merge conditions, ['false'] + if params[:display_name] + user = User.find_by_display_name(params[:display_name], :conditions => { :status => ["active", "confirmed"] }) + + if user + if user.data_public? or user == @user + conditions = cond_merge conditions, ['user_id = ?', user.id] + else + conditions = cond_merge conditions, ['false'] + end + elsif request.format == :html + @title = t 'user.no_such_user.title' + @not_found_user = params[:display_name] + render :template => 'user/no_such_user', :status => :not_found end - elsif request.format == :html - @title = t 'user.no_such_user.title' - @not_found_user = params[:display_name] - render :template => 'user/no_such_user', :status => :not_found end - end - - if params[:bbox] - bbox = params[:bbox] - elsif params[:minlon] and params[:minlat] and params[:maxlon] and params[:maxlat] - bbox = params[:minlon] + ',' + params[:minlat] + ',' + params[:maxlon] + ',' + params[:maxlat] - end - - if bbox - conditions = cond_merge conditions, conditions_bbox(bbox) - bbox = BoundingBox.from_s(bbox) - bbox_link = render_to_string :partial => "bbox", :object => bbox - end + + if params[:bbox] + bbox = params[:bbox] + elsif params[:minlon] and params[:minlat] and params[:maxlon] and params[:maxlat] + bbox = params[:minlon] + ',' + params[:minlat] + ',' + params[:maxlon] + ',' + params[:maxlat] + end + + if bbox + conditions = cond_merge conditions, conditions_bbox(bbox) + bbox = BoundingBox.from_s(bbox) + bbox_link = render_to_string :partial => "bbox", :object => bbox + end + + if user + user_link = render_to_string :partial => "user", :object => user + end + + if user and bbox + @title = t 'changeset.list.title_user_bbox', :user => user.display_name, :bbox => bbox.to_s + @heading = t 'changeset.list.heading_user_bbox', :user => user.display_name, :bbox => bbox.to_s + @description = t 'changeset.list.description_user_bbox', :user => user_link, :bbox => bbox_link + elsif user + @title = t 'changeset.list.title_user', :user => user.display_name + @heading = t 'changeset.list.heading_user', :user => user.display_name + @description = t 'changeset.list.description_user', :user => user_link + elsif bbox + @title = t 'changeset.list.title_bbox', :bbox => bbox.to_s + @heading = t 'changeset.list.heading_bbox', :bbox => bbox.to_s + @description = t 'changeset.list.description_bbox', :bbox => bbox_link + else + @title = t 'changeset.list.title' + @heading = t 'changeset.list.heading' + @description = t 'changeset.list.description' + end - if user - user_link = render_to_string :partial => "user", :object => user - end + @page = (params[:page] || 1).to_i + @page_size = 20 - if user and bbox - @title = t 'changeset.list.title_user_bbox', :user => user.display_name, :bbox => bbox.to_s - @heading = t 'changeset.list.heading_user_bbox', :user => user.display_name, :bbox => bbox.to_s - @description = t 'changeset.list.description_user_bbox', :user => user_link, :bbox => bbox_link - elsif user - @title = t 'changeset.list.title_user', :user => user.display_name - @heading = t 'changeset.list.heading_user', :user => user.display_name - @description = t 'changeset.list.description_user', :user => user_link - elsif bbox - @title = t 'changeset.list.title_bbox', :bbox => bbox.to_s - @heading = t 'changeset.list.heading_bbox', :bbox => bbox.to_s - @description = t 'changeset.list.description_bbox', :bbox => bbox_link - else - @title = t 'changeset.list.title' - @heading = t 'changeset.list.heading' - @description = t 'changeset.list.description' + @bbox = bbox + + @edits = Changeset.find(:all, + :include => [:user, :changeset_tags], + :conditions => conditions, + :order => "changesets.created_at DESC", + :offset => (@page - 1) * @page_size, + :limit => @page_size) end - - @page = (params[:page] || 1).to_i - @page_size = 20 - - @edits = Changeset.find(:all, - :include => [:user, :changeset_tags], - :conditions => conditions, - :order => "changesets.created_at DESC", - :offset => (@page - 1) * @page_size, - :limit => @page_size) end private @@ -345,7 +353,10 @@ private raise OSM::APIBadUserInput.new("Minimum longitude should be less than maximum.") unless bbox[0] <= bbox[2] raise OSM::APIBadUserInput.new("Minimum latitude should be less than maximum.") unless bbox[1] <= bbox[3] return ['min_lon < ? and max_lon > ? and min_lat < ? and max_lat > ?', - bbox[2] * GeoRecord::SCALE, bbox[0] * GeoRecord::SCALE, bbox[3]* GeoRecord::SCALE, bbox[1] * GeoRecord::SCALE] + (bbox[2] * GeoRecord::SCALE).to_i, + (bbox[0] * GeoRecord::SCALE).to_i, + (bbox[3] * GeoRecord::SCALE).to_i, + (bbox[1] * GeoRecord::SCALE).to_i] else return nil end @@ -427,7 +438,7 @@ private # query changesets which are closed # ('closed at' time has passed or changes limit is hit) def conditions_closed(closed) - return closed.nil? ? nil : ['closed_at < ? or num_changes > ?', + return closed.nil? ? nil : ['(closed_at < ? or num_changes > ?)', Time.now.getutc, Changeset::MAX_ELEMENTS] end