From: Tom Hughes Date: Thu, 16 Apr 2009 21:11:12 +0000 (+0000) Subject: Merge 14394:14533 from trunk. X-Git-Tag: live~7609^2~10 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/5449cf4adcc1fad4b9f43426e6d3e4a8f65e6fbb?hp=a4de927a2800e0fc739460cee5a71e58d09d25f9 Merge 14394:14533 from trunk. --- diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 1ee5e9cee..de3c7583b 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -41,7 +41,7 @@ class AmfController < ApplicationController include MapBoundary 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 f0ba32568..ebf729afc 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 f5ea0063d..21f691bb3 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 @@ -52,13 +52,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 @@ -66,8 +73,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/browse_controller.rb b/app/controllers/browse_controller.rb index 465184f50..6ace0817b 100644 --- a/app/controllers/browse_controller.rb +++ b/app/controllers/browse_controller.rb @@ -2,7 +2,7 @@ class BrowseController < ApplicationController layout 'site' before_filter :authorize_web - before_filter { |c| c.check_database_availability(true) } + before_filter { |c| c.check_database_readable(true) } def start end diff --git a/app/controllers/diary_entry_controller.rb b/app/controllers/diary_entry_controller.rb index 3592ccb4f..3ee36af21 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 a04aa82c0..8f866e512 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] # Allow the user to write a new message to another user. This action also # deals with the sending of that message to the other user when the user diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index c03f3c4fb..80a3b30d5 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_writable, :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 56397625c..0976a0c9a 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 da4e26d67..a42496687 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 ec86bb635..3d3fa2185 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_writable, :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 b52be7f34..0603567c4 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, :create, :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 553e841aa..9544dd8a8 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 80c75d91c..e28945dcd 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_writable, :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 bc51fa98b..534003031 100644 --- a/app/views/layouts/site.rhtml +++ b/app/views/layouts/site.rhtml @@ -94,7 +94,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 daa78f3b9..e341305f5 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 ce1216b83..7f83fd4ad 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -21,6 +21,7 @@ API_VERSION = ENV['OSM_API_VERSION'] || '0.6' # :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