]> git.openstreetmap.org Git - rails.git/blob - app/controllers/browse_controller.rb
db291f6eb89a8fc5900cd8c4da953f987473c55e
[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   before_action :require_moderator_for_unredacted_history, :only => [:relation_history, :way_history, :node_history]
10   around_action :web_timeout
11   authorize_resource :class => false
12
13   def relation
14     @type = "relation"
15     @feature = Relation.preload(:relation_tags, :containing_relation_members, :changeset => [:changeset_tags, :user], :relation_members => :member).find(params[:id])
16     render "feature"
17   rescue ActiveRecord::RecordNotFound
18     render :action => "not_found", :status => :not_found
19   end
20
21   def relation_history
22     @type = "relation"
23     @feature = Relation.preload(:relation_tags, :old_relations => [:old_tags, { :changeset => [:changeset_tags, :user], :old_members => :member }]).find(params[:id])
24     render "history"
25   rescue ActiveRecord::RecordNotFound
26     render :action => "not_found", :status => :not_found
27   end
28
29   def way
30     @type = "way"
31     @feature = Way.preload(:way_tags, :containing_relation_members, :changeset => [:changeset_tags, :user], :nodes => [:node_tags, { :ways => :way_tags }]).find(params[:id])
32     render "feature"
33   rescue ActiveRecord::RecordNotFound
34     render :action => "not_found", :status => :not_found
35   end
36
37   def way_history
38     @type = "way"
39     @feature = Way.preload(:way_tags, :old_ways => [:old_tags, { :changeset => [:changeset_tags, :user], :old_nodes => { :node => [:node_tags, :ways] } }]).find(params[:id])
40     render "history"
41   rescue ActiveRecord::RecordNotFound
42     render :action => "not_found", :status => :not_found
43   end
44
45   def node
46     @type = "node"
47     @feature = Node.preload(:node_tags, :containing_relation_members, :changeset => [:changeset_tags, :user], :ways => :way_tags).find(params[:id])
48     render "feature"
49   rescue ActiveRecord::RecordNotFound
50     render :action => "not_found", :status => :not_found
51   end
52
53   def node_history
54     @type = "node"
55     @feature = Node.preload(:node_tags, :old_nodes => [:old_tags, { :changeset => [:changeset_tags, :user] }]).find(params[:id])
56     render "history"
57   rescue ActiveRecord::RecordNotFound
58     render :action => "not_found", :status => :not_found
59   end
60
61   def query; end
62
63   private
64
65   def require_moderator_for_unredacted_history
66     deny_access(nil) if params[:show_redactions] && !current_user&.moderator?
67   end
68 end