X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/cf682f49b37a533e7e7aa5f8ea879ba970e88490..0f5e2c153a6b78e9ebde6093d05e364baf045d27:/app/controllers/changeset_controller.rb diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index 1b77d48ee..45b5f80f9 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -4,16 +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, :except => [:list, :list_user, :list_bbox] - around_filter :web_timeout, :only => [:list, :list_user, :list_bbox] + 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 @@ -431,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 @@ -439,7 +446,7 @@ private # eliminate empty changesets (where the bbox has not been set) # this should be applied to all changeset list displays def conditions_nonempty() - return ['min_lat IS NOT NULL'] + return ['num_changes > 0'] end end