1 class SiteController < ApplicationController
3 layout :map_layout, :only => [:index, :export]
5 before_action :authorize_web
6 before_action :set_locale
7 before_action :redirect_browse_params, :only => :index
8 before_action :redirect_map_params, :only => [:index, :edit, :export]
9 before_action :require_oauth, :only => [:index]
10 before_action :update_totp, :only => [:index]
12 authorize_resource :class => false
15 session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"]) unless Settings.status == "database_readonly" || Settings.status == "database_offline"
19 lon, lat, zoom = ShortLink.decode(params[:code])
20 new_params = params.except(:host, :controller, :action, :code, :lon, :lat, :zoom, :layers, :node, :way, :relation, :changeset)
24 new_params[:mlat] = lat
25 new_params[:mlon] = lon
28 new_params[:anchor] = "map=#{zoom}/#{lat}/#{lon}"
29 new_params[:anchor] += "&layers=#{params[:layers]}" if params.key? :layers
31 options = new_params.to_unsafe_h.to_options
33 path = if params.key? :node
34 node_path(params[:node], options)
35 elsif params.key? :way
36 way_path(params[:way], options)
37 elsif params.key? :relation
38 relation_path(params[:relation], options)
39 elsif params.key? :changeset
40 changeset_path(params[:changeset], options)
49 expires_in 7.days, :public => true
50 render :layout => false
54 editor = preferred_editor
58 render :action => :index, :layout => map_layout
64 if %w[id].include?(editor)
65 append_content_security_policy_directives(
66 :frame_src => %w[blob:]
72 bbox = Node.visible.find(params[:node]).bbox.to_unscaled
73 @lat = bbox.centre_lat
74 @lon = bbox.centre_lon
77 bbox = Way.visible.find(params[:way]).bbox.to_unscaled
78 @lat = bbox.centre_lat
79 @lon = bbox.centre_lon
82 note = Note.visible.find(params[:note])
86 elsif params[:gpx] && current_user
87 trace = Trace.visible_to(current_user).find(params[:gpx])
89 @lon = trace.longitude
92 rescue ActiveRecord::RecordNotFound
93 # don't try and derive a location from a missing/deleted object
98 @locale = params[:copyright_locale] || I18n.locale
106 @locale = params[:about_locale] || I18n.locale
110 @locale = I18n.locale
111 @local_chapters = OsmCommunityIndex::LocalChapter.local_chapters_with_locale(@locale)
119 render :html => RichText.new(params[:type], params[:text]).to_html
123 append_content_security_policy_directives(
124 :connect_src => %w[*],
125 :img_src => %w[* blob:],
126 :script_src => %w[dev.virtualearth.net 'unsafe-eval'],
127 :style_src => %w['unsafe-inline']
130 render :layout => false
135 def redirect_browse_params
137 redirect_to node_path(params[:node])
139 redirect_to way_path(params[:way])
140 elsif params[:relation]
141 redirect_to relation_path(params[:relation])
143 redirect_to browse_note_path(params[:note])
145 redirect_to search_path(:query => params[:query])
149 def redirect_map_params
152 anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}" if params[:lat] && params[:lon]
155 anchor << "layers=#{params.delete(:layers)}"
156 elsif params.delete(:notes) == "yes"
160 redirect_to params.to_unsafe_h.merge(:only_path => true, :anchor => anchor.join("&")) if anchor.present?