]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/2177'
authorTom Hughes <tom@compton.nu>
Sat, 16 Mar 2019 15:39:03 +0000 (15:39 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 16 Mar 2019 15:39:03 +0000 (15:39 +0000)
73 files changed:
.gitignore
.travis.yml
CONFIGURE.md
Gemfile
Gemfile.lock
INSTALL.md
app/assets/javascripts/embed.js.erb
app/assets/javascripts/osm.js.erb
app/controllers/api/amf_controller.rb
app/controllers/api/map_controller.rb
app/controllers/api/notes_controller.rb
app/controllers/api/tracepoints_controller.rb
app/controllers/application_controller.rb
app/controllers/diary_entries_controller.rb
app/controllers/geocoder_controller.rb
app/controllers/messages_controller.rb
app/controllers/oauth_controller.rb
app/controllers/traces_controller.rb
app/controllers/users_controller.rb
app/helpers/notifier_helper.rb
app/mailers/notifier.rb
app/models/client_application.rb
app/models/request_token.rb
app/models/trace.rb
app/models/user.rb
app/models/user_block.rb
app/models/way.rb
app/views/api/capabilities/show.builder
app/views/layouts/_head.html.erb
app/views/notifier/email_confirm.html.erb
app/views/notifier/email_confirm.text.erb
app/views/notifier/signup_confirm.html.erb
app/views/notifier/signup_confirm.text.erb
app/views/site/_id.html.erb
app/views/site/_potlatch2.html.erb
app/views/site/id.html.erb
app/views/users/account.html.erb
app/views/users/blocked.html.erb
app/views/users/login.html.erb
app/views/users/suspended.html.erb
config/.gitignore
config/application.rb
config/environments/production.rb
config/example.application.yml [deleted file]
config/initializers/action_mailer.rb
config/initializers/canonical_rails.rb
config/initializers/config.rb [new file with mode: 0644]
config/initializers/omniauth.rb
config/initializers/paperclip.rb
config/initializers/secure_headers.rb
config/initializers/session_store.rb
config/preinitializer.rb [deleted file]
config/settings.yml [new file with mode: 0644]
config/settings/development.yml [new file with mode: 0644]
config/settings/production.yml [new file with mode: 0644]
config/settings/test.yml [new file with mode: 0644]
lib/auth.rb
lib/bounding_box.rb
lib/osm.rb
test/controllers/api/capabilities_controller_test.rb
test/controllers/api/changes_controller_test.rb
test/controllers/api/changesets_controller_test.rb
test/controllers/api/map_controller_test.rb
test/controllers/api/relations_controller_test.rb
test/controllers/api/tracepoints_controller_test.rb
test/controllers/api/traces_controller_test.rb
test/controllers/messages_controller_test.rb
test/controllers/site_controller_test.rb
test/controllers/traces_controller_test.rb
test/integration/user_blocks_test.rb
test/integration/user_terms_seen_test.rb
test/models/trace_test.rb
test/models/way_test.rb

index 1a2d35c6a28cc056de2646690384138a52a03caf..17112bf8a48d4f21aea2c4a7c6c79fae37724f64 100644 (file)
@@ -13,3 +13,7 @@ doc
 .ruby-version
 .idea
 coverage
+
+config/settings.local.yml
+config/settings/*.local.yml
+config/environments/*.local.yml
index 3b56d2b4b666af3b77fb9df25838a6259b0def03..1738201b703035071ca38d7890431eac38ae618d 100644 (file)
@@ -14,7 +14,6 @@ env:
   global:
     - OSM_MEMCACHE_SERVERS="127.0.0.1"
 before_script:
-  - cp config/example.application.yml config/application.yml
   - psql -U postgres -c "CREATE DATABASE openstreetmap"
   - psql -U postgres -c "CREATE EXTENSION btree_gist" openstreetmap
   - make -C db/functions libpgosm.so
index c6444ffa9efe773c5edda6b735148f4d502b6c81..91a64119ed33cb5d7ccf057ba266a6684f323bce 100644 (file)
@@ -2,6 +2,10 @@
 
 After [installing](INSTALL.md) this software, you may need to carry out some of these configuration steps, depending on your tasks.
 
+## Application configuration
+
+Many settings are available in `config/settings.yml`. You can customize your installation of The Rails Port by overriding these values using `config/settings.local.yml`
+
 ## Populating the database
 
 Your installation comes with no geographic data loaded. You can either create new data using one of the editors (Potlatch 2, iD, JOSM etc) or by loading an OSM extract.
@@ -71,11 +75,11 @@ Do the following:
 * Everything else can be left with the default blank values.
 * Click the "Register" button
 * On the next page, copy the "consumer key"
-* Edit config/application.yml in your rails tree
-* Uncomment and change the "potlatch2_key" configuration value
+* Edit config/settings.local.yml in your rails tree
+* Add the "potlatch2_key" configuration key and the consumer key as the value
 * Restart your rails server
 
-An example excerpt from application.yml:
+An example excerpt from settings.local.yml:
 
 ```
 # Default editor
@@ -86,8 +90,6 @@ potlatch2_key: "8lFmZPsagHV4l3rkAHq0hWY5vV3Ctl3oEFY1aXth"
 
 Follow the same process for registering and configuring iD (`id_key`) and the website/Notes (`oauth_key`), or to save time, simply reuse the same consumer key for each.
 
-**NOTE:** If you forget to set up OAuth, then you will get an error message similar to `uninitialized constant ActionView::CompiledTemplates::ID_KEY`.
-
 ## Troubleshooting
 
 Rails has its own log.  To inspect the log, do this:
diff --git a/Gemfile b/Gemfile
index f2e1e21218c60c2324c593ae2ca454ce8185dfe0..372b7d021740b2cecc5949a33d7122b42d0c532f 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -48,6 +48,7 @@ gem "actionpack-page_caching"
 gem "active_record_union"
 gem "cancancan"
 gem "composite_primary_keys", "~> 11.1.0"
+gem "config"
 gem "delayed_job_active_record"
 gem "dynamic_form"
 gem "http_accept_language", "~> 2.0.0"
index e7e3914177833882a4a231b2f9e144bc1d8f1e4b..2b5cc1dd5a6538be1095af7342c0d86e6436dfdb 100644 (file)
@@ -92,6 +92,10 @@ GEM
     composite_primary_keys (11.1.0)
       activerecord (~> 5.2.1)
     concurrent-ruby (1.1.5)
+    config (1.7.1)
+      activesupport (>= 3.0)
+      deep_merge (~> 1.2.1)
+      dry-validation (>= 0.12.2)
     coveralls (0.8.22)
       json (>= 1.8, < 3)
       simplecov (~> 0.16.1)
@@ -103,12 +107,41 @@ GEM
     crass (1.0.4)
     dalli (2.7.9)
     debug_inspector (0.0.3)
+    deep_merge (1.2.1)
     delayed_job (4.1.5)
       activesupport (>= 3.0, < 5.3)
     delayed_job_active_record (4.1.3)
       activerecord (>= 3.0, < 5.3)
       delayed_job (>= 3.0, < 5)
     docile (1.3.1)
+    dry-configurable (0.8.2)
+      concurrent-ruby (~> 1.0)
+      dry-core (~> 0.4, >= 0.4.7)
+    dry-container (0.7.0)
+      concurrent-ruby (~> 1.0)
+      dry-configurable (~> 0.1, >= 0.1.3)
+    dry-core (0.4.7)
+      concurrent-ruby (~> 1.0)
+    dry-equalizer (0.2.2)
+    dry-inflector (0.1.2)
+    dry-logic (0.5.0)
+      dry-container (~> 0.2, >= 0.2.6)
+      dry-core (~> 0.2)
+      dry-equalizer (~> 0.2)
+    dry-types (0.14.0)
+      concurrent-ruby (~> 1.0)
+      dry-container (~> 0.3)
+      dry-core (~> 0.4, >= 0.4.4)
+      dry-equalizer (~> 0.2)
+      dry-inflector (~> 0.1, >= 0.1.2)
+      dry-logic (~> 0.5, >= 0.5)
+    dry-validation (0.13.0)
+      concurrent-ruby (~> 1.0)
+      dry-configurable (~> 0.1, >= 0.1.3)
+      dry-core (~> 0.2, >= 0.2.1)
+      dry-equalizer (~> 0.2)
+      dry-logic (~> 0.5, >= 0.5.0)
+      dry-types (~> 0.14, >= 0.14)
     dynamic_form (1.1.4)
     erubi (1.8.0)
     execjs (2.7.0)
@@ -402,6 +435,7 @@ DEPENDENCIES
   capybara (~> 2.13)
   coffee-rails (~> 4.2)
   composite_primary_keys (~> 11.1.0)
+  config
   coveralls
   dalli
   delayed_job_active_record
index 8e47cb2667473bac991125e237138ac39e0d457f..f069521eb80feacc08a52b4d12614483dcea4247 100644 (file)
@@ -115,16 +115,6 @@ cd openstreetmap-website
 bundle install
 ```
 
-## Application setup
-
-We need to create the `config/application.yml` file from the example template. This contains various configuration options.
-
-```
-cp config/example.application.yml config/application.yml
-```
-
-You can customize your installation of The Rails Port by changing the values in `config/application.yml`
-
 ## Database setup
 
 The Rails Port uses three databases -  one for development, one for testing, and one for production. The database-specific configuration
index 36b23666a92f8ebe61481ba8d508d014a76b60bf..ceb488f987681871e05c87476e5a464de126c79d 100644 (file)
@@ -20,8 +20,8 @@ window.onload = function () {
   }
 
   var thunderforestOptions = {
-<% if defined?(THUNDERFOREST_KEY) %>
-    apikey: <%= THUNDERFOREST_KEY.to_json %>
+<% if Settings.key?(:thunderforest_key) %>
+    apikey: <%= Settings.thunderforest_key.to_json %>
 <% end %>
   };
 
index a9e1a475ec15d8daf302e4cc9faeb2355adb3859..f5d530a1b3792bc9f539830cd22729a810d8a042 100644 (file)
@@ -1,24 +1,25 @@
-//= depend_on application.yml
+//= depend_on settings.yml
+//= depend_on settings.local.yml
 
 OSM = {
 <% if defined?(PIWIK) %>
   PIWIK:                   <%= PIWIK.to_json %>,
 <% end %>
 
-  MAX_REQUEST_AREA:        <%= MAX_REQUEST_AREA.to_json %>,
-  SERVER_PROTOCOL:         <%= SERVER_PROTOCOL.to_json %>,
-  SERVER_URL:              <%= SERVER_URL.to_json %>,
-  API_VERSION:             <%= API_VERSION.to_json %>,
+  MAX_REQUEST_AREA:        <%= Settings.max_request_area.to_json %>,
+  SERVER_PROTOCOL:         <%= Settings.server_protocol.to_json %>,
+  SERVER_URL:              <%= Settings.server_url.to_json %>,
+  API_VERSION:             <%= Settings.api_version.to_json %>,
   STATUS:                  <%= STATUS.to_json %>,
-  MAX_NOTE_REQUEST_AREA:   <%= MAX_NOTE_REQUEST_AREA.to_json %>,
-  OVERPASS_URL:            <%= OVERPASS_URL.to_json %>,
-  NOMINATIM_URL:           <%= NOMINATIM_URL.to_json %>,
-  GRAPHHOPPER_URL:         <%= GRAPHHOPPER_URL.to_json %>,
-  FOSSGIS_OSRM_URL:        <%= FOSSGIS_OSRM_URL.to_json %>,
+  MAX_NOTE_REQUEST_AREA:   <%= Settings.max_note_request_area.to_json %>,
+  OVERPASS_URL:            <%= Settings.overpass_url.to_json %>,
+  NOMINATIM_URL:           <%= Settings.nominatim_url.to_json %>,
+  GRAPHHOPPER_URL:         <%= Settings.graphhopper_url.to_json %>,
+  FOSSGIS_OSRM_URL:        <%= Settings.fossgis_osrm_url.to_json %>,
   DEFAULT_LOCALE:          <%= I18n.default_locale.to_json %>,
 
-<% if defined?(THUNDERFOREST_KEY) %>
-  THUNDERFOREST_KEY:       <%= THUNDERFOREST_KEY.to_json %>,
+<% if Settings.key?(:thunderforest_key) %>
+  THUNDERFOREST_KEY:       <%= Settings.thunderforest_key.to_json %>,
 <% end %>
 
   MARKER_GREEN:            <%= image_path("marker-green.png").to_json %>,
@@ -212,7 +213,7 @@ OSM = {
 
     return 6372795 * 2 * Math.asin(
       Math.sqrt(
-        Math.pow(Math.sin(latdiff / 2), 2) + 
+        Math.pow(Math.sin(latdiff / 2), 2) +
         Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(lngdiff / 2), 2)
       ));
   }
index 2a878d248930265490c5bbbd64b91870f0678785..509cf1d77c7847a77f1b8d6f849b9aae6116850d 100644 (file)
@@ -131,7 +131,7 @@ module Api
 
     def amf_handle_error_with_timeout(call, rootobj, rootid)
       amf_handle_error(call, rootobj, rootid) do
-        OSM::Timer.timeout(API_TIMEOUT, OSM::APITimeoutError) do
+        OSM::Timer.timeout(Settings.api_timeout, OSM::APITimeoutError) do
           yield
         end
       end
index 47c0aeb36af38295cd88e5b63ece3a47556457d9..e8d36c8ec375e5e69eb25b290d1c524695d9112c 100644 (file)
@@ -30,11 +30,11 @@ module Api
         return
       end
 
-      nodes = Node.bbox(bbox).where(:visible => true).includes(:node_tags).limit(MAX_NUMBER_OF_NODES + 1)
+      nodes = Node.bbox(bbox).where(:visible => true).includes(:node_tags).limit(Settings.max_number_of_nodes + 1)
 
       node_ids = nodes.collect(&:id)
-      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")
+      if node_ids.length > Settings.max_number_of_nodes
+        report_error("You requested too many nodes (limit is #{Settings.max_number_of_nodes}). Either request a smaller area, or use planet.osm")
         return
       end
 
index d4ebef5d4fb58e2b8e741c5f5dce1e2b3e481d88..686e76b147d0141d960950309d485aa78a6f6c8f 100644 (file)
@@ -37,7 +37,7 @@ module Api
       bbox.check_boundaries
 
       # Check the the bounding box is not too big
-      bbox.check_size(MAX_NOTE_REQUEST_AREA)
+      bbox.check_size(Settings.max_note_request_area)
 
       # Find the notes we want to return
       @notes = notes.bbox(bbox).order("updated_at DESC").limit(result_limit).preload(:comments)
@@ -190,7 +190,7 @@ module Api
         bbox = BoundingBox.from_bbox_params(params)
 
         bbox.check_boundaries
-        bbox.check_size(MAX_NOTE_REQUEST_AREA)
+        bbox.check_size(Settings.max_note_request_area)
 
         notes = notes.bbox(bbox)
       end
index 56cd36138b737435afcd3ea0ea3f9179e559b046..c71b5a3e9a06d7e6c5e7e1d3fea08282ae4db29f 100644 (file)
@@ -19,7 +19,7 @@ module Api
         return
       end
 
-      offset = page * TRACEPOINTS_PER_PAGE
+      offset = page * Settings.tracepoints_per_page
 
       # Figure out the bbox
       # check boundary is sane and area within defined
@@ -36,7 +36,7 @@ module Api
       # get all the points
       ordered_points = Tracepoint.bbox(bbox).joins(:trace).where(:gpx_files => { :visibility => %w[trackable identifiable] }).order("gpx_id DESC, trackid ASC, timestamp ASC")
       unordered_points = Tracepoint.bbox(bbox).joins(:trace).where(:gpx_files => { :visibility => %w[public private] }).order("gps_points.latitude", "gps_points.longitude", "gps_points.timestamp")
-      points = ordered_points.union_all(unordered_points).offset(offset).limit(TRACEPOINTS_PER_PAGE)
+      points = ordered_points.union_all(unordered_points).offset(offset).limit(Settings.tracepoints_per_page)
 
       doc = XML::Document.new
       doc.encoding = XML::Encoding::UTF_8
index 227e5198f5de115b9dc90d97acbf069cbfb2c581..0e77a398d6f5d702c83921589ad29da28707d9fe 100644 (file)
@@ -52,7 +52,7 @@ class ApplicationController < ActionController::Base
   end
 
   def require_oauth
-    @oauth = current_user.access_token(OAUTH_KEY) if current_user && defined? OAUTH_KEY
+    @oauth = current_user.access_token(Settings.oauth_key) if current_user && Settings.key?(:oauth_key)
   end
 
   ##
@@ -272,7 +272,7 @@ class ApplicationController < ActionController::Base
   ##
   # wrap an api call in a timeout
   def api_call_timeout
-    OSM::Timer.timeout(API_TIMEOUT, Timeout::Error) do
+    OSM::Timer.timeout(Settings.api_timeout, Timeout::Error) do
       yield
     end
   rescue Timeout::Error
@@ -282,7 +282,7 @@ class ApplicationController < ActionController::Base
   ##
   # wrap a web page in a timeout
   def web_timeout
-    OSM::Timer.timeout(WEB_TIMEOUT, Timeout::Error) do
+    OSM::Timer.timeout(Settings.web_timeout, Timeout::Error) do
       yield
     end
   rescue ActionView::Template::Error => ex
@@ -333,7 +333,7 @@ class ApplicationController < ActionController::Base
     append_content_security_policy_directives(
       :child_src => %w[http://127.0.0.1:8111 https://127.0.0.1:8112],
       :frame_src => %w[http://127.0.0.1:8111 https://127.0.0.1:8112],
-      :connect_src => [NOMINATIM_URL, OVERPASS_URL, FOSSGIS_OSRM_URL, GRAPHHOPPER_URL],
+      :connect_src => [Settings.nominatim_url, Settings.overpass_url, Settings.fossgis_osrm_url, Settings.graphhopper_url],
       :form_action => %w[render.openstreetmap.org],
       :style_src => %w['unsafe-inline']
     )
@@ -357,7 +357,7 @@ class ApplicationController < ActionController::Base
              elsif current_user&.preferred_editor
                current_user.preferred_editor
              else
-               DEFAULT_EDITOR
+               Settings.default_editor
              end
 
     editor
@@ -366,9 +366,9 @@ class ApplicationController < ActionController::Base
   helper_method :preferred_editor
 
   def update_totp
-    if defined?(TOTP_KEY)
+    if Settings.key?(:totp_key)
       cookies["_osm_totp_token"] = {
-        :value => ROTP::TOTP.new(TOTP_KEY, :interval => 3600).now,
+        :value => ROTP::TOTP.new(Settings.totp_key, :interval => 3600).now,
         :domain => "openstreetmap.org",
         :expires => 1.hour.from_now
       }
index 4a1da178a163b558f1775a18b99527ab7519f196..282ac29289fe1ea03bb8de382ce40c6c77298a49 100644 (file)
@@ -158,7 +158,7 @@ class DiaryEntriesController < ApplicationController
         @entries = user.diary_entries
         @title = t("diary_entries.feed.user.title", :user => user.display_name)
         @description = t("diary_entries.feed.user.description", :user => user.display_name)
-        @link = url_for :action => "index", :display_name => user.display_name, :host => SERVER_URL, :protocol => SERVER_PROTOCOL
+        @link = url_for :action => "index", :display_name => user.display_name, :host => Settings.server_url, :protocol => Settings.server_protocol
       else
         head :not_found
         return
@@ -170,11 +170,11 @@ class DiaryEntriesController < ApplicationController
         @entries = @entries.where(:language_code => params[:language])
         @title = t("diary_entries.feed.language.title", :language_name => Language.find(params[:language]).english_name)
         @description = t("diary_entries.feed.language.description", :language_name => Language.find(params[:language]).english_name)
-        @link = url_for :action => "index", :language => params[:language], :host => SERVER_URL, :protocol => SERVER_PROTOCOL
+        @link = url_for :action => "index", :language => params[:language], :host => Settings.server_url, :protocol => Settings.server_protocol
       else
         @title = t("diary_entries.feed.all.title")
         @description = t("diary_entries.feed.all.description")
-        @link = url_for :action => "index", :host => SERVER_URL, :protocol => SERVER_PROTOCOL
+        @link = url_for :action => "index", :host => Settings.server_url, :protocol => Settings.server_protocol
       end
     end
 
index b9cf8d096f35a635e8e9ad957258f097e51e8300..a877fc0926d575c56c9d6bed892447bd8f324602 100644 (file)
@@ -15,7 +15,7 @@ class GeocoderController < ApplicationController
     if @params[:lat] && @params[:lon]
       @sources.push "latlon"
       @sources.push "osm_nominatim_reverse"
-      @sources.push "geonames_reverse" if defined?(GEONAMES_USERNAME)
+      @sources.push "geonames_reverse" if Settings.key?(:geonames_username)
     elsif @params[:query]
       if @params[:query] =~ /^\d{5}(-\d{4})?$/
         @sources.push "osm_nominatim"
@@ -26,7 +26,7 @@ class GeocoderController < ApplicationController
         @sources.push "osm_nominatim"
       else
         @sources.push "osm_nominatim"
-        @sources.push "geonames" if defined?(GEONAMES_USERNAME)
+        @sources.push "geonames" if Settings.key?(:geonames_username)
       end
     end
 
@@ -93,7 +93,7 @@ class GeocoderController < ApplicationController
     if response.get_elements("geodata/error").empty?
       @results.push(:lat => response.text("geodata/latt"),
                     :lon => response.text("geodata/longt"),
-                    :zoom => POSTCODE_ZOOM,
+                    :zoom => Settings.postcode_zoom,
                     :name => query.upcase)
     end
 
@@ -118,7 +118,7 @@ class GeocoderController < ApplicationController
     exclude = "&exclude_place_ids=#{params[:exclude]}" if params[:exclude]
 
     # ask nominatim
-    response = fetch_xml("#{NOMINATIM_URL}search?format=xml&extratags=1&q=#{escape_query(query)}#{viewbox}#{exclude}&accept-language=#{http_accept_language.user_preferred_languages.join(',')}")
+    response = fetch_xml("#{Settings.nominatim_url}search?format=xml&extratags=1&q=#{escape_query(query)}#{viewbox}#{exclude}&accept-language=#{http_accept_language.user_preferred_languages.join(',')}")
 
     # extract the results from the response
     results =  response.elements["searchresults"]
@@ -182,7 +182,7 @@ class GeocoderController < ApplicationController
     @results = []
 
     # ask geonames.org
-    response = fetch_xml("http://api.geonames.org/search?q=#{escape_query(query)}&lang=#{lang}&maxRows=20&username=#{GEONAMES_USERNAME}")
+    response = fetch_xml("http://api.geonames.org/search?q=#{escape_query(query)}&lang=#{lang}&maxRows=20&username=#{Settings.geonames_username}")
 
     # parse the response
     response.elements.each("geonames/geoname") do |geoname|
@@ -192,7 +192,7 @@ class GeocoderController < ApplicationController
       country = geoname.text("countryName")
 
       @results.push(:lat => lat, :lon => lon,
-                    :zoom => GEONAMES_ZOOM,
+                    :zoom => Settings.geonames_zoom,
                     :name => name,
                     :suffix => ", #{country}")
     end
@@ -213,7 +213,7 @@ class GeocoderController < ApplicationController
     @results = []
 
     # ask nominatim
-    response = fetch_xml("#{NOMINATIM_URL}reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{http_accept_language.user_preferred_languages.join(',')}")
+    response = fetch_xml("#{Settings.nominatim_url}reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{http_accept_language.user_preferred_languages.join(',')}")
 
     # parse the response
     response.elements.each("reversegeocode/result") do |result|
@@ -247,7 +247,7 @@ class GeocoderController < ApplicationController
     @results = []
 
     # ask geonames.org
-    response = fetch_xml("http://api.geonames.org/countrySubdivision?lat=#{lat}&lng=#{lon}&lang=#{lang}&username=#{GEONAMES_USERNAME}")
+    response = fetch_xml("http://api.geonames.org/countrySubdivision?lat=#{lat}&lng=#{lon}&lang=#{lang}&username=#{Settings.geonames_username}")
 
     # parse the response
     response.elements.each("geonames/countrySubdivision") do |geoname|
@@ -255,7 +255,7 @@ class GeocoderController < ApplicationController
       country = geoname.text("countryName")
 
       @results.push(:lat => lat, :lon => lon,
-                    :zoom => GEONAMES_ZOOM,
+                    :zoom => Settings.geonames_zoom,
                     :name => name,
                     :suffix => ", #{country}")
     end
index dce0099e5b68caeceb12f1f5fa41865d4c3db0b9..5aa5aba709e33c2bf8f15a3e8442b928de548afc 100644 (file)
@@ -26,7 +26,7 @@ class MessagesController < ApplicationController
     @message.sender = current_user
     @message.sent_on = Time.now.getutc
 
-    if current_user.sent_messages.where("sent_on >= ?", Time.now.getutc - 1.hour).count >= MAX_MESSAGES_PER_HOUR
+    if current_user.sent_messages.where("sent_on >= ?", Time.now.getutc - 1.hour).count >= Settings.max_messages_per_hour
       flash[:error] = t ".limit_exceeded"
       render :action => "new"
     elsif @message.save
index 225fc0677a39b3fcd7951c7e7d8b5be56fabb62f..babd27c536ffd4eaf4d813e2fce559678a2fbadc 100644 (file)
@@ -39,7 +39,7 @@ class OauthController < ApplicationController
   end
 
   def oauth1_authorize
-    override_content_security_policy_directives(:form_action => []) if CSP_ENFORCE || defined?(CSP_REPORT_URL)
+    override_content_security_policy_directives(:form_action => []) if Settings.csp_enforce || Settings.key?(:csp_report_url)
 
     if @token.invalidated?
       @message = t "oauth.authorize_failure.invalid"
index b488d717aefcefc736d01568889c3b48a8ae8257..68a125f13f374b9475b7d72796019c4931e2109d 100644 (file)
@@ -121,7 +121,7 @@ class TracesController < ApplicationController
         flash[:notice] = t ".trace_uploaded"
         flash[:warning] = t ".traces_waiting", :count => current_user.traces.where(:inserted => false).count if current_user.traces.where(:inserted => false).count > 4
 
-        TraceImporterJob.perform_later(@trace) if TRACE_USE_JOB_QUEUE
+        TraceImporterJob.perform_later(@trace) if Settings.trace_use_job_queue
         redirect_to :action => :index, :display_name => current_user.display_name
       else
         flash[:error] = t("traces.create.upload_failed") if @trace.valid?
@@ -205,7 +205,7 @@ class TracesController < ApplicationController
       trace.visible = false
       trace.save
       flash[:notice] = t ".scheduled_for_deletion"
-      TraceDestroyerJob.perform_later(trace) if TRACE_USE_JOB_QUEUE
+      TraceDestroyerJob.perform_later(trace) if Settings.trace_use_job_queue
       redirect_to :action => :index, :display_name => trace.user.display_name
     end
   rescue ActiveRecord::RecordNotFound
index fa5b22a98951479efea3f00a4e3bb28a36a767b5..91742c7613aec51dc4d14ed6cf163b1ca82341c2 100644 (file)
@@ -16,7 +16,7 @@ class UsersController < ApplicationController
   before_action :allow_thirdparty_images, :only => [:show, :account]
 
   def terms
-    @legale = params[:legale] || OSM.ip_to_country(request.remote_ip) || DEFAULT_LEGALE
+    @legale = params[:legale] || OSM.ip_to_country(request.remote_ip) || Settings.default_legale
     @text = OSM.legal_text_for_country(@legale)
 
     if request.xhr?
@@ -332,7 +332,7 @@ class UsersController < ApplicationController
       flash[:error] = t "users.confirm_resend.failure", :name => params[:display_name]
     else
       Notifier.signup_confirm(user, user.tokens.create).deliver_later
-      flash[:notice] = t("users.confirm_resend.success", :email => user.email, :sender => SUPPORT_EMAIL).html_safe
+      flash[:notice] = t("users.confirm_resend.success", :email => user.email, :sender => Settings.support_email).html_safe
     end
 
     redirect_to :action => "login"
@@ -521,7 +521,7 @@ class UsersController < ApplicationController
         when "active", "confirmed" then
           successful_login(user, request.env["omniauth.params"]["referer"])
         when "suspended" then
-          failed_login t("users.login.account is suspended", :webmaster => "mailto:#{SUPPORT_EMAIL}").html_safe
+          failed_login t("users.login.account is suspended", :webmaster => "mailto:#{Settings.support_email}").html_safe
         else
           failed_login t("users.login.auth failure")
         end
@@ -549,7 +549,7 @@ class UsersController < ApplicationController
     elsif user = User.authenticate(:username => username, :password => password, :pending => true)
       unconfirmed_login(user)
     elsif User.authenticate(:username => username, :password => password, :suspended => true)
-      failed_login t("users.login.account is suspended", :webmaster => "mailto:#{SUPPORT_EMAIL}").html_safe, username
+      failed_login t("users.login.account is suspended", :webmaster => "mailto:#{Settings.support_email}").html_safe, username
     else
       failed_login t("users.login.auth failure"), username
     end
index a696a3d9cd79a38394877192b06226189d3b3888..1c2e5e65437b18370f9d05f9a79313d846f4dd50 100644 (file)
@@ -12,7 +12,7 @@ module NotifierHelper
         # the <a> but Outlook only on the <strong>
         :style => "text-decoration: none"
       ),
-      user_url(display_name, :host => SERVER_URL),
+      user_url(display_name, :host => Settings.server_url),
       :target => "_blank",
       :rel => "noopener",
       :style => "text-decoration: none; color: #222"
index 4b53c66f6825f1b38d5fdbde69653002762e9896..e705efb006756f09a6f5ff21ea8b7665689725cc 100644 (file)
@@ -1,6 +1,6 @@
 class Notifier < ActionMailer::Base
-  default :from => EMAIL_FROM,
-          :return_path => EMAIL_RETURN_PATH,
+  default :from => Settings.email_from,
+          :return_path => Settings.email_return_path,
           :auto_submitted => "auto-generated"
   helper :application
   before_action :set_shared_template_vars
@@ -196,14 +196,14 @@ class Notifier < ActionMailer::Base
   end
 
   def from_address(name, type, id, digest, user_id = nil)
-    if Object.const_defined?(:MESSAGES_DOMAIN) && domain = MESSAGES_DOMAIN
+    if Settings.key?(:messages_domain) && domain = Settings.messages_domain
       if user_id
         "#{name} <#{type}-#{id}-#{user_id}-#{digest[0, 6]}@#{domain}>"
       else
         "#{name} <#{type}-#{id}-#{digest[0, 6]}@#{domain}>"
       end
     else
-      EMAIL_FROM
+      Settings.email_from
     end
   end
 end
index 5dafaaa5c7afefd4097e30f0d3f7283245dacf92..ae95e2908a286793565915fd8f70577387df39c2 100644 (file)
@@ -67,7 +67,7 @@ class ClientApplication < ActiveRecord::Base
   end
 
   def oauth_server
-    @oauth_server ||= OAuth::Server.new("https://" + SERVER_URL)
+    @oauth_server ||= OAuth::Server.new("https://" + Settings.server_url)
   end
 
   def credentials
index ed0cc3ae4c89164f322f32380341f9dbcab0a7c8..f7c9501b56b3c84ce938a98b4966c4c3d8ac11d3 100644 (file)
@@ -77,6 +77,6 @@ class RequestToken < OauthToken
   end
 
   def oauth10?
-    (defined? OAUTH_10_SUPPORT) && OAUTH_10_SUPPORT && callback_url.blank?
+    Settings.key?(:oauth_10_support) && Settings.oauth_10_support && callback_url.blank?
   end
 end
index d2c71524505914e5739fa2b4e52b9176410a2b3f..892d41a2a217b5872cacc8a5724f63a36da5690c 100644 (file)
@@ -110,15 +110,15 @@ class Trace < ActiveRecord::Base
   end
 
   def large_picture_name
-    "#{GPX_IMAGE_DIR}/#{id}.gif"
+    "#{Settings.gpx_image_dir}/#{id}.gif"
   end
 
   def icon_picture_name
-    "#{GPX_IMAGE_DIR}/#{id}_icon.gif"
+    "#{Settings.gpx_image_dir}/#{id}_icon.gif"
   end
 
   def trace_name
-    "#{GPX_TRACE_DIR}/#{id}.gpx"
+    "#{Settings.gpx_trace_dir}/#{id}.gpx"
   end
 
   def mime_type
index fba429338246a1d48a866c2c5d0fa3fe458d7e32..9f13108434793d9f027fe67ac7eab81c19324cd5 100644 (file)
@@ -201,7 +201,7 @@ class User < ActiveRecord::Base
     @preferred_languages = nil
   end
 
-  def nearby(radius = NEARBY_RADIUS, num = NEARBY_USERS)
+  def nearby(radius = Settings.nearby_radius, num = Settings.nearby_users)
     if home_lon && home_lat
       gc = OSM::GreatCircle.new(home_lat, home_lon)
       sql_for_area = QuadTile.sql_for_area(gc.bounds(radius), "home_")
@@ -300,7 +300,7 @@ class User < ActiveRecord::Base
   ##
   # perform a spam check on a user
   def spam_check
-    update(:status => "suspended") if status == "active" && spam_score > SPAM_THRESHOLD
+    update(:status => "suspended") if status == "active" && spam_score > Settings.spam_threshold
   end
 
   ##
index 02af385a7a09389c88aa722ca8766054e3f2f29f..27bc40498b90ba455006ffd054a2eadbb3e7d60f 100644 (file)
@@ -32,7 +32,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 = USER_BLOCK_PERIODS
+  PERIODS = Settings.user_block_periods
 
   ##
   # scope to match active blocks
index c95a1212296acc56746aea30c7959ef0a6678db5..6573b9805ecc449aac0b365e5a9a31798b86f2c2 100644 (file)
@@ -206,7 +206,7 @@ class Way < ActiveRecord::Base
 
   def preconditions_ok?(old_nodes = [])
     return false if nds.empty?
-    raise OSM::APITooManyWayNodesError.new(id, nds.length, MAX_NUMBER_OF_WAY_NODES) if nds.length > MAX_NUMBER_OF_WAY_NODES
+    raise OSM::APITooManyWayNodesError.new(id, nds.length, Settings.max_number_of_way_nodes) if nds.length > Settings.max_number_of_way_nodes
 
     # check only the new nodes, for efficiency - old nodes having been checked last time and can't
     # be deleted when they're in-use.
index 3fa79058b13b759bd9b3c4eb43151fe4659a6d52..682373898be4398a2402a7668b620e12a946aa0a 100644 (file)
@@ -1,20 +1,20 @@
 xml.instruct! :xml, :version => "1.0"
 xml.osm(OSM::API.new.xml_root_attributes) do |osm|
   osm.api do |api|
-    api.version(:minimum => API_VERSION.to_s, :maximum => API_VERSION.to_s)
-    api.area(:maximum => MAX_REQUEST_AREA.to_s)
-    api.note_area(:maximum => MAX_NOTE_REQUEST_AREA.to_s)
-    api.tracepoints(:per_page => TRACEPOINTS_PER_PAGE.to_s)
-    api.waynodes(:maximum => MAX_NUMBER_OF_WAY_NODES.to_s)
-    api.changesets(:maximum_elements => Changeset::MAX_ELEMENTS.to_s)
-    api.timeout(:seconds => API_TIMEOUT.to_s)
-    api.status(:database => @database_status.to_s,
-               :api => @api_status.to_s,
-               :gpx => @gpx_status.to_s)
+    api.version(:minimum => Settings.api_version, :maximum => Settings.api_version)
+    api.area(:maximum => Settings.max_request_area)
+    api.note_area(:maximum => Settings.max_note_request_area)
+    api.tracepoints(:per_page => Settings.tracepoints_per_page)
+    api.waynodes(:maximum => Settings.max_number_of_way_nodes)
+    api.changesets(:maximum_elements => Changeset::MAX_ELEMENTS)
+    api.timeout(:seconds => Settings.api_timeout)
+    api.status(:database => @database_status,
+               :api => @api_status,
+               :gpx => @gpx_status)
   end
   osm.policy do |policy|
     policy.imagery do |imagery|
-      IMAGERY_BLACKLIST.each do |url_regex|
+      Settings.imagery_blacklist.each do |url_regex|
         imagery.blacklist(:regex => url_regex.to_s)
       end
     end
index 8c6b246d80b145f8fd3cd31102fa3219cc3fb346..86d4665cf0aea7dc3247d7961d30140c46741da4 100644 (file)
@@ -25,8 +25,8 @@
   <%= tag("meta", { :name => "msapplication-TileImage", :content => image_path("mstile-144x144.png") }) %>
   <%= tag("meta", { :name => "theme-color", :content => "#ffffff" }) %>
   <%= canonical_tag %>
-  <% if defined?(PUBLISHER_URL) -%>
-  <%= tag("link", { :rel => "publisher", :href => PUBLISHER_URL }) %>
+  <% if Settings.key?(:publisher_url) -%>
+  <%= tag("link", { :rel => "publisher", :href => Settings.publisher_url }) %>
   <% end -%>
   <%= tag("link", { :rel => "search", :type => "application/opensearchdescription+xml", :title => "OpenStreetMap Search", :href => asset_path("osm.xml") }) %>
   <%= tag("meta", { :name => "description", :content => "OpenStreetMap is the free wiki world map." }) %>
index 5b7c74d7f52dd608bcb41569b6db3c5577d6654b..369c81ae66531d8b70b10d4d4f9089fd1623c580 100644 (file)
@@ -1,6 +1,6 @@
 <p><%= t 'notifier.email_confirm_html.greeting' %></p>
 
-<p><%= t 'notifier.email_confirm_html.hopefully_you', :server_url => SERVER_URL, :new_address => @address %></p>
+<p><%= t 'notifier.email_confirm_html.hopefully_you', :server_url => Settings.server_url, :new_address => @address %></p>
 
 <p><%= t 'notifier.email_confirm_html.click_the_link' %></p>
 
index db9ae0f93f5abb6117880d4b3e771e47094983cc..7c4f0a5abbbe3718e131cb4a4632b4bab688540a 100644 (file)
@@ -1,6 +1,6 @@
 <%= t 'notifier.email_confirm_plain.greeting' %>
 
-<%= word_wrap(t 'notifier.email_confirm_plain.hopefully_you', :server_url => SERVER_URL, :new_address => @address) %>
+<%= word_wrap(t 'notifier.email_confirm_plain.hopefully_you', :server_url => Settings.server_url, :new_address => @address) %>
 
 <%= t 'notifier.email_confirm_plain.click_the_link' %>
 
index a0e0079fc537f92a1fa06c4fdb6ab235379634b5..ea7d101d0e94fbccd2f0511f59d45805be99805e 100644 (file)
@@ -1,6 +1,6 @@
 <p><%= t(".greeting") %></p>
 
-<p><%= t(".created", :site_url => SERVER_URL) %></p>
+<p><%= t(".created", :site_url => Settings.server_url) %></p>
 
 <p><%= t(".confirm") %></p>
 
index e170564687ec0e6f581053fc1033904e44f1de05..774209e5981d99290d0cd4cd60b7dc035c8f0f3d 100644 (file)
@@ -1,6 +1,6 @@
 <%= fp(t(".greeting")) %>
 
-<%= fp(t(".created", :site_url => SERVER_URL)) %>
+<%= fp(t(".created", :site_url => Settings.server_url)) %>
 
 <%= fp(t(".confirm")) %>
 
index 867b148fd4aeba0ea4b1ba5a47945d33a0e6a238..9b44ed4613f38a64345a3e980aa56a0a8dda31c4 100644 (file)
@@ -1,7 +1,7 @@
 <%= javascript_include_tag "edit/id" %>
 
 <div id="map">
-  <% data = { :key => ID_KEY } -%>
+  <% data = { :key => Settings.id_key } -%>
   <% data[:lat] = @lat if @lat -%>
   <% data[:lon] = @lon if @lon -%>
   <% data[:gpx] = trace_data_url(params[:gpx], :format => :xml) if params[:gpx] -%>
index 9e01eef302ab204e49d4d2d5278bd896b6aa7663..eb2a593768330017bf8d4577006a9c438c2feeda 100644 (file)
@@ -6,8 +6,8 @@
   <% data[:lat] = @lat if @lat -%>
   <% data[:lon] = @lon if @lon -%>
   <% data[:zoom] = @zoom if @zoom -%>
-  <% if defined? POTLATCH2_KEY %>
-  <% token = current_user.access_token(POTLATCH2_KEY) %>
+  <% if Settings.key?(:potlatch2_key) %>
+  <% token = current_user.access_token(Settings.potlatch2_key) %>
   <% data[:token] = token.token -%>
   <% data[:token_secret] = token.secret -%>
   <% data[:consumer_key] = token.client_application.key -%>
index c115ea59ff47d5c71596f603585535a8c66453bc..f8d0f5858cc7ab0dc3be3e9bade086b4cd32d69b 100644 (file)
@@ -9,8 +9,8 @@
 </head>
 <body>
 <% data = {} -%>
-<% if defined? ID_KEY %>
-<% token = current_user.access_token(ID_KEY) %>
+<% if Settings.key?(:id_key) %>
+<% token = current_user.access_token(Settings.id_key) %>
 <% data[:token] = token.token -%>
 <% data[:token_secret] = token.secret -%>
 <% data[:consumer_key] = token.client_application.key -%>
index 7638b7a770ed9162be1c78b0c4e7cf5f7e30faf2..233f2629fa96f1ca84174e4c873d8b17c36e376f 100644 (file)
@@ -85,7 +85,7 @@
     </div>
     <div class="form-row">
       <label class="standard-label"><%= t '.preferred editor' %></label>
-      <%= f.select :preferred_editor, [[t("editor.default", :name => t("editor.#{DEFAULT_EDITOR}.name")), 'default']] + Editors::ALL_EDITORS.collect { |e| [t("editor.#{e}.description"), e] } %>
+      <%= f.select :preferred_editor, [[t("editor.default", :name => t("editor.#{Settings.default_editor}.name")), 'default']] + Editors::ALL_EDITORS.collect { |e| [t("editor.#{e}.description"), e] } %>
     </div>
   </fieldset>
 
index d5be31ef649f278871bef192164d91f399424848..08ce4cc539454e02f3166332b3da6d02e3521bba 100644 (file)
@@ -6,5 +6,5 @@
 
 <div class="message">
   <h1><%= t 'users.new.no_auto_account_create' %></h1>
-  <h2><%= raw t 'users.new.contact_webmaster', :webmaster => "mailto:#{SUPPORT_EMAIL}" %></h2>
+  <h2><%= raw t 'users.new.contact_webmaster', :webmaster => "mailto:#{Settings.support_email}" %></h2>
 </div>
index 04a04158c93d973569c0392edeafd16fb0b06426..2e27875d2bab5f40d628547b6dd920f53b96a1c7 100644 (file)
 
         <ul class='clearfix' id="login_auth_buttons">
           <li><%= link_to image_tag("openid.png", :alt => t(".auth_providers.openid.title")), "#", :id => "openid_open_url", :title => t(".auth_providers.openid.title") %></li>
-          <% if defined?(GOOGLE_AUTH_ID) -%>
+          <% if Settings.key?(:google_auth_id) -%>
           <li><%= auth_button "google", "google" %></li>
           <% end -%>
-          <% if defined?(FACEBOOK_AUTH_ID) -%>
+          <% if Settings.key?(:facebook_auth_id) -%>
           <li><%= auth_button "facebook", "facebook" %></li>
           <% end -%>
-          <% if defined?(WINDOWSLIVE_AUTH_ID) -%>
+          <% if Settings.key?(:windowslive_auth_id) -%>
           <li><%= auth_button "windowslive", "windowslive" %></li>
           <% end -%>
-          <% if defined?(GITHUB_AUTH_ID) -%>
+          <% if Settings.key?(:github_auth_id) -%>
           <li><%= auth_button "github", "github" %></li>
           <% end -%>
-          <% if defined?(WIKIPEDIA_AUTH_ID) -%>
+          <% if Settings.key?(:wikipedia_auth_id) -%>
           <li><%= auth_button "wikipedia", "wikipedia" %></li>
           <% end -%>
           <li><%= auth_button "yahoo", "openid", :openid_url => "yahoo.com" %></li>
index 20547569d21842898798da6b592e53e2fc526fff..3a2df498ad197d0f8b2734cf716a4bccf7d67efc 100644 (file)
@@ -4,4 +4,4 @@
   <h1><%= t ".heading" %></h1>
 <% end %>
 
-<%= raw t ".body", :webmaster => link_to(t(".webmaster"), "mailto:#{SUPPORT_EMAIL}") %>
+<%= raw t ".body", :webmaster => link_to(t(".webmaster"), "mailto:#{Settings.support_email}") %>
index f8580b4261aeb954e811f0701876c6787b6d1939..b5649dd032e81aa0bf153efcb1d90e9bbfe20df4 100644 (file)
@@ -1,2 +1 @@
-application.yml
 database.yml
index 5139111cc8460dce6bb65d296ff8b84b2c82c37e..d521b4a9cc9764fe909c003a558e8356f772d5fc 100644 (file)
@@ -1,6 +1,34 @@
 require_relative "boot"
 
-require_relative "preinitializer"
+# Guard against deployments with old-style application.yml configurations
+# Otherwise, admins might not be aware that they are now silently ignored
+# and major problems could occur
+# rubocop:disable Rails/Output, Rails/Exit
+if File.exist?(File.expand_path("application.yml", __dir__))
+  puts "The config/application.yml file is no longer supported"
+  puts "Default settings are now found in config/settings.yml and you can override these in config/settings.local.yml"
+  puts "To prevent unexpected behaviour, please copy any custom settings to config/settings.local.yml"
+  puts " and then remove your config/application.yml file."
+  exit!
+end
+# rubocop:enable Rails/Output, Rails/Exit
+
+# Set the STATUS constant from the environment, if it matches a recognized value
+ALLOWED_STATUS = [
+  :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
+].freeze
+
+status = if ENV["STATUS"] && ALLOWED_STATUS.include?(ENV["STATUS"].to_sym)
+           ENV["STATUS"].to_sym
+         else
+           :online
+         end
+Object.const_set("STATUS", status)
 
 if STATUS == :database_offline
   require "action_controller/railtie"
@@ -42,13 +70,13 @@ module OpenStreetMap
     config.paths["app/models"].skip_eager_load! if STATUS == :database_offline
 
     # Use memcached for caching if required
-    config.cache_store = :mem_cache_store, MEMCACHE_SERVERS, { :namespace => "rails:cache" } if defined?(MEMCACHE_SERVERS)
+    config.cache_store = :mem_cache_store, Settings.memcache_servers, { :namespace => "rails:cache" } if Settings.key?(:memcache_servers)
 
     # Use logstash for logging if required
-    if defined?(LOGSTASH_PATH)
+    if Settings.key?(:logstash_path)
       config.logstasher.enabled = true
       config.logstasher.suppress_app_log = false
-      config.logstasher.logger_path = LOGSTASH_PATH
+      config.logstasher.logger_path = Settings.logstash_path
       config.logstasher.log_controller_parameters = true
     end
   end
index 9e15487ae4877fb80d9d1e0177958dbaee7efead..051c5dd44b5b12a739414b6c6698e9f4103be8e5 100644 (file)
@@ -57,7 +57,7 @@ Rails.application.configure do
   config.log_tags = [:request_id]
 
   # Use a different log path in production.
-  config.paths["log"] = LOG_PATH if defined?(LOG_PATH)
+  config.paths["log"] = Settings.log_path if Settings.key?(:log_path)
 
   # Use a different cache store in production.
   # config.cache_store = :mem_cache_store
diff --git a/config/example.application.yml b/config/example.application.yml
deleted file mode 100644 (file)
index 8596e10..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-defaults: &defaults
-  # The server protocol and host
-  server_protocol: "http"
-  server_url: "openstreetmap.example.com"
-  # Publisher
-  #publisher_url: ""
-  # The generator
-  generator: "OpenStreetMap server"
-  copyright_owner: "OpenStreetMap and contributors"
-  attribution_url: "http://www.openstreetmap.org/copyright"
-  license_url: "http://opendatacommons.org/licenses/odbl/1-0/"
-  # Support email address
-  support_email: "openstreetmap@example.com"
-  # Sender addresses for emails
-  email_from: "OpenStreetMap <openstreetmap@example.com>"
-  email_return_path: "openstreetmap@example.com"
-  # API version
-  api_version: "0.6"
-  # Application status - possible 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
-  max_request_area: 0.25
-  # Number of GPS trace/trackpoints returned per-page
-  tracepoints_per_page: 5000
-  # Maximum number of nodes that will be returned by the api in a map request
-  max_number_of_nodes: 50000
-  # Maximum number of nodes that can be in a way (checked on save)
-  max_number_of_way_nodes: 2000
-  # The maximum area you're allowed to request notes from, in square degrees
-  max_note_request_area: 25
-  # Zoom level to use for postcode results from the geocoder
-  postcode_zoom: 15
-  # Zoom level to use for geonames results from the geocoder
-  geonames_zoom: 12
-  # Timeout for API calls in seconds
-  api_timeout: 300
-  # Timeout for web pages in seconds
-  web_timeout: 30
-  # Periods (in hours) which are allowed for user blocks
-  user_block_periods: [0, 1, 3, 6, 12, 24, 48, 96]
-  # Rate limit for message sending
-  max_messages_per_hour: 60
-  # Domain for handling message replies
-  #messages_domain: "messages.openstreetmap.org"
-  # Geonames authentication details
-  #geonames_username: ""
-  # GeoIP database
-  #geoip_database: ""
-  # Users to show as being nearby
-  nearby_users: 30
-  # Max radius, in km, for nearby users
-  nearby_radius: 50
-  # Spam threshold
-  spam_threshold: 50
-  # Default legale (jurisdiction location) for contributor terms
-  default_legale: GB
-  # Use the built-in jobs queue for importing traces
-  # Leave as false if you are using the external high-speed gpx importer
-  # https://github.com/openstreetmap/gpx-import
-  trace_use_job_queue: false
-  # Location of GPX traces and images
-  gpx_trace_dir: "/home/osm/traces"
-  gpx_image_dir: "/home/osm/images"
-  # Location of data for attachments
-  attachments_dir: ":rails_root/public/attachments"
-  # Log file to use
-  #log_path: ""
-  # Log file to use for logstash
-  #logstash_path: ""
-  # List of memcache servers to use for caching
-  #memcache_servers: []
-  # Enable legacy OAuth 1.0 support
-  oauth_10_support: true
-  # URL of Nominatim instance to use for geocoding
-  nominatim_url: "https://nominatim.openstreetmap.org/"
-  # Default editor
-  default_editor: "id"
-  # OAuth consumer key for Potlatch 2
-  #potlatch2_key: ""
-  # OAuth consumer key for the web site
-  #oauth_key: ""
-  # OAuth consumer key for iD
-  #id_key: ""
-  # Imagery to return in capabilities as blacklisted
-  imagery_blacklist:
-    # Current Google imagery URLs have google or googleapis in the domain
-    # with a vt or kh endpoint, and x, y and z query parameters
-    - ".*\\.google(apis)?\\..*/(vt|kh)[\\?/].*([xyz]=.*){3}.*"
-    # Blacklist VWorld
-    - "http://xdworld\\.vworld\\.kr:8080/.*"
-    # Blacklist here
-    - ".*\\.here\\.com[/:].*"
-  # URL of Overpass instance to use for feature queries
-  overpass_url: "https://overpass-api.de/api/interpreter"
-  # Routing endpoints
-  graphhopper_url: "https://graphhopper.com/api/1/route"
-  fossgis_osrm_url: "https://routing.openstreetmap.de/"
-  # External authentication credentials
-  #google_auth_id: ""
-  #google_auth_secret: ""
-  #google_openid_realm: ""
-  #facebook_auth_id: ""
-  #facebook_auth_secret: ""
-  #windowslive_auth_id: ""
-  #windowslive_auth_secret: ""
-  #github_auth_id: ""
-  #github_auth_secret: ""
-  #wikipedia_auth_id: ""
-  #wikipedia_auth_secret: ""
-  # Thunderforest authentication details
-  #thunderforest_key: ""
-  # Key for generating TOTP tokens
-  #totp_key: ""
-  # Enforce Content-Security-Policy
-  csp_enforce: false
-  # URL for reporting Content-Security-Policy violations
-  #csp_report_url: ""
-
-development:
-  <<: *defaults
-
-production:
-  <<: *defaults
-
-test:
-  <<: *defaults
-  # Geonames credentials for testing
-  geonames_username: "dummy"
-  # External authentication credentials for testing
-  google_auth_id: "dummy"
-  google_auth_secret: "dummy"
-  google_openid_realm: "https://www.openstreetmap.org"
-  facebook_auth_id: "dummy"
-  facebook_auth_secret: "dummy"
-  windowslive_auth_id: "dummy"
-  windowslive_auth_secret: "dummy"
-  github_auth_id: "dummy"
-  github_auth_secret: "dummy"
-  wikipedia_auth_id: "dummy"
-  wikipedia_auth_secret: "dummy"
index 54da2813912d51396cdea479f6d0a219823eab78..32dfa79bbfea05f7de1396385727e8debec7baf8 100644 (file)
@@ -8,6 +8,6 @@ ActionMailer::Base.smtp_settings = {
 
 # Set the host and protocol for all ActionMailer URLs
 ActionMailer::Base.default_url_options = {
-  :host => SERVER_URL,
-  :protocol => SERVER_PROTOCOL
+  :host => Settings.server_url,
+  :protocol => Settings.server_protocol
 }
index 0d1461ed7b153758d893a1216a602a3f9ef792e8..c2c8440476adae5375cdc4713eeb9edd6bb70e89 100644 (file)
@@ -1,12 +1,12 @@
 CanonicalRails.setup do |config|
   # Force the protocol. If you do not specify, the protocol will be based on the incoming request's protocol.
 
-  config.protocol = "#{SERVER_PROTOCOL}://"
+  config.protocol = "#{Settings.server_protocol}://"
 
   # This is the main host, not just the TLD, omit slashes and protocol. If you have more than one, pick the one you want to rank in search results.
 
-  config.host = SERVER_URL
-  config.port = SERVER_PROTOCOL == "https" ? 443 : 80
+  config.host = Settings.server_url
+  config.port = Settings.server_protocol == "https" ? 443 : 80
 
   # http://en.wikipedia.org/wiki/URL_normalization
   # Trailing slash represents semantics of a directory, ie a collection view - implying an :index get route;
diff --git a/config/initializers/config.rb b/config/initializers/config.rb
new file mode 100644 (file)
index 0000000..caaab0c
--- /dev/null
@@ -0,0 +1,53 @@
+Config.setup do |config|
+  # Name of the constant exposing loaded settings
+  config.const_name = "Settings"
+
+  # Ability to remove elements of the array set in earlier loaded settings file. For example value: '--'.
+  #
+  # config.knockout_prefix = nil
+
+  # Overwrite an existing value when merging a `nil` value.
+  # When set to `false`, the existing value is retained after merge.
+  #
+  # config.merge_nil_values = true
+
+  # Overwrite arrays found in previously loaded settings file. When set to `false`, arrays will be merged.
+  #
+  # config.overwrite_arrays = true
+
+  # Load environment variables from the `ENV` object and override any settings defined in files.
+  #
+  # config.use_env = false
+
+  # Define ENV variable prefix deciding which variables to load into config.
+  #
+  # config.env_prefix = 'Settings'
+
+  # What string to use as level separator for settings loaded from ENV variables. Default value of '.' works well
+  # with Heroku, but you might want to change it for example for '__' to easy override settings from command line, where
+  # using dots in variable names might not be allowed (eg. Bash).
+  #
+  # config.env_separator = '.'
+
+  # Ability to process variables names:
+  #   * nil  - no change
+  #   * :downcase - convert to lower case
+  #
+  # config.env_converter = :downcase
+
+  # Parse numeric values as integers instead of strings.
+  #
+  # config.env_parse_values = true
+
+  # Validate presence and type of specific config values. Check https://github.com/dry-rb/dry-validation for details.
+  #
+  config.schema do
+    required(:api_version).filled(:str?)
+    required(:max_request_area).filled(:number?)
+    required(:max_note_request_area).filled(:number?)
+    required(:tracepoints_per_page).filled(:int?)
+    required(:max_number_of_way_nodes).filled(:int?)
+    required(:api_timeout).filled(:int?)
+    required(:imagery_blacklist).maybe(:array?)
+  end
+end
index 7e499c0e6960cc7aa2545d0ada0eb73bfe9274d7..dc5b28e66f55ef1b58cf3470c61e03e10d041add 100644 (file)
@@ -9,10 +9,10 @@ OpenID::Util.logger = Rails.logger
 OmniAuth.config.logger = Rails.logger
 OmniAuth.config.failure_raise_out_environments = []
 
-if defined?(MEMCACHE_SERVERS)
+if Settings.key?(:memcache_servers)
   require "openid/store/memcache"
 
-  openid_store = OpenID::Store::Memcache.new(Dalli::Client.new(MEMCACHE_SERVERS, :namespace => "rails"))
+  openid_store = OpenID::Store::Memcache.new(Dalli::Client.new(Settings.memcache_servers, :namespace => "rails"))
 else
   require "openid/store/filesystem"
 
@@ -26,13 +26,13 @@ windowslive_options = { :name => "windowslive", :scope => "wl.signin,wl.emails"
 github_options = { :name => "github", :scope => "user:email" }
 wikipedia_options = { :name => "wikipedia", :client_options => { :site => "https://meta.wikimedia.org" } }
 
-google_options[:openid_realm] = GOOGLE_OPENID_REALM if defined?(GOOGLE_OPENID_REALM)
+google_options[:openid_realm] = Settings.google_openid_realm if Settings.key?(:google_openid_realm)
 
 Rails.application.config.middleware.use OmniAuth::Builder do
   provider :openid, openid_options
-  provider :google_oauth2, GOOGLE_AUTH_ID, GOOGLE_AUTH_SECRET, google_options if defined?(GOOGLE_AUTH_ID)
-  provider :facebook, FACEBOOK_AUTH_ID, FACEBOOK_AUTH_SECRET, facebook_options if defined?(FACEBOOK_AUTH_ID)
-  provider :windowslive, WINDOWSLIVE_AUTH_ID, WINDOWSLIVE_AUTH_SECRET, windowslive_options if defined?(WINDOWSLIVE_AUTH_ID)
-  provider :github, GITHUB_AUTH_ID, GITHUB_AUTH_SECRET, github_options if defined?(GITHUB_AUTH_ID)
-  provider :mediawiki, WIKIPEDIA_AUTH_ID, WIKIPEDIA_AUTH_SECRET, wikipedia_options if defined?(WIKIPEDIA_AUTH_ID)
+  provider :google_oauth2, Settings.google_auth_id, Settings.google_auth_secret, google_options if Settings.key?(:google_auth_id)
+  provider :facebook, Settings.facebook_auth_id, Settings.facebook_auth_secret, facebook_options if Settings.key?(:facebook_auth_id)
+  provider :windowslive, Settings.windowslive_auth_id, Settings.windowslive_auth_secret, windowslive_options if Settings.key?(:windowslive_auth_id)
+  provider :github, Settings.github_auth_id, Settings.github_auth_secret, github_options if Settings.key?(:github_auth_id)
+  provider :mediawiki, Settings.wikipedia_auth_id, Settings.wikipedia_auth_secret, wikipedia_options if Settings.key?(:wikipedia_auth_id)
 end
index 4db3166ae9a4419003f541bc53772ddc557e9dc6..3aa1d003e354107cc672209daf8477bbe6827569 100644 (file)
@@ -21,5 +21,5 @@ Rails.application.config.after_initialize do |_app|
 end
 
 Paperclip::Attachment.default_options[:url] = "/attachments/:class/:attachment/:id_partition/:style/:fingerprint.:extension"
-Paperclip::Attachment.default_options[:path] = "#{ATTACHMENTS_DIR}/:class/:attachment/:id_partition/:style/:fingerprint.:extension"
+Paperclip::Attachment.default_options[:path] = "#{Settings.attachments_dir}/:class/:attachment/:id_partition/:style/:fingerprint.:extension"
 Paperclip::Attachment.default_options[:url_generator] = Paperclip::AssetUrlGenerator
index daddd762df65cbdaace333765f6769a425993eb7..54702a39915818ebbd0bace6a7486766c0b445cc 100644 (file)
@@ -21,7 +21,7 @@ csp_policy = {
 csp_policy[:connect_src] << PIWIK["location"] if defined?(PIWIK)
 csp_policy[:img_src] << PIWIK["location"] if defined?(PIWIK)
 csp_policy[:script_src] << PIWIK["location"] if defined?(PIWIK)
-csp_policy[:report_uri] << CSP_REPORT_URL if defined?(CSP_REPORT_URL)
+csp_policy[:report_uri] << Settings.csp_report_url if Settings.key?(:csp_report_url)
 
 cookie_policy = {
   :secure => SecureHeaders::OPT_OUT,
@@ -31,10 +31,10 @@ cookie_policy = {
 SecureHeaders::Configuration.default do |config|
   config.hsts = SecureHeaders::OPT_OUT
 
-  if CSP_ENFORCE
+  if Settings.csp_enforce
     config.csp = csp_policy
     config.csp_report_only = SecureHeaders::OPT_OUT
-  elsif defined?(CSP_REPORT_URL)
+  elsif Settings.key?(:csp_report_url)
     config.csp = SecureHeaders::OPT_OUT
     config.csp_report_only = csp_policy
   else
index a9c735d6255d40e20cdc2e6eaa5fc206850e6fa0..a122848553bf1a9f00fe4d09f2f18ee292617f3b 100644 (file)
@@ -1,7 +1,7 @@
 # Be sure to restart your server when you modify this file.
 
-if defined?(MEMCACHE_SERVERS)
-  Rails.application.config.session_store :mem_cache_store, :memcache_server => MEMCACHE_SERVERS, :namespace => "rails:session", :key => "_osm_session"
+if Settings.key?(:memcache_servers)
+  Rails.application.config.session_store :mem_cache_store, :memcache_server => Settings.memcache_servers, :namespace => "rails:session", :key => "_osm_session"
 else
   Rails.application.config.session_store :cache_store, :key => "_osm_session", :cache => ActiveSupport::Cache::MemoryStore.new
 end
diff --git a/config/preinitializer.rb b/config/preinitializer.rb
deleted file mode 100644 (file)
index 07f1057..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-require "yaml"
-
-env = if defined?(Rake.application) && Rake.application.top_level_tasks.grep(/^(default$|test(:|$))/).any?
-        "test"
-      else
-        ENV["RAILS_ENV"] || "development"
-      end
-
-config = YAML.load_file(File.expand_path(env == "test" ? "../example.application.yml" : "../application.yml", __FILE__))
-
-ENV.each do |key, value|
-  Object.const_set(Regexp.last_match(1).upcase, value) if key =~ /^OSM_(.*)$/
-end
-
-config[env].each do |key, value|
-  Object.const_set(key.upcase, value) unless Object.const_defined?(key.upcase)
-end
diff --git a/config/settings.yml b/config/settings.yml
new file mode 100644 (file)
index 0000000..4f267e5
--- /dev/null
@@ -0,0 +1,122 @@
+# The server protocol and host
+server_protocol: "http"
+server_url: "openstreetmap.example.com"
+# Publisher
+#publisher_url: ""
+# The generator
+generator: "OpenStreetMap server"
+copyright_owner: "OpenStreetMap and contributors"
+attribution_url: "http://www.openstreetmap.org/copyright"
+license_url: "http://opendatacommons.org/licenses/odbl/1-0/"
+# Support email address
+support_email: "openstreetmap@example.com"
+# Sender addresses for emails
+email_from: "OpenStreetMap <openstreetmap@example.com>"
+email_return_path: "openstreetmap@example.com"
+# API version
+api_version: "0.6"
+# Application status - possible 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
+max_request_area: 0.25
+# Number of GPS trace/trackpoints returned per-page
+tracepoints_per_page: 5000
+# Maximum number of nodes that will be returned by the api in a map request
+max_number_of_nodes: 50000
+# Maximum number of nodes that can be in a way (checked on save)
+max_number_of_way_nodes: 2000
+# The maximum area you're allowed to request notes from, in square degrees
+max_note_request_area: 25
+# Zoom level to use for postcode results from the geocoder
+postcode_zoom: 15
+# Zoom level to use for geonames results from the geocoder
+geonames_zoom: 12
+# Timeout for API calls in seconds
+api_timeout: 300
+# Timeout for web pages in seconds
+web_timeout: 30
+# Periods (in hours) which are allowed for user blocks
+user_block_periods: [0, 1, 3, 6, 12, 24, 48, 96]
+# Rate limit for message sending
+max_messages_per_hour: 60
+# Domain for handling message replies
+#messages_domain: "messages.openstreetmap.org"
+# Geonames authentication details
+#geonames_username: ""
+# GeoIP database
+#geoip_database: ""
+# Users to show as being nearby
+nearby_users: 30
+# Max radius, in km, for nearby users
+nearby_radius: 50
+# Spam threshold
+spam_threshold: 50
+# Default legale (jurisdiction location) for contributor terms
+default_legale: GB
+# Use the built-in jobs queue for importing traces
+# Leave as false if you are using the external high-speed gpx importer
+# https://github.com/openstreetmap/gpx-import
+trace_use_job_queue: false
+# Location of GPX traces and images
+gpx_trace_dir: "/home/osm/traces"
+gpx_image_dir: "/home/osm/images"
+# Location of data for attachments
+attachments_dir: ":rails_root/public/attachments"
+# Log file to use
+#log_path: ""
+# Log file to use for logstash
+#logstash_path: ""
+# List of memcache servers to use for caching
+#memcache_servers: []
+# Enable legacy OAuth 1.0 support
+oauth_10_support: true
+# URL of Nominatim instance to use for geocoding
+nominatim_url: "https://nominatim.openstreetmap.org/"
+# Default editor
+default_editor: "id"
+# OAuth consumer key for Potlatch 2
+#potlatch2_key: ""
+# OAuth consumer key for the web site
+#oauth_key: ""
+# OAuth consumer key for iD
+#id_key: ""
+# Imagery to return in capabilities as blacklisted
+imagery_blacklist:
+  # Current Google imagery URLs have google or googleapis in the domain
+  # with a vt or kh endpoint, and x, y and z query parameters
+  - ".*\\.google(apis)?\\..*/(vt|kh)[\\?/].*([xyz]=.*){3}.*"
+  # Blacklist VWorld
+  - "http://xdworld\\.vworld\\.kr:8080/.*"
+  # Blacklist here
+  - ".*\\.here\\.com[/:].*"
+# URL of Overpass instance to use for feature queries
+overpass_url: "https://overpass-api.de/api/interpreter"
+# Routing endpoints
+graphhopper_url: "https://graphhopper.com/api/1/route"
+fossgis_osrm_url: "https://routing.openstreetmap.de/"
+# External authentication credentials
+#google_auth_id: ""
+#google_auth_secret: ""
+#google_openid_realm: ""
+#facebook_auth_id: ""
+#facebook_auth_secret: ""
+#windowslive_auth_id: ""
+#windowslive_auth_secret: ""
+#github_auth_id: ""
+#github_auth_secret: ""
+#wikipedia_auth_id: ""
+#wikipedia_auth_secret: ""
+# Thunderforest authentication details
+#thunderforest_key: ""
+# Key for generating TOTP tokens
+#totp_key: ""
+# Enforce Content-Security-Policy
+csp_enforce: false
+# URL for reporting Content-Security-Policy violations
+#csp_report_url: ""
diff --git a/config/settings/development.yml b/config/settings/development.yml
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/config/settings/production.yml b/config/settings/production.yml
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/config/settings/test.yml b/config/settings/test.yml
new file mode 100644 (file)
index 0000000..307eb7f
--- /dev/null
@@ -0,0 +1,16 @@
+gpx_trace_dir: <%= Rails.root.join("test", "gpx", "traces") %>
+gpx_image_dir: <%= Rails.root.join("test", "gpx", "images") %>
+# Geonames credentials for testing
+geonames_username: "dummy"
+# External authentication credentials for testing
+google_auth_id: "dummy"
+google_auth_secret: "dummy"
+google_openid_realm: "https://www.openstreetmap.org"
+facebook_auth_id: "dummy"
+facebook_auth_secret: "dummy"
+windowslive_auth_id: "dummy"
+windowslive_auth_secret: "dummy"
+github_auth_id: "dummy"
+github_auth_secret: "dummy"
+wikipedia_auth_id: "dummy"
+wikipedia_auth_secret: "dummy"
index 434994329d7b62a435335dbbeb6da5c3489ee4b5..6190831f7ada6b8fa18c33a1c05b4036049bb351 100644 (file)
@@ -1,9 +1,9 @@
 module Auth
   PROVIDERS = { "None" => "", "OpenID" => "openid" }.tap do |providers|
-    providers["Google"] = "google" if defined?(GOOGLE_AUTH_ID)
-    providers["Facebook"] = "facebook" if defined?(FACEBOOK_AUTH_ID)
-    providers["Windows Live"] = "windowslive" if defined?(WINDOWSLIVE_AUTH_ID)
-    providers["GitHub"] = "github" if defined?(GITHUB_AUTH_ID)
-    providers["Wikipedia"] = "wikipedia" if defined?(WIKIPEDIA_AUTH_ID)
+    providers["Google"] = "google" if Settings.key?(:google_auth_id)
+    providers["Facebook"] = "facebook" if Settings.key?(:facebook_auth_id)
+    providers["Windows Live"] = "windowslive" if Settings.key?(:windowslive_auth_id)
+    providers["GitHub"] = "github" if Settings.key?(:github_auth_id)
+    providers["Wikipedia"] = "wikipedia" if Settings.key?(:wikipedia_auth_id)
   end.freeze
 end
index 6582a30c0157ed1af60b844853df84743a33e72d..d1c39f1f4dbf73674f6f875d4489c86be17a0c1a 100644 (file)
@@ -69,7 +69,7 @@ class BoundingBox
     self
   end
 
-  def check_size(max_area = MAX_REQUEST_AREA)
+  def check_size(max_area = Settings.max_request_area)
     # check the bbox isn't too large
     if area > max_area
       raise OSM::APIBadBoundingBox, "The maximum bbox size is " + max_area.to_s +
index 1951e3c31287f82d1bc15929a17573834e3a0c6e..743d1b1c665cbec9d0f2b462714b31c4a0428866 100644 (file)
@@ -502,16 +502,16 @@ module OSM
     end
 
     def xml_root_attributes
-      { "version" => API_VERSION.to_s,
-        "generator" => GENERATOR,
-        "copyright" => COPYRIGHT_OWNER,
-        "attribution" => ATTRIBUTION_URL,
-        "license" => LICENSE_URL }
+      { "version" => Settings.api_version,
+        "generator" => Settings.generator,
+        "copyright" => Settings.copyright_owner,
+        "attribution" => Settings.attribution_url,
+        "license" => Settings.license_url }
     end
   end
 
   def self.ip_to_country(ip_address)
-    ipinfo = geoip_database.country(ip_address) if defined?(GEOIP_DATABASE)
+    ipinfo = geoip_database.country(ip_address) if Settings.key?(:geoip_database)
 
     if ipinfo
       country = ipinfo.country_code2
@@ -566,7 +566,7 @@ module OSM
   # Return the terms and conditions text for a given country
   def self.legal_text_for_country(country_code)
     file_name = Rails.root.join("config", "legales", country_code.to_s + ".yml")
-    file_name = Rails.root.join("config", "legales", DEFAULT_LEGALE + ".yml") unless File.exist? file_name
+    file_name = Rails.root.join("config", "legales", Settings.default_legale + ".yml") unless File.exist? file_name
     YAML.load_file(file_name)
   end
 
@@ -577,6 +577,6 @@ module OSM
 
   # Return the GeoIP database handle
   def self.geoip_database
-    @geoip_database ||= GeoIP.new(GEOIP_DATABASE) if defined?(GEOIP_DATABASE)
+    @geoip_database ||= GeoIP.new(Settings.geoip_database) if Settings.key?(:geoip_database)
   end
 end
index 127201f9c2824d3c66607b392ba19cf92a9d323b..03869c638d8145a8d15953799f990d50f74d0a0e 100644 (file)
@@ -18,12 +18,12 @@ module Api
     def test_capabilities
       get :show
       assert_response :success
-      assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
+      assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
         assert_select "api", :count => 1 do
-          assert_select "version[minimum='#{API_VERSION}'][maximum='#{API_VERSION}']", :count => 1
-          assert_select "area[maximum='#{MAX_REQUEST_AREA}']", :count => 1
-          assert_select "note_area[maximum='#{MAX_NOTE_REQUEST_AREA}']", :count => 1
-          assert_select "tracepoints[per_page='#{TRACEPOINTS_PER_PAGE}']", :count => 1
+          assert_select "version[minimum='#{Settings.api_version}'][maximum='#{Settings.api_version}']", :count => 1
+          assert_select "area[maximum='#{Settings.max_request_area}']", :count => 1
+          assert_select "note_area[maximum='#{Settings.max_note_request_area}']", :count => 1
+          assert_select "tracepoints[per_page='#{Settings.tracepoints_per_page}']", :count => 1
           assert_select "changesets[maximum_elements='#{Changeset::MAX_ELEMENTS}']", :count => 1
           assert_select "status[database='online']", :count => 1
           assert_select "status[api='online']", :count => 1
index c212ba1d07a66506ced55c3be3a5b2ade3b38864..4b3090443b9a0b8102a1c7870ff46477b9a29a01 100644 (file)
@@ -32,7 +32,7 @@ module Api
         assert_response :success
         now = Time.now.getutc
         hourago = now - 1.hour
-        assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
+        assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
           assert_select "changes[starttime='#{hourago.xmlschema}'][endtime='#{now.xmlschema}']", :count => 1 do
             assert_select "tile", :count => 0
           end
@@ -47,7 +47,7 @@ module Api
         # changes at the time we have frozen at
         now = Time.now.getutc
         hourago = now - 1.hour
-        assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
+        assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
           assert_select "changes[starttime='#{hourago.xmlschema}'][endtime='#{now.xmlschema}']", :count => 1 do
             assert_select "tile", :count => 6
           end
@@ -70,7 +70,7 @@ module Api
         assert_response :success
         # NOTE: there was a test here for the timing, but it was too sensitive to be a good test
         # and it was annoying.
-        assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
+        assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
           assert_select "changes", :count => 1
         end
       end
index 730c3cbd96b0fbf398e34775f9a743c074c19d89..be4875630caece982a086a8f0d68630cbc6b4ffc 100644 (file)
@@ -137,14 +137,14 @@ module Api
       get :show, :params => { :id => changeset_id }
       assert_response :success, "cannot get first changeset"
 
-      assert_select "osm[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
+      assert_select "osm[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1
       assert_select "osm>changeset[id='#{changeset_id}']", 1
       assert_select "osm>changeset>discussion", 0
 
       get :show, :params => { :id => changeset_id, :include_discussion => true }
       assert_response :success, "cannot get first changeset with comments"
 
-      assert_select "osm[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
+      assert_select "osm[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1
       assert_select "osm>changeset[id='#{changeset_id}']", 1
       assert_select "osm>changeset>discussion", 1
       assert_select "osm>changeset>discussion>comment", 0
@@ -155,7 +155,7 @@ module Api
       get :show, :params => { :id => changeset_id, :include_discussion => true }
       assert_response :success, "cannot get closed changeset with comments"
 
-      assert_select "osm[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
+      assert_select "osm[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1
       assert_select "osm>changeset[id='#{changeset_id}']", 1
       assert_select "osm>changeset>discussion", 1
       assert_select "osm>changeset>discussion>comment", 3
@@ -409,7 +409,7 @@ CHANGESET
                       "can't upload a simple valid creation to changeset: #{@response.body}"
 
       # check the returned payload
-      assert_select "diffResult[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
+      assert_select "diffResult[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1
       assert_select "diffResult>node", 1
       assert_select "diffResult>way", 1
       assert_select "diffResult>relation", 1
@@ -647,7 +647,7 @@ CHANGESET
                       "can't do a conditional delete of in use objects: #{@response.body}"
 
       # check the returned payload
-      assert_select "diffResult[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
+      assert_select "diffResult[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1
       assert_select "diffResult>node", 1
       assert_select "diffResult>way", 1
       assert_select "diffResult>relation", 1
@@ -742,7 +742,7 @@ CHANGESET
                       "can't upload a complex diff to changeset: #{@response.body}"
 
       # check the returned payload
-      assert_select "diffResult[version='#{API_VERSION}'][generator='#{GENERATOR}']", 1
+      assert_select "diffResult[version='#{Settings.api_version}'][generator='#{Settings.generator}']", 1
       assert_select "diffResult>node", 1
       assert_select "diffResult>way", 1
       assert_select "diffResult>relation", 1
@@ -1234,7 +1234,7 @@ CHANGESET
                       "failed to return error in XML format"
 
       # check the returned payload
-      assert_select "osmError[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
+      assert_select "osmError[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1
       assert_select "osmError>status", 1
       assert_select "osmError>message", 1
     end
@@ -1428,7 +1428,7 @@ CHANGESET
       assert_template nil
       # print @response.body
       # FIXME: needs more assert_select tests
-      assert_select "osmChange[version='#{API_VERSION}'][generator='#{GENERATOR}']" do
+      assert_select "osmChange[version='#{Settings.api_version}'][generator='#{Settings.generator}']" do
         assert_select "create", :count => 5
         assert_select "create>node[id='#{node.id}'][visible='#{node.visible?}'][version='#{node.version}']" do
           assert_select "tag[k='#{tag.k}'][v='#{tag.v}']"
index 5ee5a9e6ccaffb63eb65e941f532e79a502c6f9d..db83aaa9f32fe4a29fdf8f0de5dbf13757249923 100644 (file)
@@ -49,7 +49,7 @@ module Api
         print @response.body
       end
       assert_response :success, "Expected scucess with the map call"
-      assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
+      assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
         assert_select "bounds[minlon='#{format('%.7f', minlon)}'][minlat='#{format('%.7f', minlat)}'][maxlon='#{format('%.7f', maxlon)}'][maxlat='#{format('%.7f', maxlat)}']", :count => 1
         assert_select "node[id='#{node.id}'][lat='#{format('%.7f', node.lat)}'][lon='#{format('%.7f', node.lon)}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
           # This should really be more generic
@@ -75,7 +75,7 @@ module Api
       bbox = "#{node.lon},#{node.lat},#{node.lon},#{node.lat}"
       get :index, :params => { :bbox => bbox }
       assert_response :success, "The map call should have succeeded"
-      assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
+      assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
         assert_select "bounds[minlon='#{node.lon}'][minlat='#{node.lat}'][maxlon='#{node.lon}'][maxlat='#{node.lat}']", :count => 1
         assert_select "node[id='#{node.id}'][lat='#{format('%.7f', node.lat)}'][lon='#{format('%.7f', node.lon)}'][version='#{node.version}'][changeset='#{node.changeset_id}'][visible='#{node.visible}'][timestamp='#{node.timestamp.xmlschema}']", :count => 1 do
           # This should really be more generic
@@ -103,7 +103,7 @@ module Api
       bbox = "#{node.lon},#{node.lat},#{node.lon},#{node.lat}"
       get :index, :params => { :bbox => bbox }
       assert_response :success, "The map call should have succeeded"
-      assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
+      assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
         assert_select "bounds[minlon='#{node.lon}'][minlat='#{node.lat}'][maxlon='#{node.lon}'][maxlat='#{node.lat}']", :count => 1
         assert_select "node", :count => 3
         assert_select "node[id='#{node.id}']", :count => 1
@@ -120,7 +120,7 @@ module Api
     def test_map_empty
       get :index, :params => { :bbox => "179.998,89.998,179.999.1,89.999" }
       assert_response :success, "The map call should have succeeded"
-      assert_select "osm[version='#{API_VERSION}'][generator='#{GENERATOR}']", :count => 1 do
+      assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
         assert_select "bounds[minlon='179.9980000'][minlat='89.9980000'][maxlon='179.9990000'][maxlat='89.9990000']", :count => 1
         assert_select "node", :count => 0
         assert_select "way", :count => 0
@@ -138,7 +138,7 @@ module Api
       @badbigbbox.each do |bbox|
         get :index, :params => { :bbox => bbox }
         assert_response :bad_request, "The bbox:#{bbox} was expected to be too big"
-        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}"
+        assert_equal "The maximum bbox size is #{Settings.max_request_area}, and your request was too large. Either request a smaller area, or use planet.osm", @response.body, "bbox: #{bbox}"
       end
     end
 
index e5390922d64446467e44f9b802c98059fa28b401..4d2969026aa3621dea4936c2abf674425880553d 100644 (file)
@@ -133,7 +133,7 @@ module Api
       assert_response :success
 
       # count one osm element
-      assert_select "osm[version='#{API_VERSION}'][generator='OpenStreetMap server']", 1
+      assert_select "osm[version='#{Settings.api_version}'][generator='OpenStreetMap server']", 1
 
       # we should have only the expected number of relations
       assert_select "osm>relation", expected_relations.size
index b9a1c126f350b5bcf06c8ddbc85f386fbd21a8ae..e02dca53307c38d8a6c3ae13f09882cbaca64a81 100644 (file)
@@ -115,7 +115,7 @@ module Api
       @badbigbbox.each do |bbox|
         get :index, :params => { :bbox => bbox }
         assert_response :bad_request, "The bbox:#{bbox} was expected to be too big"
-        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}"
+        assert_equal "The maximum bbox size is #{Settings.max_request_area}, and your request was too large. Either request a smaller area, or use planet.osm", @response.body, "bbox: #{bbox}"
       end
     end
 
index 4f28514775d6cc9284ac95ea0ca47462d55c93da..0466ac9962ff72756daa48ed45b5ea25fc352f12 100644 (file)
@@ -3,23 +3,9 @@ require "minitest/mock"
 
 module Api
   class TracesControllerTest < ActionController::TestCase
-    def setup
-      @gpx_trace_dir = Object.send("remove_const", "GPX_TRACE_DIR")
-      Object.const_set("GPX_TRACE_DIR", Rails.root.join("test", "gpx", "traces"))
-
-      @gpx_image_dir = Object.send("remove_const", "GPX_IMAGE_DIR")
-      Object.const_set("GPX_IMAGE_DIR", Rails.root.join("test", "gpx", "images"))
-    end
-
     def teardown
-      File.unlink(*Dir.glob(File.join(GPX_TRACE_DIR, "*.gpx")))
-      File.unlink(*Dir.glob(File.join(GPX_IMAGE_DIR, "*.gif")))
-
-      Object.send("remove_const", "GPX_TRACE_DIR")
-      Object.const_set("GPX_TRACE_DIR", @gpx_trace_dir)
-
-      Object.send("remove_const", "GPX_IMAGE_DIR")
-      Object.const_set("GPX_IMAGE_DIR", @gpx_image_dir)
+      File.unlink(*Dir.glob(File.join(Settings.gpx_trace_dir, "*.gpx")))
+      File.unlink(*Dir.glob(File.join(Settings.gpx_image_dir, "*.gif")))
     end
 
     ##
index 8e4d5eeb27fd0f4cd062c2dc7627fa5dea2997cd..0348163bab100535279fe5d355f48bb5dd0d7ff9 100644 (file)
@@ -190,7 +190,7 @@ class MessagesControllerTest < ActionController::TestCase
     assert_equal "[OpenStreetMap] Test Message", e.subject
     assert_match(/Test message body/, e.text_part.decoded)
     assert_match(/Test message body/, e.html_part.decoded)
-    assert_match %r{#{SERVER_URL}/messages/[0-9]+}, e.text_part.decoded
+    assert_match %r{#{Settings.server_url}/messages/[0-9]+}, e.text_part.decoded
     ActionMailer::Base.deliveries.clear
     m = Message.last
     assert_equal user.id, m.from_user_id
@@ -483,12 +483,11 @@ class MessagesControllerTest < ActionController::TestCase
   private
 
   def with_message_limit(value)
-    max_messages_per_hour = Object.send("remove_const", "MAX_MESSAGES_PER_HOUR")
-    Object.const_set("MAX_MESSAGES_PER_HOUR", value)
+    max_messages_per_hour = Settings.max_messages_per_hour
+    Settings.max_messages_per_hour = value
 
     yield
 
-    Object.send("remove_const", "MAX_MESSAGES_PER_HOUR")
-    Object.const_set("MAX_MESSAGES_PER_HOUR", max_messages_per_hour)
+    Settings.max_messages_per_hour = max_messages_per_hour
   end
 end
index c4e1a5a66309bfc96ddaec3244c8e649cad60002..a2ea86f6f661c2c469a3c472dab5c197739e4c6b 100644 (file)
@@ -4,8 +4,8 @@ class SiteControllerTest < ActionController::TestCase
   ##
   # setup oauth keys
   def setup
-    Object.const_set("ID_KEY", create(:client_application).key)
-    Object.const_set("POTLATCH2_KEY", create(:client_application).key)
+    Settings.id_key = create(:client_application).key
+    Settings.potlatch2_key = create(:client_application).key
 
     stub_hostip_requests
   end
@@ -13,8 +13,8 @@ class SiteControllerTest < ActionController::TestCase
   ##
   # clear oauth keys
   def teardown
-    Object.send("remove_const", "ID_KEY")
-    Object.send("remove_const", "POTLATCH2_KEY")
+    Settings.id_key = nil
+    Settings.potlatch2_key = nil
   end
 
   ##
@@ -173,7 +173,7 @@ class SiteControllerTest < ActionController::TestCase
     get :edit, :session => { :user => create(:user) }
     assert_response :success
     assert_template "edit"
-    assert_template :partial => "_#{DEFAULT_EDITOR}", :count => 1
+    assert_template :partial => "_#{Settings.default_editor}", :count => 1
   end
 
   # Test the right editor gets used when the user has set a preference
index 84469437ac8524b7be304df60073430fed9f5642..daa8a678729a31e8a5fc92ddff6ddda955d0ee16 100644 (file)
@@ -2,23 +2,9 @@ require "test_helper"
 require "minitest/mock"
 
 class TracesControllerTest < ActionController::TestCase
-  def setup
-    @gpx_trace_dir = Object.send("remove_const", "GPX_TRACE_DIR")
-    Object.const_set("GPX_TRACE_DIR", Rails.root.join("test", "gpx", "traces"))
-
-    @gpx_image_dir = Object.send("remove_const", "GPX_IMAGE_DIR")
-    Object.const_set("GPX_IMAGE_DIR", Rails.root.join("test", "gpx", "images"))
-  end
-
   def teardown
-    File.unlink(*Dir.glob(File.join(GPX_TRACE_DIR, "*.gpx")))
-    File.unlink(*Dir.glob(File.join(GPX_IMAGE_DIR, "*.gif")))
-
-    Object.send("remove_const", "GPX_TRACE_DIR")
-    Object.const_set("GPX_TRACE_DIR", @gpx_trace_dir)
-
-    Object.send("remove_const", "GPX_IMAGE_DIR")
-    Object.const_set("GPX_IMAGE_DIR", @gpx_image_dir)
+    File.unlink(*Dir.glob(File.join(Settings.gpx_trace_dir, "*.gpx")))
+    File.unlink(*Dir.glob(File.join(Settings.gpx_image_dir, "*.gif")))
   end
 
   ##
index 9381365920a8ab116efbb65ee7cedf2f70bc12ac..3bc6ded98b74b164f9af4ba62cbfc6e8879713cf 100644 (file)
@@ -8,10 +8,10 @@ class UserBlocksTest < ActionDispatch::IntegrationTest
   def test_api_blocked
     blocked_user = create(:user)
 
-    get "/api/#{API_VERSION}/user/details"
+    get "/api/#{Settings.api_version}/user/details"
     assert_response :unauthorized
 
-    get "/api/#{API_VERSION}/user/details", :headers => auth_header(blocked_user.display_name, "test")
+    get "/api/#{Settings.api_version}/user/details", :headers => auth_header(blocked_user.display_name, "test")
     assert_response :success
 
     # now block the user
@@ -21,7 +21,7 @@ class UserBlocksTest < ActionDispatch::IntegrationTest
       :reason => "testing",
       :ends_at => Time.now.getutc + 5.minutes
     )
-    get "/api/#{API_VERSION}/user/details", :headers => auth_header(blocked_user.display_name, "test")
+    get "/api/#{Settings.api_version}/user/details", :headers => auth_header(blocked_user.display_name, "test")
     assert_response :forbidden
   end
 
@@ -35,7 +35,7 @@ class UserBlocksTest < ActionDispatch::IntegrationTest
       :reason => "testing",
       :ends_at => Time.now.getutc + 5.minutes
     )
-    get "/api/#{API_VERSION}/user/details", :headers => auth_header(blocked_user.display_name, "test")
+    get "/api/#{Settings.api_version}/user/details", :headers => auth_header(blocked_user.display_name, "test")
     assert_response :forbidden
 
     # revoke the ban
@@ -54,7 +54,7 @@ class UserBlocksTest < ActionDispatch::IntegrationTest
     reset!
 
     # access the API again. this time it should work
-    get "/api/#{API_VERSION}/user/details", :headers => auth_header(blocked_user.display_name, "test")
+    get "/api/#{Settings.api_version}/user/details", :headers => auth_header(blocked_user.display_name, "test")
     assert_response :success
   end
 end
index 416d226ccd472fde9c735df02990433229475864..32fdba0b2c09516f26209de4400863213ef344b4 100644 (file)
@@ -8,14 +8,14 @@ class UserTermsSeenTest < ActionDispatch::IntegrationTest
   def test_api_blocked
     user = create(:user, :terms_seen => false, :terms_agreed => nil)
 
-    get "/api/#{API_VERSION}/user/preferences", :headers => auth_header(user.display_name, "test")
+    get "/api/#{Settings.api_version}/user/preferences", :headers => auth_header(user.display_name, "test")
     assert_response :forbidden
 
     # touch it so that the user has seen the terms
     user.terms_seen = true
     user.save
 
-    get "/api/#{API_VERSION}/user/preferences", :headers => auth_header(user.display_name, "test")
+    get "/api/#{Settings.api_version}/user/preferences", :headers => auth_header(user.display_name, "test")
     assert_response :success
   end
 
index 1497040f04a22ddd946ca101886183054fc2bc04..f03488a6115324e631624edf397f461d1960f8ed 100644 (file)
@@ -2,23 +2,9 @@ require "test_helper"
 require "minitest/mock"
 
 class TraceTest < ActiveSupport::TestCase
-  def setup
-    @gpx_trace_dir = Object.send("remove_const", "GPX_TRACE_DIR")
-    Object.const_set("GPX_TRACE_DIR", Rails.root.join("test", "gpx", "traces"))
-
-    @gpx_image_dir = Object.send("remove_const", "GPX_IMAGE_DIR")
-    Object.const_set("GPX_IMAGE_DIR", Rails.root.join("test", "gpx", "images"))
-  end
-
   def teardown
-    File.unlink(*Dir.glob(File.join(GPX_TRACE_DIR, "*.gpx")))
-    File.unlink(*Dir.glob(File.join(GPX_IMAGE_DIR, "*.gif")))
-
-    Object.send("remove_const", "GPX_TRACE_DIR")
-    Object.const_set("GPX_TRACE_DIR", @gpx_trace_dir)
-
-    Object.send("remove_const", "GPX_IMAGE_DIR")
-    Object.const_set("GPX_IMAGE_DIR", @gpx_image_dir)
+    File.unlink(*Dir.glob(File.join(Settings.gpx_trace_dir, "*.gpx")))
+    File.unlink(*Dir.glob(File.join(Settings.gpx_image_dir, "*.gif")))
   end
 
   def test_visible
@@ -227,7 +213,7 @@ class TraceTest < ActiveSupport::TestCase
     FakeFS do
       FakeFS::FileSystem.clone(Rails.root.join("test", "gpx"))
       trace = create(:trace, :fixture => "a")
-      icon_path = File.join(GPX_IMAGE_DIR, "#{trace.id}_icon.gif")
+      icon_path = File.join(Settings.gpx_image_dir, "#{trace.id}_icon.gif")
       FileUtils.rm(icon_path)
       assert_equal false, File.exist?(icon_path)
 
@@ -241,7 +227,7 @@ class TraceTest < ActiveSupport::TestCase
     FakeFS do
       FakeFS::FileSystem.clone(Rails.root.join("test", "gpx"))
       trace = create(:trace, :fixture => "a")
-      large_picture_path = File.join(GPX_IMAGE_DIR, "#{trace.id}.gif")
+      large_picture_path = File.join(Settings.gpx_image_dir, "#{trace.id}.gif")
       FileUtils.rm(large_picture_path)
       assert_equal false, File.exist?(large_picture_path)
 
index fb37be1b4fdfb40b31a49957222ae32f9b1dd036..3c44f2f26bd6ddb5975920b2e6948038defb5e4f 100644 (file)
@@ -29,7 +29,7 @@ class WayTest < ActiveSupport::TestCase
     # Take one of the current ways and add nodes to it until we are near the limit
     assert way.valid?
     # it already has 1 node
-    1.upto(MAX_NUMBER_OF_WAY_NODES / 2) do
+    1.upto(Settings.max_number_of_way_nodes / 2) do
       way.add_nd_num(node_a.id)
       way.add_nd_num(node_b.id)
     end