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)
|
||||
amf_handle_error(call,rootobj,rootid) do
|
||||
Timeout::timeout(APP_CONFIG['api_timeout'], OSM::APITimeoutError) do
|
||||
Timeout::timeout(API_TIMEOUT, OSM::APITimeoutError) do
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ class ApiController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
offset = page * APP_CONFIG['tracepoints_per_page']
|
||||
offset = page * TRACEPOINTS_PER_PAGE
|
||||
|
||||
# Figure out the bbox
|
||||
bbox = params['bbox']
|
||||
|
@ -39,7 +39,7 @@ class ApiController < ApplicationController
|
|||
end
|
||||
|
||||
# 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.encoding = XML::Encoding::UTF_8
|
||||
|
@ -145,14 +145,14 @@ class ApiController < ApplicationController
|
|||
end
|
||||
|
||||
# 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
|
||||
# need to be @nodes (instance var) so tests in /spec can be performed
|
||||
#@nodes = Node.search(bbox, params[:tag])
|
||||
|
||||
node_ids = @nodes.collect(&:id)
|
||||
if node_ids.length > APP_CONFIG['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")
|
||||
if node_ids.length > MAX_NUMBER_OF_NODES
|
||||
report_error("You requested too many nodes (limit is #{MAX_NUMBER_OF_NODES}). Either request a smaller area, or use planet.osm")
|
||||
return
|
||||
end
|
||||
if node_ids.length == 0
|
||||
|
@ -295,19 +295,19 @@ class ApiController < ApplicationController
|
|||
version['maximum'] = "#{API_VERSION}";
|
||||
api << version
|
||||
area = XML::Node.new 'area'
|
||||
area['maximum'] = APP_CONFIG['max_request_area'].to_s;
|
||||
area['maximum'] = MAX_REQUEST_AREA.to_s;
|
||||
api << area
|
||||
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
|
||||
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
|
||||
changesets = XML::Node.new 'changesets'
|
||||
changesets['maximum_elements'] = Changeset::MAX_ELEMENTS.to_s
|
||||
api << changesets
|
||||
timeout = XML::Node.new 'timeout'
|
||||
timeout['seconds'] = APP_CONFIG['api_timeout'].to_s
|
||||
timeout['seconds'] = API_TIMEOUT.to_s
|
||||
api << timeout
|
||||
|
||||
doc.root << api
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# Likewise, all the methods added will be available for all controllers.
|
||||
class ApplicationController < ActionController::Base
|
||||
|
||||
if OSM_STATUS == :database_readonly or OSM_STATUS == :database_offline
|
||||
if STATUS == :database_readonly or STATUS == :database_offline
|
||||
session :off
|
||||
end
|
||||
|
||||
|
@ -120,20 +120,20 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
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'
|
||||
end
|
||||
end
|
||||
|
||||
def check_database_writable(need_api = false)
|
||||
if OSM_STATUS == :database_offline or OSM_STATUS == :database_readonly or
|
||||
(need_api and (OSM_STATUS == :api_offline or OSM_STATUS == :api_readonly))
|
||||
if STATUS == :database_offline or STATUS == :database_readonly or
|
||||
(need_api and (STATUS == :api_offline or STATUS == :api_readonly))
|
||||
redirect_to :controller => 'site', :action => 'offline'
|
||||
end
|
||||
end
|
||||
|
||||
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"
|
||||
render :nothing => true, :status => :service_unavailable
|
||||
return false
|
||||
|
@ -141,8 +141,8 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def check_api_writable
|
||||
if OSM_STATUS == :database_offline or OSM_STATUS == :database_readonly or
|
||||
OSM_STATUS == :api_offline or OSM_STATUS == :api_readonly
|
||||
if STATUS == :database_offline or STATUS == :database_readonly or
|
||||
STATUS == :api_offline or STATUS == :api_readonly
|
||||
response.headers['Error'] = "Database offline for maintenance"
|
||||
render :nothing => true, :status => :service_unavailable
|
||||
return false
|
||||
|
@ -219,7 +219,7 @@ class ApplicationController < ActionController::Base
|
|||
##
|
||||
# wrap an api call in a timeout
|
||||
def api_call_timeout
|
||||
SystemTimer.timeout_after(APP_CONFIG['api_timeout']) do
|
||||
SystemTimer.timeout_after(API_TIMEOUT) do
|
||||
yield
|
||||
end
|
||||
rescue Timeout::Error
|
||||
|
@ -229,7 +229,7 @@ class ApplicationController < ActionController::Base
|
|||
##
|
||||
# wrap a web page in a timeout
|
||||
def web_timeout
|
||||
SystemTimer.timeout_after(APP_CONFIG['web_timeout']) do
|
||||
SystemTimer.timeout_after(WEB_TIMEOUT) do
|
||||
yield
|
||||
end
|
||||
rescue ActionView::TemplateError => ex
|
||||
|
|
|
@ -10,7 +10,7 @@ class DiaryEntryController < ApplicationController
|
|||
|
||||
caches_action :list, :view, :layout => false
|
||||
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
|
||||
@title = t 'diary_entry.new.title'
|
||||
|
|
|
@ -57,7 +57,7 @@ class GeocoderController < ApplicationController
|
|||
render :action => "error"
|
||||
else
|
||||
@results.push({:lat => lat, :lon => lon,
|
||||
:zoom => APP_CONFIG['postcode_zoom'],
|
||||
:zoom => POSTCODE_ZOOM,
|
||||
:name => "#{lat}, #{lon}"})
|
||||
|
||||
render :action => "results"
|
||||
|
@ -78,7 +78,7 @@ class GeocoderController < ApplicationController
|
|||
unless response.match(/couldn't find this zip/)
|
||||
data = response.split(/\s*,\s+/) # lat,long,town,state,zip
|
||||
@results.push({:lat => data[0], :lon => data[1],
|
||||
:zoom => APP_CONFIG['postcode_zoom'],
|
||||
:zoom => POSTCODE_ZOOM,
|
||||
:prefix => "#{data[2]}, #{data[3]},",
|
||||
:name => data[4]})
|
||||
end
|
||||
|
@ -104,7 +104,7 @@ class GeocoderController < ApplicationController
|
|||
dataline = response.split(/\n/)[1]
|
||||
data = dataline.split(/,/) # easting,northing,postcode,lat,long
|
||||
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,
|
||||
:name => postcode})
|
||||
end
|
||||
|
@ -127,7 +127,7 @@ class GeocoderController < ApplicationController
|
|||
if response.get_elements("geodata/error").empty?
|
||||
@results.push({:lat => response.get_text("geodata/latt").to_s,
|
||||
:lon => response.get_text("geodata/longt").to_s,
|
||||
:zoom => APP_CONFIG['postcode_zoom'],
|
||||
:zoom => POSTCODE_ZOOM,
|
||||
:name => query.upcase})
|
||||
end
|
||||
|
||||
|
@ -286,7 +286,7 @@ class GeocoderController < ApplicationController
|
|||
name = geoname.get_text("name").to_s
|
||||
country = geoname.get_text("countryName").to_s
|
||||
@results.push({:lat => lat, :lon => lon,
|
||||
:zoom => APP_CONFIG['geonames_zoom'],
|
||||
:zoom => GEONAMES_ZOOM,
|
||||
:name => name,
|
||||
:suffix => ", #{country}"})
|
||||
end
|
||||
|
|
|
@ -15,7 +15,7 @@ class MessageController < ApplicationController
|
|||
@to_user = User.find_by_display_name(params[:display_name])
|
||||
if @to_user
|
||||
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'
|
||||
else
|
||||
@message = Message.new(params[:message])
|
||||
|
|
|
@ -17,8 +17,8 @@ class TraceController < ApplicationController
|
|||
|
||||
caches_action :list, :view, :layout => false
|
||||
caches_action :georss, :layout => true
|
||||
cache_sweeper :trace_sweeper, :only => [:create, :edit, :delete, :api_create], :unless => OSM_STATUS == :database_offline
|
||||
cache_sweeper :tracetag_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 => STATUS == :database_offline
|
||||
|
||||
# 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
|
||||
|
@ -395,11 +395,11 @@ private
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def offline_redirect
|
||||
redirect_to :action => :offline if OSM_STATUS == :gpx_offline
|
||||
redirect_to :action => :offline if STATUS == :gpx_offline
|
||||
end
|
||||
|
||||
def default_visibility
|
||||
|
|
|
@ -16,13 +16,13 @@ class UserController < ApplicationController
|
|||
|
||||
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
|
||||
@title = t 'user.new.title'
|
||||
@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)
|
||||
|
||||
if request.xhr?
|
||||
|
|
|
@ -58,7 +58,7 @@ class Node < ActiveRecord::Base
|
|||
|
||||
find_by_area(min_lat, min_lon, max_lat, max_lon,
|
||||
:conditions => {:visible => true},
|
||||
:limit => APP_CONFIG['max_number_of_nodes']+1)
|
||||
:limit => MAX_NUMBER_OF_NODES+1)
|
||||
end
|
||||
|
||||
# Read in xml as text and return it's Node object representation
|
||||
|
|
|
@ -105,7 +105,7 @@ private
|
|||
end
|
||||
|
||||
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")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ class SpamObserver < ActiveRecord::Observer
|
|||
when record.is_a?(DiaryComment): user = record.user
|
||||
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")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ class UserBlock < ActiveRecord::Base
|
|||
belongs_to :creator, :class_name => "User", :foreign_key => :creator_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
|
||||
|
|
|
@ -234,8 +234,8 @@ class Way < ActiveRecord::Base
|
|||
|
||||
def preconditions_ok?(old_nodes = [])
|
||||
return false if self.nds.empty?
|
||||
if self.nds.length > APP_CONFIG['max_number_of_way_nodes']
|
||||
raise OSM::APITooManyWayNodesError.new(self.id, 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, MAX_NUMBER_OF_WAY_NODES)
|
||||
end
|
||||
|
||||
# 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 size = projected.getWidth() * projected.getHeight();
|
||||
|
||||
if (size > #{APP_CONFIG['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 }));
|
||||
if (size > #{MAX_REQUEST_AREA}) {
|
||||
setStatus(i18n("#{I18n.t('browse.start_rjs.unable_to_load_size', :max_bbox_size => MAX_REQUEST_AREA)}", { bbox_size: size }));
|
||||
} else {
|
||||
loadGML("/api/#{API_VERSION}/map?bbox=" + projected.toBBOX());
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ page << <<EOJ
|
|||
function validateControls() {
|
||||
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";
|
||||
} else {
|
||||
$("export_osm_too_large").style.display = "none";
|
||||
|
@ -198,7 +198,7 @@ page << <<EOJ
|
|||
|
||||
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;
|
||||
} else if ($("format_mapnik").checked && $("mapnik_scale").value < max_scale) {
|
||||
$("export_commit").disabled = true;
|
||||
|
|
|
@ -100,11 +100,11 @@
|
|||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline %>
|
||||
<% if STATUS == :database_offline or STATUS == :api_offline %>
|
||||
<div id="alert">
|
||||
<%= t 'layouts.osm_offline' %>
|
||||
</div>
|
||||
<% elsif OSM_STATUS == :database_readonly or OSM_STATUS == :api_readonly %>
|
||||
<% elsif STATUS == :database_readonly or STATUS == :api_readonly %>
|
||||
<div id="alert">
|
||||
<%= t 'layouts.osm_read_only' %>
|
||||
</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>
|
||||
<% 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>
|
||||
<% elsif !@user.data_public? %>
|
||||
|
|
|
@ -125,7 +125,7 @@ end
|
|||
function mapInit(){
|
||||
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.events.register("visibilitychanged", map.dataLayer, toggleData);
|
||||
map.addLayer(map.dataLayer);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<% if OSM_STATUS == :database_offline %>
|
||||
<% if STATUS == :database_offline %>
|
||||
<p><%= t 'layouts.osm_offline' %>
|
||||
</p>
|
||||
<% else %>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<tr>
|
||||
<% cl = cycle('table0', 'table1') %>
|
||||
<td class="<%= cl %>">
|
||||
<% if OSM_STATUS != :gpx_offline %>
|
||||
<% if STATUS != :gpx_offline %>
|
||||
<% 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>
|
||||
<% else %>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<h2><%= t 'trace.view.heading', :name => h(@trace.name) %></h2>
|
||||
|
||||
<% if OSM_STATUS != :gpx_offline %>
|
||||
<% if STATUS != :gpx_offline %>
|
||||
<% if @trace.inserted %>
|
||||
<img src="<%= url_for :controller => 'trace', :action => 'picture', :id => @trace.id, :display_name => @trace.user.display_name %>">
|
||||
<% else %>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue