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_user, :only => [:welcome]
10 before_action :require_oauth, :only => [:index]
11 before_action :update_totp, :only => [:index]
14 session[:location] ||= OSM.ip_location(request.env["REMOTE_ADDR"]) unless STATUS == :database_readonly || STATUS == :database_offline
18 lon, lat, zoom = ShortLink.decode(params[:code])
19 new_params = params.except(:code, :lon, :lat, :zoom, :layers, :node, :way, :relation, :changeset)
23 new_params[:mlat] = lat
24 new_params[:mlon] = lon
28 new_params[:controller] = "browse"
29 new_params[:action] = "node"
30 new_params[:id] = params[:node]
31 elsif params.key? :way
32 new_params[:controller] = "browse"
33 new_params[:action] = "way"
34 new_params[:id] = params[:way]
35 elsif params.key? :relation
36 new_params[:controller] = "browse"
37 new_params[:action] = "relation"
38 new_params[:id] = params[:relation]
39 elsif params.key? :changeset
40 new_params[:controller] = "browse"
41 new_params[:action] = "changeset"
42 new_params[:id] = params[:changeset]
44 new_params[:controller] = "site"
45 new_params[:action] = "index"
48 new_params[:anchor] = "map=#{zoom}/#{lat}/#{lon}"
49 new_params[:anchor] += "&layers=#{params[:layers]}" if params.key? :layers
51 redirect_to new_params.to_unsafe_h
55 expires_in 7.days, :public => true
56 render :layout => false
60 editor = preferred_editor
64 render :action => :index, :layout => map_layout
70 if %w[potlatch potlatch2].include?(editor)
71 append_content_security_policy_directives(
73 :plugin_types => %w[application/x-shockwave-flash],
74 :script_src => %w['unsafe-inline']
79 bbox = Node.find(params[:node]).bbox.to_unscaled
80 @lat = bbox.centre_lat
81 @lon = bbox.centre_lon
84 bbox = Way.find(params[:way]).bbox.to_unscaled
85 @lat = bbox.centre_lat
86 @lon = bbox.centre_lon
89 note = Note.find(params[:note])
93 elsif params[:gpx] && current_user
94 trace = Trace.visible_to(current_user).find(params[:gpx])
96 @lon = trace.longitude
102 @locale = params[:copyright_locale] || I18n.locale
116 render :html => RichText.new(params[:type], params[:text]).to_html
120 append_content_security_policy_directives(
121 :connect_src => %w[*],
122 :img_src => %w[* blob:],
123 :script_src => %w[dev.virtualearth.net *.wikipedia.org www.wikidata.org services.arcgisonline.com serviceslab.arcgisonline.com 'unsafe-eval'],
124 :style_src => %w['unsafe-inline']
127 render "id", :layout => false
132 def redirect_browse_params
134 redirect_to node_path(params[:node])
136 redirect_to way_path(params[:way])
137 elsif params[:relation]
138 redirect_to relation_path(params[:relation])
140 redirect_to browse_note_path(params[:note])
142 redirect_to search_path(:query => params[:query])
146 def redirect_map_params
149 anchor << "map=#{params.delete(:zoom) || 5}/#{params.delete(:lat)}/#{params.delete(:lon)}" if params[:lat] && params[:lon]
152 anchor << "layers=#{params.delete(:layers)}"
153 elsif params.delete(:notes) == "yes"
157 redirect_to params.to_unsafe_h.merge(:anchor => anchor.join("&")) if anchor.present?