]> git.openstreetmap.org Git - rails.git/blob - app/controllers/browse_controller.rb
Serve an updated TOTP token with the browse query response
[rails.git] / app / controllers / browse_controller.rb
1 class BrowseController < ApplicationController
2   layout :map_layout
3
4   before_action :authorize_web
5   before_action :set_locale
6   before_action -> { check_database_readable(:need_api => true) }
7   before_action :require_oauth
8   before_action :update_totp, :only => [:query]
9   around_action :web_timeout
10   authorize_resource :class => false
11
12   def relation
13     @type = "relation"
14     @feature = Relation.preload(:relation_tags, :containing_relation_members, :changeset => [:changeset_tags, :user], :relation_members => :member).find(params[:id])
15     render "feature"
16   rescue ActiveRecord::RecordNotFound
17     render :action => "not_found", :status => :not_found
18   end
19
20   def relation_history
21     @type = "relation"
22     @feature = Relation.preload(:relation_tags, :old_relations => [:old_tags, { :changeset => [:changeset_tags, :user], :old_members => :member }]).find(params[:id])
23     render "history"
24   rescue ActiveRecord::RecordNotFound
25     render :action => "not_found", :status => :not_found
26   end
27
28   def way
29     @type = "way"
30     @feature = Way.preload(:way_tags, :containing_relation_members, :changeset => [:changeset_tags, :user], :nodes => [:node_tags, { :ways => :way_tags }]).find(params[:id])
31     render "feature"
32   rescue ActiveRecord::RecordNotFound
33     render :action => "not_found", :status => :not_found
34   end
35
36   def way_history
37     @type = "way"
38     @feature = Way.preload(:way_tags, :old_ways => [:old_tags, { :changeset => [:changeset_tags, :user], :old_nodes => { :node => [:node_tags, :ways] } }]).find(params[:id])
39     render "history"
40   rescue ActiveRecord::RecordNotFound
41     render :action => "not_found", :status => :not_found
42   end
43
44   def node
45     @type = "node"
46     @feature = Node.preload(:node_tags, :containing_relation_members, :changeset => [:changeset_tags, :user], :ways => :way_tags).find(params[:id])
47     render "feature"
48   rescue ActiveRecord::RecordNotFound
49     render :action => "not_found", :status => :not_found
50   end
51
52   def node_history
53     @type = "node"
54     @feature = Node.preload(:node_tags, :old_nodes => [:old_tags, { :changeset => [:changeset_tags, :user] }]).find(params[:id])
55     render "history"
56   rescue ActiveRecord::RecordNotFound
57     render :action => "not_found", :status => :not_found
58   end
59
60   def changeset
61     @type = "changeset"
62     @changeset = Changeset.find(params[:id])
63     @comments = if current_user&.moderator?
64                   @changeset.comments.unscope(:where => :visible).includes(:author)
65                 else
66                   @changeset.comments.includes(:author)
67                 end
68     @node_pages, @nodes = paginate(:old_nodes, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "node_page")
69     @way_pages, @ways = paginate(:old_ways, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "way_page")
70     @relation_pages, @relations = paginate(:old_relations, :conditions => { :changeset_id => @changeset.id }, :per_page => 20, :parameter => "relation_page")
71     if @changeset.user.active? && @changeset.user.data_public?
72       @next_by_user = @changeset.user.changesets.where("id > ?", @changeset.id).reorder(:id => :asc).first
73       @prev_by_user = @changeset.user.changesets.where("id < ?", @changeset.id).reorder(:id => :desc).first
74     end
75   rescue ActiveRecord::RecordNotFound
76     render :action => "not_found", :status => :not_found
77   end
78
79   def note
80     @type = "note"
81
82     if current_user&.moderator?
83       @note = Note.find(params[:id])
84       @note_comments = @note.comments.unscope(:where => :visible)
85     else
86       @note = Note.visible.find(params[:id])
87       @note_comments = @note.comments
88     end
89   rescue ActiveRecord::RecordNotFound
90     render :action => "not_found", :status => :not_found
91   end
92
93   def query; end
94 end