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