From 09fdee54938792f06ce5b0636f01440a17117add Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 14 Apr 2009 14:27:30 +0000 Subject: [PATCH] Add a "database readonly" state that allows all writes to the database to be suppressed. --- app/controllers/amf_controller.rb | 2 +- app/controllers/api_controller.rb | 2 +- app/controllers/application.rb | 18 +++++++++++++----- app/controllers/diary_entry_controller.rb | 3 ++- app/controllers/message_controller.rb | 2 ++ app/controllers/node_controller.rb | 4 ++-- app/controllers/old_node_controller.rb | 2 +- app/controllers/old_way_controller.rb | 2 +- app/controllers/relation_controller.rb | 4 ++-- app/controllers/swf_controller.rb | 2 +- app/controllers/trace_controller.rb | 6 ++++-- app/controllers/user_controller.rb | 5 +++-- app/controllers/way_controller.rb | 4 ++-- app/views/layouts/site.rhtml | 2 +- app/views/site/edit.rhtml | 2 +- app/views/site/offline.rhtml | 6 ++++++ config/environment.rb | 1 + 17 files changed, 44 insertions(+), 23 deletions(-) diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 03d952b96..7f85280b7 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -29,7 +29,7 @@ class AmfController < ApplicationController include Potlatch session :off - before_filter :check_write_availability + before_filter :check_api_writable # Main AMF handlers: process the raw AMF string (using AMF library) and # calls each action (private method) accordingly. diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index 7a0a45fc8..029e4c8a6 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -1,7 +1,7 @@ class ApiController < ApplicationController session :off - before_filter :check_read_availability, :except => [:capabilities] + before_filter :check_api_readable, :except => [:capabilities] after_filter :compress_output # Help methods for checking boundary sanity and area size diff --git a/app/controllers/application.rb b/app/controllers/application.rb index ce13a6aa3..615022656 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -2,7 +2,7 @@ # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base - if OSM_STATUS == :database_offline + if OSM_STATUS == :database_readonly or OSM_STATUS == :database_offline session :off end @@ -43,13 +43,20 @@ class ApplicationController < ActionController::Base end end - def check_database_availability(need_api = false) + def check_database_readable(need_api = false) if OSM_STATUS == :database_offline or (need_api and OSM_STATUS == :api_offline) redirect_to :controller => 'site', :action => 'offline' end end - def check_read_availability + 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)) + redirect_to :controller => 'site', :action => 'offline' + end + end + + def check_api_readable if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline response.headers['Error'] = "Database offline for maintenance" render :nothing => true, :status => :service_unavailable @@ -57,8 +64,9 @@ class ApplicationController < ActionController::Base end end - def check_write_availability - if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline or OSM_STATUS == :api_readonly + def check_api_writable + if OSM_STATUS == :database_offline or OSM_STATUS == :database_readonly or + OSM_STATUS == :api_offline or OSM_STATUS == :api_readonly response.headers['Error'] = "Database offline for maintenance" render :nothing => true, :status => :service_unavailable return false diff --git a/app/controllers/diary_entry_controller.rb b/app/controllers/diary_entry_controller.rb index e0d6e44cd..52e2ab22b 100644 --- a/app/controllers/diary_entry_controller.rb +++ b/app/controllers/diary_entry_controller.rb @@ -3,7 +3,8 @@ class DiaryEntryController < ApplicationController before_filter :authorize_web before_filter :require_user, :only => [:new, :edit] - before_filter :check_database_availability + before_filter :check_database_readable + before_filter :check_database_writable, :only => [:new, :edit] def new @title = 'New diary entry' diff --git a/app/controllers/message_controller.rb b/app/controllers/message_controller.rb index 85c0ac328..d6e5d7fda 100644 --- a/app/controllers/message_controller.rb +++ b/app/controllers/message_controller.rb @@ -3,6 +3,8 @@ class MessageController < ApplicationController before_filter :authorize_web before_filter :require_user + before_filter :check_database_readable + before_filter :check_database_writable, :only => [:new, :reply, :mark] def new @title = 'send message' diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index edc3675e5..e13d846b0 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/node_controller.rb @@ -5,8 +5,8 @@ class NodeController < ApplicationController session :off before_filter :authorize, :only => [:create, :update, :delete] - before_filter :check_write_availability, :only => [:create, :update, :delete] - before_filter :check_read_availability, :except => [:create, :update, :delete] + before_filter :check_api_writeable, :only => [:create, :update, :delete] + before_filter :check_api_readable, :except => [:create, :update, :delete] after_filter :compress_output # Create a node from XML. diff --git a/app/controllers/old_node_controller.rb b/app/controllers/old_node_controller.rb index e27898336..40f4093e3 100644 --- a/app/controllers/old_node_controller.rb +++ b/app/controllers/old_node_controller.rb @@ -2,7 +2,7 @@ class OldNodeController < ApplicationController require 'xml/libxml' session :off - before_filter :check_read_availability + before_filter :check_api_readable after_filter :compress_output def history diff --git a/app/controllers/old_way_controller.rb b/app/controllers/old_way_controller.rb index e72c97a00..3d913c0f7 100644 --- a/app/controllers/old_way_controller.rb +++ b/app/controllers/old_way_controller.rb @@ -2,7 +2,7 @@ class OldWayController < ApplicationController require 'xml/libxml' session :off - before_filter :check_read_availability + before_filter :check_api_readable after_filter :compress_output def history diff --git a/app/controllers/relation_controller.rb b/app/controllers/relation_controller.rb index 2b1ba6c75..32cbdaf6d 100644 --- a/app/controllers/relation_controller.rb +++ b/app/controllers/relation_controller.rb @@ -3,8 +3,8 @@ class RelationController < ApplicationController session :off before_filter :authorize, :only => [:create, :update, :delete] - before_filter :check_write_availability, :only => [:create, :update, :delete] - before_filter :check_read_availability, :except => [:create, :update, :delete] + before_filter :check_api_writeable, :only => [:create, :update, :delete] + before_filter :check_api_readable, :except => [:create, :update, :delete] after_filter :compress_output def create diff --git a/app/controllers/swf_controller.rb b/app/controllers/swf_controller.rb index a96e71d05..182fb8c54 100644 --- a/app/controllers/swf_controller.rb +++ b/app/controllers/swf_controller.rb @@ -1,6 +1,6 @@ class SwfController < ApplicationController session :off - before_filter :check_read_availability + before_filter :check_api_readable # to log: # RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}") diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 0c4fc9e58..3942cb7fe 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -4,8 +4,10 @@ class TraceController < ApplicationController before_filter :authorize_web before_filter :require_user, :only => [:mine, :edit, :delete, :make_public] before_filter :authorize, :only => [:api_details, :api_data, :api_create] - before_filter :check_database_availability, :except => [:api_details, :api_data, :api_create] - before_filter :check_read_availability, :only => [:api_details, :api_data, :api_create] + before_filter :check_database_readable, :except => [:api_details, :api_data, :api_create] + before_filter :check_database_writable, :only => [:create, :edit, :delete, :make_public] + before_filter :check_api_readable, :only => [:api_details, :api_data] + before_filter :check_api_writable, :only => [:api_create] # 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 diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index 6a60917f2..1cd34900a 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -4,8 +4,9 @@ class UserController < ApplicationController before_filter :authorize, :only => [:api_details, :api_gpx_files] before_filter :authorize_web, :except => [:api_details, :api_gpx_files] before_filter :require_user, :only => [:set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image, :delete_image] - before_filter :check_database_availability, :except => [:api_details, :api_gpx_files] - before_filter :check_read_availability, :only => [:api_details, :api_gpx_files] + before_filter :check_database_readable, :except => [:api_details, :api_gpx_files] + before_filter :check_database_writable, :only => [:login, :new, :set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image, :delete_image] + before_filter :check_api_readable, :only => [:api_details, :api_gpx_files] filter_parameter_logging :password, :pass_crypt, :pass_crypt_confirmation diff --git a/app/controllers/way_controller.rb b/app/controllers/way_controller.rb index 3b6491cf0..836b9f486 100644 --- a/app/controllers/way_controller.rb +++ b/app/controllers/way_controller.rb @@ -3,8 +3,8 @@ class WayController < ApplicationController session :off before_filter :authorize, :only => [:create, :update, :delete] - before_filter :check_write_availability, :only => [:create, :update, :delete] - before_filter :check_read_availability, :except => [:create, :update, :delete] + before_filter :check_api_writeable, :only => [:create, :update, :delete] + before_filter :check_api_readable, :except => [:create, :update, :delete] after_filter :compress_output def create diff --git a/app/views/layouts/site.rhtml b/app/views/layouts/site.rhtml index d1d3bba79..ff17fcf1d 100644 --- a/app/views/layouts/site.rhtml +++ b/app/views/layouts/site.rhtml @@ -90,7 +90,7 @@ The OpenStreetMap database is currently offline while essential database maintenance work is carried out. - <% elsif OSM_STATUS == :api_readonly %> + <% elsif OSM_STATUS == :database_readonly or OSM_STATUS == :api_readonly %>
The OpenStreetMap database is currently in read-only mode while essential database maintenance work is carried out. diff --git a/app/views/site/edit.rhtml b/app/views/site/edit.rhtml index 9c3c78fda..7d80a1705 100644 --- a/app/views/site/edit.rhtml +++ b/app/views/site/edit.rhtml @@ -2,7 +2,7 @@

The OpenStreetMap database is currently offline while essential database maintenance work is carried out.

-<% elsif OSM_STATUS == :api_readonly %> +<% elsif OSM_STATUS == :database_readonly or OSM_STATUS == :api_readonly %>

The OpenStreetMap database is currently in read-only mode while essential database maintenance work is carried out.

diff --git a/app/views/site/offline.rhtml b/app/views/site/offline.rhtml index d97a6ca90..22cf37ca9 100644 --- a/app/views/site/offline.rhtml +++ b/app/views/site/offline.rhtml @@ -1,3 +1,9 @@ +<% if OSM_STATUS == :database_offline %>

The OpenStreetMap database is currently offline while essential database maintenance work is carried out.

+<% else %> +

The OpenStreetMap database is currently in read-only mode while + essential database maintenance work is carried out. +

+<% end %> diff --git a/config/environment.rb b/config/environment.rb index e6af619eb..930fc81e9 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -18,6 +18,7 @@ API_VERSION = ENV['OSM_API_VERSION'] || '0.5' # :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 # OSM_STATUS = :online -- 2.43.2