Rework application configuration
Use a preinitializer to load the settings from application.yml so that they are available as early as possible. All settings can also be overridden using environment variables. The ad-hoc settins in environment.rb are then moved to this new system so we have one consistent location for settings.
This commit is contained in:
parent
8b9cacd3c2
commit
f07819d81a
33 changed files with 100 additions and 99 deletions
|
@ -172,7 +172,7 @@ class AmfController < ApplicationController
|
||||||
|
|
||||||
def amf_handle_error_with_timeout(call,rootobj,rootid)
|
def amf_handle_error_with_timeout(call,rootobj,rootid)
|
||||||
amf_handle_error(call,rootobj,rootid) do
|
amf_handle_error(call,rootobj,rootid) do
|
||||||
Timeout::timeout(APP_CONFIG['api_timeout'], OSM::APITimeoutError) do
|
Timeout::timeout(API_TIMEOUT, OSM::APITimeoutError) do
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,7 +18,7 @@ class ApiController < ApplicationController
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
offset = page * APP_CONFIG['tracepoints_per_page']
|
offset = page * TRACEPOINTS_PER_PAGE
|
||||||
|
|
||||||
# Figure out the bbox
|
# Figure out the bbox
|
||||||
bbox = params['bbox']
|
bbox = params['bbox']
|
||||||
|
@ -39,7 +39,7 @@ class ApiController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# get all the points
|
# get all the points
|
||||||
points = Tracepoint.find_by_area(min_lat, min_lon, max_lat, max_lon, :offset => offset, :limit => APP_CONFIG['tracepoints_per_page'], :order => "gpx_id DESC, trackid ASC, timestamp ASC" )
|
points = Tracepoint.find_by_area(min_lat, min_lon, max_lat, max_lon, :offset => offset, :limit => TRACEPOINTS_PER_PAGE, :order => "gpx_id DESC, trackid ASC, timestamp ASC" )
|
||||||
|
|
||||||
doc = XML::Document.new
|
doc = XML::Document.new
|
||||||
doc.encoding = XML::Encoding::UTF_8
|
doc.encoding = XML::Encoding::UTF_8
|
||||||
|
@ -145,14 +145,14 @@ class ApiController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# FIXME um why is this area using a different order for the lat/lon from above???
|
# FIXME um why is this area using a different order for the lat/lon from above???
|
||||||
@nodes = Node.find_by_area(min_lat, min_lon, max_lat, max_lon, :conditions => {:visible => true}, :include => :node_tags, :limit => APP_CONFIG['max_number_of_nodes']+1)
|
@nodes = Node.find_by_area(min_lat, min_lon, max_lat, max_lon, :conditions => {:visible => true}, :include => :node_tags, :limit => MAX_NUMBER_OF_NODES+1)
|
||||||
# get all the nodes, by tag not yet working, waiting for change from NickB
|
# get all the nodes, by tag not yet working, waiting for change from NickB
|
||||||
# need to be @nodes (instance var) so tests in /spec can be performed
|
# need to be @nodes (instance var) so tests in /spec can be performed
|
||||||
#@nodes = Node.search(bbox, params[:tag])
|
#@nodes = Node.search(bbox, params[:tag])
|
||||||
|
|
||||||
node_ids = @nodes.collect(&:id)
|
node_ids = @nodes.collect(&:id)
|
||||||
if node_ids.length > APP_CONFIG['max_number_of_nodes']
|
if node_ids.length > MAX_NUMBER_OF_NODES
|
||||||
report_error("You requested too many nodes (limit is #{APP_CONFIG['max_number_of_nodes']}). Either request a smaller area, or use planet.osm")
|
report_error("You requested too many nodes (limit is #{MAX_NUMBER_OF_NODES}). Either request a smaller area, or use planet.osm")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if node_ids.length == 0
|
if node_ids.length == 0
|
||||||
|
@ -295,19 +295,19 @@ class ApiController < ApplicationController
|
||||||
version['maximum'] = "#{API_VERSION}";
|
version['maximum'] = "#{API_VERSION}";
|
||||||
api << version
|
api << version
|
||||||
area = XML::Node.new 'area'
|
area = XML::Node.new 'area'
|
||||||
area['maximum'] = APP_CONFIG['max_request_area'].to_s;
|
area['maximum'] = MAX_REQUEST_AREA.to_s;
|
||||||
api << area
|
api << area
|
||||||
tracepoints = XML::Node.new 'tracepoints'
|
tracepoints = XML::Node.new 'tracepoints'
|
||||||
tracepoints['per_page'] = APP_CONFIG['tracepoints_per_page'].to_s
|
tracepoints['per_page'] = TRACEPOINTS_PER_PAGE.to_s
|
||||||
api << tracepoints
|
api << tracepoints
|
||||||
waynodes = XML::Node.new 'waynodes'
|
waynodes = XML::Node.new 'waynodes'
|
||||||
waynodes['maximum'] = APP_CONFIG['max_number_of_way_nodes'].to_s
|
waynodes['maximum'] = MAX_NUMBER_OF_WAY_NODES.to_s
|
||||||
api << waynodes
|
api << waynodes
|
||||||
changesets = XML::Node.new 'changesets'
|
changesets = XML::Node.new 'changesets'
|
||||||
changesets['maximum_elements'] = Changeset::MAX_ELEMENTS.to_s
|
changesets['maximum_elements'] = Changeset::MAX_ELEMENTS.to_s
|
||||||
api << changesets
|
api << changesets
|
||||||
timeout = XML::Node.new 'timeout'
|
timeout = XML::Node.new 'timeout'
|
||||||
timeout['seconds'] = APP_CONFIG['api_timeout'].to_s
|
timeout['seconds'] = API_TIMEOUT.to_s
|
||||||
api << timeout
|
api << timeout
|
||||||
|
|
||||||
doc.root << api
|
doc.root << api
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# Likewise, all the methods added will be available for all controllers.
|
# Likewise, all the methods added will be available for all controllers.
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
if OSM_STATUS == :database_readonly or OSM_STATUS == :database_offline
|
if STATUS == :database_readonly or STATUS == :database_offline
|
||||||
session :off
|
session :off
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -120,20 +120,20 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_database_readable(need_api = false)
|
def check_database_readable(need_api = false)
|
||||||
if OSM_STATUS == :database_offline or (need_api and OSM_STATUS == :api_offline)
|
if STATUS == :database_offline or (need_api and STATUS == :api_offline)
|
||||||
redirect_to :controller => 'site', :action => 'offline'
|
redirect_to :controller => 'site', :action => 'offline'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_database_writable(need_api = false)
|
def check_database_writable(need_api = false)
|
||||||
if OSM_STATUS == :database_offline or OSM_STATUS == :database_readonly or
|
if STATUS == :database_offline or STATUS == :database_readonly or
|
||||||
(need_api and (OSM_STATUS == :api_offline or OSM_STATUS == :api_readonly))
|
(need_api and (STATUS == :api_offline or STATUS == :api_readonly))
|
||||||
redirect_to :controller => 'site', :action => 'offline'
|
redirect_to :controller => 'site', :action => 'offline'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_api_readable
|
def check_api_readable
|
||||||
if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline
|
if STATUS == :database_offline or STATUS == :api_offline
|
||||||
response.headers['Error'] = "Database offline for maintenance"
|
response.headers['Error'] = "Database offline for maintenance"
|
||||||
render :nothing => true, :status => :service_unavailable
|
render :nothing => true, :status => :service_unavailable
|
||||||
return false
|
return false
|
||||||
|
@ -141,8 +141,8 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_api_writable
|
def check_api_writable
|
||||||
if OSM_STATUS == :database_offline or OSM_STATUS == :database_readonly or
|
if STATUS == :database_offline or STATUS == :database_readonly or
|
||||||
OSM_STATUS == :api_offline or OSM_STATUS == :api_readonly
|
STATUS == :api_offline or STATUS == :api_readonly
|
||||||
response.headers['Error'] = "Database offline for maintenance"
|
response.headers['Error'] = "Database offline for maintenance"
|
||||||
render :nothing => true, :status => :service_unavailable
|
render :nothing => true, :status => :service_unavailable
|
||||||
return false
|
return false
|
||||||
|
@ -219,7 +219,7 @@ class ApplicationController < ActionController::Base
|
||||||
##
|
##
|
||||||
# wrap an api call in a timeout
|
# wrap an api call in a timeout
|
||||||
def api_call_timeout
|
def api_call_timeout
|
||||||
SystemTimer.timeout_after(APP_CONFIG['api_timeout']) do
|
SystemTimer.timeout_after(API_TIMEOUT) do
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
rescue Timeout::Error
|
rescue Timeout::Error
|
||||||
|
@ -229,7 +229,7 @@ class ApplicationController < ActionController::Base
|
||||||
##
|
##
|
||||||
# wrap a web page in a timeout
|
# wrap a web page in a timeout
|
||||||
def web_timeout
|
def web_timeout
|
||||||
SystemTimer.timeout_after(APP_CONFIG['web_timeout']) do
|
SystemTimer.timeout_after(WEB_TIMEOUT) do
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
rescue ActionView::TemplateError => ex
|
rescue ActionView::TemplateError => ex
|
||||||
|
|
|
@ -10,7 +10,7 @@ class DiaryEntryController < ApplicationController
|
||||||
|
|
||||||
caches_action :list, :view, :layout => false
|
caches_action :list, :view, :layout => false
|
||||||
caches_action :rss, :layout => true
|
caches_action :rss, :layout => true
|
||||||
cache_sweeper :diary_sweeper, :only => [:new, :edit, :comment, :hide, :hidecomment], :unless => OSM_STATUS == :database_offline
|
cache_sweeper :diary_sweeper, :only => [:new, :edit, :comment, :hide, :hidecomment], :unless => STATUS == :database_offline
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@title = t 'diary_entry.new.title'
|
@title = t 'diary_entry.new.title'
|
||||||
|
|
|
@ -57,7 +57,7 @@ class GeocoderController < ApplicationController
|
||||||
render :action => "error"
|
render :action => "error"
|
||||||
else
|
else
|
||||||
@results.push({:lat => lat, :lon => lon,
|
@results.push({:lat => lat, :lon => lon,
|
||||||
:zoom => APP_CONFIG['postcode_zoom'],
|
:zoom => POSTCODE_ZOOM,
|
||||||
:name => "#{lat}, #{lon}"})
|
:name => "#{lat}, #{lon}"})
|
||||||
|
|
||||||
render :action => "results"
|
render :action => "results"
|
||||||
|
@ -78,7 +78,7 @@ class GeocoderController < ApplicationController
|
||||||
unless response.match(/couldn't find this zip/)
|
unless response.match(/couldn't find this zip/)
|
||||||
data = response.split(/\s*,\s+/) # lat,long,town,state,zip
|
data = response.split(/\s*,\s+/) # lat,long,town,state,zip
|
||||||
@results.push({:lat => data[0], :lon => data[1],
|
@results.push({:lat => data[0], :lon => data[1],
|
||||||
:zoom => APP_CONFIG['postcode_zoom'],
|
:zoom => POSTCODE_ZOOM,
|
||||||
:prefix => "#{data[2]}, #{data[3]},",
|
:prefix => "#{data[2]}, #{data[3]},",
|
||||||
:name => data[4]})
|
:name => data[4]})
|
||||||
end
|
end
|
||||||
|
@ -104,7 +104,7 @@ class GeocoderController < ApplicationController
|
||||||
dataline = response.split(/\n/)[1]
|
dataline = response.split(/\n/)[1]
|
||||||
data = dataline.split(/,/) # easting,northing,postcode,lat,long
|
data = dataline.split(/,/) # easting,northing,postcode,lat,long
|
||||||
postcode = data[2].gsub(/'/, "")
|
postcode = data[2].gsub(/'/, "")
|
||||||
zoom = APP_CONFIG['postcode_zoom'] - postcode.count("#")
|
zoom = POSTCODE_ZOOM - postcode.count("#")
|
||||||
@results.push({:lat => data[3], :lon => data[4], :zoom => zoom,
|
@results.push({:lat => data[3], :lon => data[4], :zoom => zoom,
|
||||||
:name => postcode})
|
:name => postcode})
|
||||||
end
|
end
|
||||||
|
@ -127,7 +127,7 @@ class GeocoderController < ApplicationController
|
||||||
if response.get_elements("geodata/error").empty?
|
if response.get_elements("geodata/error").empty?
|
||||||
@results.push({:lat => response.get_text("geodata/latt").to_s,
|
@results.push({:lat => response.get_text("geodata/latt").to_s,
|
||||||
:lon => response.get_text("geodata/longt").to_s,
|
:lon => response.get_text("geodata/longt").to_s,
|
||||||
:zoom => APP_CONFIG['postcode_zoom'],
|
:zoom => POSTCODE_ZOOM,
|
||||||
:name => query.upcase})
|
:name => query.upcase})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ class GeocoderController < ApplicationController
|
||||||
name = geoname.get_text("name").to_s
|
name = geoname.get_text("name").to_s
|
||||||
country = geoname.get_text("countryName").to_s
|
country = geoname.get_text("countryName").to_s
|
||||||
@results.push({:lat => lat, :lon => lon,
|
@results.push({:lat => lat, :lon => lon,
|
||||||
:zoom => APP_CONFIG['geonames_zoom'],
|
:zoom => GEONAMES_ZOOM,
|
||||||
:name => name,
|
:name => name,
|
||||||
:suffix => ", #{country}"})
|
:suffix => ", #{country}"})
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ class MessageController < ApplicationController
|
||||||
@to_user = User.find_by_display_name(params[:display_name])
|
@to_user = User.find_by_display_name(params[:display_name])
|
||||||
if @to_user
|
if @to_user
|
||||||
if params[:message]
|
if params[:message]
|
||||||
if @user.sent_messages.count(:conditions => ["sent_on >= ?", Time.now.getutc - 1.hour]) >= APP_CONFIG['max_messages_per_hour']
|
if @user.sent_messages.count(:conditions => ["sent_on >= ?", Time.now.getutc - 1.hour]) >= MAX_MESSAGES_PER_HOUR
|
||||||
flash[:error] = t 'message.new.limit_exceeded'
|
flash[:error] = t 'message.new.limit_exceeded'
|
||||||
else
|
else
|
||||||
@message = Message.new(params[:message])
|
@message = Message.new(params[:message])
|
||||||
|
|
|
@ -17,8 +17,8 @@ class TraceController < ApplicationController
|
||||||
|
|
||||||
caches_action :list, :view, :layout => false
|
caches_action :list, :view, :layout => false
|
||||||
caches_action :georss, :layout => true
|
caches_action :georss, :layout => true
|
||||||
cache_sweeper :trace_sweeper, :only => [:create, :edit, :delete, :api_create], :unless => OSM_STATUS == :database_offline
|
cache_sweeper :trace_sweeper, :only => [:create, :edit, :delete, :api_create], :unless => STATUS == :database_offline
|
||||||
cache_sweeper :tracetag_sweeper, :only => [:create, :edit, :delete, :api_create], :unless => OSM_STATUS == :database_offline
|
cache_sweeper :tracetag_sweeper, :only => [:create, :edit, :delete, :api_create], :unless => STATUS == :database_offline
|
||||||
|
|
||||||
# Counts and selects pages of GPX traces for various criteria (by user, tags, public etc.).
|
# Counts and selects pages of GPX traces for various criteria (by user, tags, public etc.).
|
||||||
# target_user - if set, specifies the user to fetch traces for. if not set will fetch all traces
|
# target_user - if set, specifies the user to fetch traces for. if not set will fetch all traces
|
||||||
|
@ -395,11 +395,11 @@ private
|
||||||
end
|
end
|
||||||
|
|
||||||
def offline_warning
|
def offline_warning
|
||||||
flash.now[:warning] = t 'trace.offline_warning.message' if OSM_STATUS == :gpx_offline
|
flash.now[:warning] = t 'trace.offline_warning.message' if STATUS == :gpx_offline
|
||||||
end
|
end
|
||||||
|
|
||||||
def offline_redirect
|
def offline_redirect
|
||||||
redirect_to :action => :offline if OSM_STATUS == :gpx_offline
|
redirect_to :action => :offline if STATUS == :gpx_offline
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_visibility
|
def default_visibility
|
||||||
|
|
|
@ -16,13 +16,13 @@ class UserController < ApplicationController
|
||||||
|
|
||||||
filter_parameter_logging :password, :pass_crypt, :pass_crypt_confirmation
|
filter_parameter_logging :password, :pass_crypt, :pass_crypt_confirmation
|
||||||
|
|
||||||
cache_sweeper :user_sweeper, :only => [:account, :set_status, :delete], :unless => OSM_STATUS == :database_offline
|
cache_sweeper :user_sweeper, :only => [:account, :set_status, :delete], :unless => STATUS == :database_offline
|
||||||
|
|
||||||
def terms
|
def terms
|
||||||
@title = t 'user.new.title'
|
@title = t 'user.new.title'
|
||||||
@user = User.new(params[:user])
|
@user = User.new(params[:user])
|
||||||
|
|
||||||
@legale = params[:legale] || OSM.IPToCountry(request.remote_ip) || APP_CONFIG['default_legale']
|
@legale = params[:legale] || OSM.IPToCountry(request.remote_ip) || DEFAULT_LEGALE
|
||||||
@text = OSM.legal_text_for_country(@legale)
|
@text = OSM.legal_text_for_country(@legale)
|
||||||
|
|
||||||
if request.xhr?
|
if request.xhr?
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Node < ActiveRecord::Base
|
||||||
|
|
||||||
find_by_area(min_lat, min_lon, max_lat, max_lon,
|
find_by_area(min_lat, min_lon, max_lat, max_lon,
|
||||||
:conditions => {:visible => true},
|
:conditions => {:visible => true},
|
||||||
:limit => APP_CONFIG['max_number_of_nodes']+1)
|
:limit => MAX_NUMBER_OF_NODES+1)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Read in xml as text and return it's Node object representation
|
# Read in xml as text and return it's Node object representation
|
||||||
|
|
|
@ -105,7 +105,7 @@ private
|
||||||
end
|
end
|
||||||
|
|
||||||
def from_header(name, type, id, digest)
|
def from_header(name, type, id, digest)
|
||||||
if domain = APP_CONFIG['messages_domain']
|
if domain = MESSAGES_DOMAIN
|
||||||
from quote_address_if_necessary("#{name} <#{type}-#{id}-#{digest[0,6]}@#{domain}>", "utf-8")
|
from quote_address_if_necessary("#{name} <#{type}-#{id}-#{digest[0,6]}@#{domain}>", "utf-8")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ class SpamObserver < ActiveRecord::Observer
|
||||||
when record.is_a?(DiaryComment): user = record.user
|
when record.is_a?(DiaryComment): user = record.user
|
||||||
end
|
end
|
||||||
|
|
||||||
if user.status == "active" and user.spam_score > APP_CONFIG['spam_threshold']
|
if user.status == "active" and user.spam_score > SPAM_THRESHOLD
|
||||||
user.update_attributes(:status => "suspended")
|
user.update_attributes(:status => "suspended")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,7 +5,7 @@ class UserBlock < ActiveRecord::Base
|
||||||
belongs_to :creator, :class_name => "User", :foreign_key => :creator_id
|
belongs_to :creator, :class_name => "User", :foreign_key => :creator_id
|
||||||
belongs_to :revoker, :class_name => "User", :foreign_key => :revoker_id
|
belongs_to :revoker, :class_name => "User", :foreign_key => :revoker_id
|
||||||
|
|
||||||
PERIODS = APP_CONFIG['user_block_periods']
|
PERIODS = USER_BLOCK_PERIODS
|
||||||
|
|
||||||
##
|
##
|
||||||
# returns true if the block is currently active (i.e: the user can't
|
# returns true if the block is currently active (i.e: the user can't
|
||||||
|
|
|
@ -234,8 +234,8 @@ class Way < ActiveRecord::Base
|
||||||
|
|
||||||
def preconditions_ok?(old_nodes = [])
|
def preconditions_ok?(old_nodes = [])
|
||||||
return false if self.nds.empty?
|
return false if self.nds.empty?
|
||||||
if self.nds.length > APP_CONFIG['max_number_of_way_nodes']
|
if self.nds.length > MAX_NUMBER_OF_WAY_NODES
|
||||||
raise OSM::APITooManyWayNodesError.new(self.id, self.nds.length, APP_CONFIG['max_number_of_way_nodes'])
|
raise OSM::APITooManyWayNodesError.new(self.id, self.nds.length, MAX_NUMBER_OF_WAY_NODES)
|
||||||
end
|
end
|
||||||
|
|
||||||
# check only the new nodes, for efficiency - old nodes having been checked last time and can't
|
# check only the new nodes, for efficiency - old nodes having been checked last time and can't
|
||||||
|
|
|
@ -185,8 +185,8 @@ page << <<EOJ
|
||||||
var projected = bounds.clone().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
|
var projected = bounds.clone().transform(new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));
|
||||||
var size = projected.getWidth() * projected.getHeight();
|
var size = projected.getWidth() * projected.getHeight();
|
||||||
|
|
||||||
if (size > #{APP_CONFIG['max_request_area']}) {
|
if (size > #{MAX_REQUEST_AREA}) {
|
||||||
setStatus(i18n("#{I18n.t('browse.start_rjs.unable_to_load_size', :max_bbox_size => APP_CONFIG['max_request_area'])}", { bbox_size: size }));
|
setStatus(i18n("#{I18n.t('browse.start_rjs.unable_to_load_size', :max_bbox_size => MAX_REQUEST_AREA)}", { bbox_size: size }));
|
||||||
} else {
|
} else {
|
||||||
loadGML("/api/#{API_VERSION}/map?bbox=" + projected.toBBOX());
|
loadGML("/api/#{API_VERSION}/map?bbox=" + projected.toBBOX());
|
||||||
}
|
}
|
||||||
|
|
|
@ -190,7 +190,7 @@ page << <<EOJ
|
||||||
function validateControls() {
|
function validateControls() {
|
||||||
var bounds = new OpenLayers.Bounds($("minlon").value, $("minlat").value, $("maxlon").value, $("maxlat").value);
|
var bounds = new OpenLayers.Bounds($("minlon").value, $("minlat").value, $("maxlon").value, $("maxlat").value);
|
||||||
|
|
||||||
if (bounds.getWidth() * bounds.getHeight() > #{APP_CONFIG['max_request_area']}) {
|
if (bounds.getWidth() * bounds.getHeight() > #{MAX_REQUEST_AREA}) {
|
||||||
$("export_osm_too_large").style.display = "block";
|
$("export_osm_too_large").style.display = "block";
|
||||||
} else {
|
} else {
|
||||||
$("export_osm_too_large").style.display = "none";
|
$("export_osm_too_large").style.display = "none";
|
||||||
|
@ -198,7 +198,7 @@ page << <<EOJ
|
||||||
|
|
||||||
var max_scale = maxMapnikScale();
|
var max_scale = maxMapnikScale();
|
||||||
|
|
||||||
if ($("format_osm").checked && bounds.getWidth() * bounds.getHeight() > #{APP_CONFIG['max_request_area']}) {
|
if ($("format_osm").checked && bounds.getWidth() * bounds.getHeight() > #{MAX_REQUEST_AREA}) {
|
||||||
$("export_commit").disabled = true;
|
$("export_commit").disabled = true;
|
||||||
} else if ($("format_mapnik").checked && $("mapnik_scale").value < max_scale) {
|
} else if ($("format_mapnik").checked && $("mapnik_scale").value < max_scale) {
|
||||||
$("export_commit").disabled = true;
|
$("export_commit").disabled = true;
|
||||||
|
|
|
@ -100,11 +100,11 @@
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline %>
|
<% if STATUS == :database_offline or STATUS == :api_offline %>
|
||||||
<div id="alert">
|
<div id="alert">
|
||||||
<%= t 'layouts.osm_offline' %>
|
<%= t 'layouts.osm_offline' %>
|
||||||
</div>
|
</div>
|
||||||
<% elsif OSM_STATUS == :database_readonly or OSM_STATUS == :api_readonly %>
|
<% elsif STATUS == :database_readonly or STATUS == :api_readonly %>
|
||||||
<div id="alert">
|
<div id="alert">
|
||||||
<%= t 'layouts.osm_read_only' %>
|
<%= t 'layouts.osm_read_only' %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<% if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline %>
|
<% if STATUS == :database_offline or STATUS == :api_offline %>
|
||||||
<p><%= t 'layouts.osm_offline' %>
|
<p><%= t 'layouts.osm_offline' %>
|
||||||
</p>
|
</p>
|
||||||
<% elsif OSM_STATUS == :database_readonly or OSM_STATUS == :api_readonly %>
|
<% elsif STATUS == :database_readonly or STATUS == :api_readonly %>
|
||||||
<p><%= t 'layouts.osm_read_only' %>
|
<p><%= t 'layouts.osm_read_only' %>
|
||||||
</p>
|
</p>
|
||||||
<% elsif !@user.data_public? %>
|
<% elsif !@user.data_public? %>
|
||||||
|
|
|
@ -125,7 +125,7 @@ end
|
||||||
function mapInit(){
|
function mapInit(){
|
||||||
map = createMap("map");
|
map = createMap("map");
|
||||||
|
|
||||||
<% unless OSM_STATUS == :api_offline or OSM_STATUS == :database_offline %>
|
<% unless STATUS == :api_offline or STATUS == :database_offline %>
|
||||||
map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
|
map.dataLayer = new OpenLayers.Layer("<%= I18n.t 'browse.start_rjs.data_layer_name' %>", { "visibility": false });
|
||||||
map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
|
map.dataLayer.events.register("visibilitychanged", map.dataLayer, toggleData);
|
||||||
map.addLayer(map.dataLayer);
|
map.addLayer(map.dataLayer);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<% if OSM_STATUS == :database_offline %>
|
<% if STATUS == :database_offline %>
|
||||||
<p><%= t 'layouts.osm_offline' %>
|
<p><%= t 'layouts.osm_offline' %>
|
||||||
</p>
|
</p>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<% cl = cycle('table0', 'table1') %>
|
<% cl = cycle('table0', 'table1') %>
|
||||||
<td class="<%= cl %>">
|
<td class="<%= cl %>">
|
||||||
<% if OSM_STATUS != :gpx_offline %>
|
<% if STATUS != :gpx_offline %>
|
||||||
<% if trace.inserted %>
|
<% if trace.inserted %>
|
||||||
<a href="<%= url_for :controller => 'trace', :action => 'view', :id => trace.id, :display_name => trace.user.display_name %>"><img src="<%= url_for :controller => 'trace', :action => 'icon', :id => trace.id, :display_name => trace.user.display_name %>" border="0" alt="" /></a>
|
<a href="<%= url_for :controller => 'trace', :action => 'view', :id => trace.id, :display_name => trace.user.display_name %>"><img src="<%= url_for :controller => 'trace', :action => 'icon', :id => trace.id, :display_name => trace.user.display_name %>" border="0" alt="" /></a>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<h2><%= t 'trace.view.heading', :name => h(@trace.name) %></h2>
|
<h2><%= t 'trace.view.heading', :name => h(@trace.name) %></h2>
|
||||||
|
|
||||||
<% if OSM_STATUS != :gpx_offline %>
|
<% if STATUS != :gpx_offline %>
|
||||||
<% if @trace.inserted %>
|
<% if @trace.inserted %>
|
||||||
<img src="<%= url_for :controller => 'trace', :action => 'picture', :id => @trace.id, :display_name => @trace.user.display_name %>">
|
<img src="<%= url_for :controller => 'trace', :action => 'picture', :id => @trace.id, :display_name => @trace.user.display_name %>">
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|
|
@ -1,4 +1,21 @@
|
||||||
standard_settings: &standard_settings
|
standard_settings: &standard_settings
|
||||||
|
# The server URL
|
||||||
|
server_url: "www.openstreetmap.org"
|
||||||
|
# The generator
|
||||||
|
generator: "OpenStreetMap server"
|
||||||
|
# Sender addresses for emails
|
||||||
|
email_from: "OpenStreetMap <webmaster@openstreetmap.org>"
|
||||||
|
email_return_path: "bounces@openstreetmap.org"
|
||||||
|
# API version
|
||||||
|
api_version: "0.6"
|
||||||
|
# Application status - posstible values are:
|
||||||
|
# :online - online and operating normally
|
||||||
|
# :api_readonly - site online but API in read-only mode
|
||||||
|
# :api_offline - site online but API offline
|
||||||
|
# :database_readonly - database and site in read-only mode
|
||||||
|
# :database_offline - database offline with site in emergency mode
|
||||||
|
# :gpx_offline - gpx storage offline
|
||||||
|
status: :online
|
||||||
# The maximum area you're allowed to request, in square degrees
|
# The maximum area you're allowed to request, in square degrees
|
||||||
max_request_area: 0.25
|
max_request_area: 0.25
|
||||||
# Number of GPS trace/trackpoints returned per-page
|
# Number of GPS trace/trackpoints returned per-page
|
||||||
|
|
|
@ -1,36 +1,8 @@
|
||||||
# Be sure to restart your server when you modify this file
|
# Be sure to restart your server when you modify this file
|
||||||
|
|
||||||
# Uncomment below to force Rails into production mode when
|
|
||||||
# you don't control web/app server and can't set it the proper way
|
|
||||||
ENV['RAILS_ENV'] ||= 'production'
|
|
||||||
|
|
||||||
# Specifies gem version of Rails to use when vendor/rails is not present
|
# Specifies gem version of Rails to use when vendor/rails is not present
|
||||||
RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION
|
RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION
|
||||||
|
|
||||||
# Set the server URL
|
|
||||||
SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org'
|
|
||||||
|
|
||||||
# Set the generator
|
|
||||||
GENERATOR = ENV['OSM_SERVER_GENERATOR'] || 'OpenStreetMap server'
|
|
||||||
|
|
||||||
# Settings for generated emails (e.g. signup confirmation
|
|
||||||
EMAIL_FROM = ENV['OSM_EMAIL_FROM'] || 'OpenStreetMap <webmaster@openstreetmap.org>'
|
|
||||||
EMAIL_RETURN_PATH = ENV['OSM_EMAIL_RETURN_PATH'] || 'bounces@openstreetmap.org'
|
|
||||||
|
|
||||||
# Application constants needed for routes.rb - must go before Initializer call
|
|
||||||
API_VERSION = ENV['OSM_API_VERSION'] || '0.6'
|
|
||||||
|
|
||||||
# Set application status - possible settings are:
|
|
||||||
#
|
|
||||||
# :online - online and operating normally
|
|
||||||
# :api_readonly - site online but API in read-only mode
|
|
||||||
# :api_offline - site online but API offline
|
|
||||||
# :database_readonly - database and site in read-only mode
|
|
||||||
# :database_offline - database offline with site in emergency mode
|
|
||||||
# :gpx_offline - gpx storage offline
|
|
||||||
#
|
|
||||||
OSM_STATUS = :online
|
|
||||||
|
|
||||||
# Bootstrap the Rails environment, frameworks, and default configuration
|
# Bootstrap the Rails environment, frameworks, and default configuration
|
||||||
require File.join(File.dirname(__FILE__), 'boot')
|
require File.join(File.dirname(__FILE__), 'boot')
|
||||||
|
|
||||||
|
@ -43,7 +15,7 @@ Rails::Initializer.run do |config|
|
||||||
# config.load_paths += %W( #{RAILS_ROOT}/extras )
|
# config.load_paths += %W( #{RAILS_ROOT}/extras )
|
||||||
|
|
||||||
# Specify gems that this application depends on and have them installed with rake gems:install
|
# Specify gems that this application depends on and have them installed with rake gems:install
|
||||||
unless OSM_STATUS == :database_offline
|
unless STATUS == :database_offline
|
||||||
config.gem 'composite_primary_keys', :version => '2.2.2'
|
config.gem 'composite_primary_keys', :version => '2.2.2'
|
||||||
end
|
end
|
||||||
config.gem 'libxml-ruby', :version => '>= 1.1.1', :lib => 'libxml'
|
config.gem 'libxml-ruby', :version => '>= 1.1.1', :lib => 'libxml'
|
||||||
|
@ -59,7 +31,7 @@ Rails::Initializer.run do |config|
|
||||||
|
|
||||||
# Skip frameworks you're not going to use. To use Rails without a database,
|
# Skip frameworks you're not going to use. To use Rails without a database,
|
||||||
# you must remove the Active Record framework.
|
# you must remove the Active Record framework.
|
||||||
if OSM_STATUS == :database_offline
|
if STATUS == :database_offline
|
||||||
config.frameworks -= [ :active_record ]
|
config.frameworks -= [ :active_record ]
|
||||||
config.eager_load_paths = []
|
config.eager_load_paths = []
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
# This file loads various yml configuration files
|
|
||||||
|
|
||||||
# Load application config
|
|
||||||
APP_CONFIG = YAML.load(File.read(RAILS_ROOT + "/config/application.yml"))[RAILS_ENV]
|
|
|
@ -1,11 +1,11 @@
|
||||||
# Setup any specified hard limit on the virtual size of the process
|
# Setup any specified hard limit on the virtual size of the process
|
||||||
if APP_CONFIG.include?('hard_memory_limit') and Process.const_defined?(:RLIMIT_AS)
|
if defined?(HARD_MEMORY_LIMIT) and Process.const_defined?(:RLIMIT_AS)
|
||||||
Process.setrlimit Process::RLIMIT_AS, APP_CONFIG['hard_memory_limit']*1024*1024, Process::RLIM_INFINITY
|
Process.setrlimit Process::RLIMIT_AS, HARD_MEMORY_LIMIT*1024*1024, Process::RLIM_INFINITY
|
||||||
end
|
end
|
||||||
|
|
||||||
# If we're running under passenger and a soft memory limit is
|
# If we're running under passenger and a soft memory limit is
|
||||||
# configured then setup some rack middleware to police the limit
|
# configured then setup some rack middleware to police the limit
|
||||||
if APP_CONFIG.include?('soft_memory_limit') and defined?(PhusionPassenger)
|
if defined?(SOFT_MEMORY_LIMIT) and defined?(PhusionPassenger)
|
||||||
# Define some rack middleware to police the soft memory limit
|
# Define some rack middleware to police the soft memory limit
|
||||||
class MemoryLimit
|
class MemoryLimit
|
||||||
def initialize(app)
|
def initialize(app)
|
||||||
|
@ -17,7 +17,7 @@ if APP_CONFIG.include?('soft_memory_limit') and defined?(PhusionPassenger)
|
||||||
status, headers, body = @app.call(env)
|
status, headers, body = @app.call(env)
|
||||||
|
|
||||||
# Restart if we've hit our memory limit
|
# Restart if we've hit our memory limit
|
||||||
if resident_size > APP_CONFIG['soft_memory_limit']
|
if resident_size > SOFT_MEMORY_LIMIT
|
||||||
Process.kill("USR1", 0)
|
Process.kill("USR1", 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,6 @@ ActionController::Base.session = {
|
||||||
# Use the database for sessions instead of the cookie-based default,
|
# Use the database for sessions instead of the cookie-based default,
|
||||||
# which shouldn't be used to store highly confidential information
|
# which shouldn't be used to store highly confidential information
|
||||||
# (create the session table with "rake db:sessions:create")
|
# (create the session table with "rake db:sessions:create")
|
||||||
unless OSM_STATUS == :database_offline or OSM_STATUS == :database_readonly
|
unless STATUS == :database_offline or STATUS == :database_readonly
|
||||||
ActionController::Base.session_store = :sql_session_store
|
ActionController::Base.session_store = :sql_session_store
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,6 @@ adapter = Rails.configuration.database_configuration[environment]["adapter"]
|
||||||
session_class = adapter + "_session"
|
session_class = adapter + "_session"
|
||||||
|
|
||||||
# Configure SqlSessionStore
|
# Configure SqlSessionStore
|
||||||
unless OSM_STATUS == :database_offline
|
unless STATUS == :database_offline
|
||||||
SqlSessionStore.session_class = session_class.camelize.constantize
|
SqlSessionStore.session_class = session_class.camelize.constantize
|
||||||
end
|
end
|
||||||
|
|
16
config/preinitializer.rb
Normal file
16
config/preinitializer.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
require 'yaml'
|
||||||
|
|
||||||
|
config = YAML.load_file("#{RAILS_ROOT}/config/application.yml")
|
||||||
|
env = ENV['RAILS_ENV'] || 'development'
|
||||||
|
|
||||||
|
ENV.each do |key,value|
|
||||||
|
if key.match(/^OSM_(.*)$/)
|
||||||
|
Object.const_set(Regexp.last_match(1).upcase, value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
config[env].each do |key,value|
|
||||||
|
unless Object.const_defined?(key.upcase)
|
||||||
|
Object.const_set(key.upcase, value)
|
||||||
|
end
|
||||||
|
end
|
|
@ -24,8 +24,8 @@ module MapBoundary
|
||||||
|
|
||||||
# check the bbox isn't too large
|
# check the bbox isn't too large
|
||||||
requested_area = (max_lat-min_lat)*(max_lon-min_lon)
|
requested_area = (max_lat-min_lat)*(max_lon-min_lon)
|
||||||
if requested_area > APP_CONFIG['max_request_area']
|
if requested_area > MAX_REQUEST_AREA
|
||||||
raise OSM::APIBadBoundingBox.new("The maximum bbox size is " + APP_CONFIG['max_request_area'].to_s +
|
raise OSM::APIBadBoundingBox.new("The maximum bbox size is " + MAX_REQUEST_AREA.to_s +
|
||||||
", and your request was too large. Either request a smaller area, or use planet.osm")
|
", and your request was too large. Either request a smaller area, or use planet.osm")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -530,7 +530,7 @@ module OSM
|
||||||
|
|
||||||
def self.legal_text_for_country(country_code)
|
def self.legal_text_for_country(country_code)
|
||||||
file_name = File.join(RAILS_ROOT, "config", "legales", country_code.to_s + ".yml")
|
file_name = File.join(RAILS_ROOT, "config", "legales", country_code.to_s + ".yml")
|
||||||
file_name = File.join(RAILS_ROOT, "config", "legales", APP_CONFIG['default_legale'] + ".yml") unless File.exist? file_name
|
file_name = File.join(RAILS_ROOT, "config", "legales", DEFAULT_LEGALE + ".yml") unless File.exist? file_name
|
||||||
YAML::load_file(file_name)
|
YAML::load_file(file_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,8 +17,8 @@ module Quova
|
||||||
##
|
##
|
||||||
# Access details for WSDL description
|
# Access details for WSDL description
|
||||||
WSDL_URL="https://webservices.quova.com/OnDemand/GeoPoint/v1/default.asmx?WSDL"
|
WSDL_URL="https://webservices.quova.com/OnDemand/GeoPoint/v1/default.asmx?WSDL"
|
||||||
WSDL_USER = APP_CONFIG['quova_username']
|
WSDL_USER = QUOVA_USERNAME
|
||||||
WSDL_PASS = APP_CONFIG['quova_password']
|
WSDL_PASS = QUOVA_PASSWORD
|
||||||
|
|
||||||
##
|
##
|
||||||
# Status codes
|
# Status codes
|
||||||
|
|
|
@ -147,7 +147,7 @@ class ApiControllerTest < ActionController::TestCase
|
||||||
[ "trackpoints", "map" ].each do |tq|
|
[ "trackpoints", "map" ].each do |tq|
|
||||||
get tq, :bbox => bbox
|
get tq, :bbox => bbox
|
||||||
assert_response :bad_request, "The bbox:#{bbox} was expected to be too big"
|
assert_response :bad_request, "The bbox:#{bbox} was expected to be too big"
|
||||||
assert_equal "The maximum bbox size is #{APP_CONFIG['max_request_area']}, and your request was too large. Either request a smaller area, or use planet.osm", @response.body, "bbox: #{bbox}"
|
assert_equal "The maximum bbox size is #{MAX_REQUEST_AREA}, and your request was too large. Either request a smaller area, or use planet.osm", @response.body, "bbox: #{bbox}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -264,8 +264,8 @@ class ApiControllerTest < ActionController::TestCase
|
||||||
assert_select "osm:root[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
|
assert_select "osm:root[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
|
||||||
assert_select "api", :count => 1 do
|
assert_select "api", :count => 1 do
|
||||||
assert_select "version[minimum=#{API_VERSION}][maximum=#{API_VERSION}]", :count => 1
|
assert_select "version[minimum=#{API_VERSION}][maximum=#{API_VERSION}]", :count => 1
|
||||||
assert_select "area[maximum=#{APP_CONFIG['max_request_area']}]", :count => 1
|
assert_select "area[maximum=#{MAX_REQUEST_AREA}]", :count => 1
|
||||||
assert_select "tracepoints[per_page=#{APP_CONFIG['tracepoints_per_page']}]", :count => 1
|
assert_select "tracepoints[per_page=#{TRACEPOINTS_PER_PAGE}]", :count => 1
|
||||||
assert_select "changesets[maximum_elements=#{Changeset::MAX_ELEMENTS}]", :count => 1
|
assert_select "changesets[maximum_elements=#{Changeset::MAX_ELEMENTS}]", :count => 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,7 @@ class WayTest < ActiveSupport::TestCase
|
||||||
way = Way.find(current_ways(:visible_way).id)
|
way = Way.find(current_ways(:visible_way).id)
|
||||||
assert way.valid?
|
assert way.valid?
|
||||||
# it already has 1 node
|
# it already has 1 node
|
||||||
1.upto((APP_CONFIG['max_number_of_way_nodes']) / 2) {
|
1.upto((MAX_NUMBER_OF_WAY_NODES) / 2) {
|
||||||
way.add_nd_num(current_nodes(:used_node_1).id)
|
way.add_nd_num(current_nodes(:used_node_1).id)
|
||||||
way.add_nd_num(current_nodes(:used_node_2).id)
|
way.add_nd_num(current_nodes(:used_node_2).id)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue