-
Notifications
You must be signed in to change notification settings - Fork 937
/
Copy pathchangesets_controller.rb
137 lines (115 loc) · 5.35 KB
/
changesets_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# The ChangesetController is the RESTful interface to Changeset objects
class ChangesetsController < ApplicationController
include UserMethods
layout "site"
before_action :authorize_web
before_action :set_locale
before_action -> { check_database_readable(:need_api => true) }
before_action :require_oauth, :only => :show
authorize_resource
around_action :web_timeout
##
# list non-empty changesets in reverse chronological order
def index
param! :max_id, Integer, :min => 1
@params = params.permit(:display_name, :bbox, :friends, :nearby, :max_id, :list)
if request.format == :atom && @params[:max_id]
redirect_to url_for(@params.merge(:max_id => nil)), :status => :moved_permanently
return
end
if @params[:display_name]
user = User.find_by(:display_name => @params[:display_name])
if !user || !user.active?
render_unknown_user @params[:display_name]
return
end
end
if (@params[:friends] || @params[:nearby]) && !current_user
require_user
return
end
if request.format == :html && !@params[:list]
require_oauth
render :action => :history, :layout => map_layout
else
changesets = conditions_nonempty(Changeset.all)
if @params[:display_name]
changesets = if user.data_public? || user == current_user
changesets.where(:user => user)
else
changesets.where("false")
end
elsif @params[:bbox]
changesets = conditions_bbox(changesets, BoundingBox.from_bbox_params(params))
elsif @params[:friends] && current_user
changesets = changesets.where(:user => current_user.followings.identifiable)
elsif @params[:nearby] && current_user
changesets = changesets.where(:user => current_user.nearby)
end
changesets = changesets.where(:changesets => { :id => ..@params[:max_id] }) if @params[:max_id]
@changesets = changesets.order("changesets.id DESC").limit(20).preload(:user, :changeset_tags, :comments)
render :action => :index, :layout => false
end
end
##
# list edits as an atom feed
def feed
index
end
def show
@type = "changeset"
@changeset = Changeset.find(params[:id])
case turbo_frame_request_id
when "changeset_nodes"
@node_pages, @nodes = paginate(:old_nodes, :conditions => { :changeset_id => @changeset.id }, :order => [:node_id, :version], :per_page => 20, :parameter => "node_page")
render :partial => "elements", :locals => { :type => "node", :elements => @nodes, :pages => @node_pages }
when "changeset_ways"
@way_pages, @ways = paginate(:old_ways, :conditions => { :changeset_id => @changeset.id }, :order => [:way_id, :version], :per_page => 20, :parameter => "way_page")
render :partial => "elements", :locals => { :type => "way", :elements => @ways, :pages => @way_pages }
when "changeset_relations"
@relation_pages, @relations = paginate(:old_relations, :conditions => { :changeset_id => @changeset.id }, :order => [:relation_id, :version], :per_page => 20, :parameter => "relation_page")
render :partial => "elements", :locals => { :type => "relation", :elements => @relations, :pages => @relation_pages }
else
@comments = if current_user&.moderator?
@changeset.comments.unscope(:where => :visible).includes(:author)
else
@changeset.comments.includes(:author)
end
@node_pages, @nodes = paginate(:old_nodes, :conditions => { :changeset_id => @changeset.id }, :order => [:node_id, :version], :per_page => 20, :parameter => "node_page")
@way_pages, @ways = paginate(:old_ways, :conditions => { :changeset_id => @changeset.id }, :order => [:way_id, :version], :per_page => 20, :parameter => "way_page")
@relation_pages, @relations = paginate(:old_relations, :conditions => { :changeset_id => @changeset.id }, :order => [:relation_id, :version], :per_page => 20, :parameter => "relation_page")
if @changeset.user.active? && @changeset.user.data_public?
changesets = conditions_nonempty(@changeset.user.changesets)
@next_by_user = changesets.where("id > ?", @changeset.id).reorder(:id => :asc).first
@prev_by_user = changesets.where(:id => ...@changeset.id).reorder(:id => :desc).first
end
render :layout => map_layout
end
rescue ActiveRecord::RecordNotFound
render :template => "browse/not_found", :status => :not_found, :layout => map_layout
end
private
#------------------------------------------------------------
# utility functions below.
#------------------------------------------------------------
##
# if a bounding box was specified do some sanity checks.
# restrict changesets to those enclosed by a bounding box
def conditions_bbox(changesets, bbox)
if bbox
bbox.check_boundaries
bbox = bbox.to_scaled
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)
else
changesets
end
end
##
# eliminate empty changesets (where the bbox has not been set)
# this should be applied to all changeset list displays
def conditions_nonempty(changesets)
changesets.where("num_changes > 0")
end
end