From 9dbe1a497af89d3e53aad1af091d296520a74c6f Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 26 Jul 2007 17:15:23 +0000 Subject: [PATCH] Add a flag to allow the API to be placed in read-only mode. --- app/controllers/amf_controller.rb | 2 ++ app/controllers/application.rb | 11 +++++++++- app/controllers/node_controller.rb | 1 + app/controllers/segment_controller.rb | 1 + app/controllers/swf_controller.rb | 1 + app/controllers/way_controller.rb | 1 + app/views/layouts/site.rhtml | 8 ++++++- app/views/site/edit.rhtml | 31 ++++++++++++++++----------- config/environment.rb | 3 +++ public/stylesheets/site.css | 11 ++++++++++ 10 files changed, 56 insertions(+), 14 deletions(-) diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 3bcab182b..ed4f87b21 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -1,6 +1,8 @@ class AmfController < ApplicationController require 'stringio' + before_filter :check_availability + # to log: # RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}") diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 792792f83..085a3fa9f 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -34,10 +34,19 @@ class ApplicationController < ActionController::Base # no auth, the user does not exist or the password was wrong response.headers["Status"] = "Unauthorized" response.headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\"" - render_text(errormessage, 401) # :unauthorized + render :text => errormessage, :status => :unauthorized + return false end end + def check_availability + if API_READONLY + response.headers['Error'] = "Database offline for maintenance" + render :nothing => true, :status => :service_unavailable + return false + end + end + # Report and error to the user # (If anyone ever fixes Rails so it can set a http status "reason phrase", # rather than only a status code and having the web engine make up a diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index 3f3f882ae..fba41e330 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/node_controller.rb @@ -2,6 +2,7 @@ class NodeController < ApplicationController require 'xml/libxml' before_filter :authorize, :only => [:create, :update, :delete] + before_filter :check_availability, :only => [:create, :update, :delete] after_filter :compress_output def create diff --git a/app/controllers/segment_controller.rb b/app/controllers/segment_controller.rb index 2d55bbf79..070c2be81 100644 --- a/app/controllers/segment_controller.rb +++ b/app/controllers/segment_controller.rb @@ -2,6 +2,7 @@ class SegmentController < ApplicationController require 'xml/libxml' before_filter :authorize, :only => [:create, :update, :delete] + before_filter :check_availability, :only => [:create, :update, :delete] after_filter :compress_output def create diff --git a/app/controllers/swf_controller.rb b/app/controllers/swf_controller.rb index a58e899e0..9a4516016 100644 --- a/app/controllers/swf_controller.rb +++ b/app/controllers/swf_controller.rb @@ -1,4 +1,5 @@ class SwfController < ApplicationController + before_filter :check_availability # to log: # RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}") diff --git a/app/controllers/way_controller.rb b/app/controllers/way_controller.rb index ea22206a3..b1adf25a2 100644 --- a/app/controllers/way_controller.rb +++ b/app/controllers/way_controller.rb @@ -2,6 +2,7 @@ class WayController < ApplicationController require 'xml/libxml' before_filter :authorize, :only => [:create, :update, :delete] + before_filter :check_availability, :only => [:create, :update, :delete] after_filter :compress_output def create diff --git a/app/views/layouts/site.rhtml b/app/views/layouts/site.rhtml index 52d51f3f8..c2e831bf7 100644 --- a/app/views/layouts/site.rhtml +++ b/app/views/layouts/site.rhtml @@ -71,6 +71,13 @@ <% end %> + <% if API_READONLY %> +
+ The OpenStreetMap database is currently in read-only mode while + essential database maintenance work is carried out. +
+ <% end %> +
Help & Wiki
<%= link_to "Users' diaries", {:controller => 'diary_entry', :action => 'list', :display_name => nil} %>
@@ -78,7 +85,6 @@ Shop
- <%= yield :optionals %> - - + +<% end %> diff --git a/config/environment.rb b/config/environment.rb index 1265abe3b..d3c68ca69 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -67,6 +67,9 @@ end # inflect.uncountable %w( fish sheep ) # end +# Set to true to put the API in read-only mode +API_READONLY = false + # Include your application configuration below SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org' diff --git a/public/stylesheets/site.css b/public/stylesheets/site.css index 008089ed2..194eee874 100644 --- a/public/stylesheets/site.css +++ b/public/stylesheets/site.css @@ -80,6 +80,17 @@ body { font-size: 11px; } +#alert { + width: 150px; + margin: 10px; + padding: 10px; + border: 1px solid #ccc; + background: #d00; + line-height: 1.2em; + text-align: left; + font-size: 14px; +} + .left_menu { width: 150px; min-width: 150px; -- 2.43.2