1 # The ChangesetController is the RESTful interface to Changeset objects
3 class ChangesetsController < ApplicationController
7 before_action :authorize_web
8 before_action :set_locale
9 before_action -> { check_database_readable(true) }, :only => [:index, :feed]
13 around_action :web_timeout
15 # Helper methods for checking consistency
16 include ConsistencyValidations
19 # list non-empty changesets in reverse chronological order
21 @params = params.permit(:display_name, :bbox, :friends, :nearby, :max_id, :list)
23 if request.format == :atom && @params[:max_id]
24 redirect_to url_for(@params.merge(:max_id => nil)), :status => :moved_permanently
28 if @params[:display_name]
29 user = User.find_by(:display_name => @params[:display_name])
30 if !user || !user.active?
31 render_unknown_user @params[:display_name]
36 if (@params[:friends] || @params[:nearby]) && !current_user
41 if request.format == :html && !@params[:list]
43 render :action => :history, :layout => map_layout
45 changesets = conditions_nonempty(Changeset.all)
47 if @params[:display_name]
48 changesets = if user.data_public? || user == current_user
49 changesets.where(:user_id => user.id)
51 changesets.where("false")
54 changesets = conditions_bbox(changesets, BoundingBox.from_bbox_params(params))
55 elsif @params[:friends] && current_user
56 changesets = changesets.where(:user_id => current_user.friends.identifiable)
57 elsif @params[:nearby] && current_user
58 changesets = changesets.where(:user_id => current_user.nearby)
61 changesets = changesets.where("changesets.id <= ?", @params[:max_id]) if @params[:max_id]
63 @changesets = changesets.order("changesets.id DESC").limit(20).preload(:user, :changeset_tags, :comments)
65 render :action => :index, :layout => false
70 # list edits as an atom feed
77 #------------------------------------------------------------
78 # utility functions below.
79 #------------------------------------------------------------
82 # if a bounding box was specified do some sanity checks.
83 # restrict changesets to those enclosed by a bounding box
84 # we need to return both the changesets and the bounding box
85 def conditions_bbox(changesets, bbox)
90 changesets.where("min_lon < ? and max_lon > ? and min_lat < ? and max_lat > ?",
91 bbox.max_lon.to_i, bbox.min_lon.to_i,
92 bbox.max_lat.to_i, bbox.min_lat.to_i)
99 # eliminate empty changesets (where the bbox has not been set)
100 # this should be applied to all changeset list displays
101 def conditions_nonempty(changesets)
102 changesets.where("num_changes > 0")