Add a "database readonly" state that allows all writes to the database

to be suppressed.
This commit is contained in:
Tom Hughes 2009-04-14 14:27:30 +00:00
parent 240869f37b
commit 09fdee5493
17 changed files with 44 additions and 23 deletions

View file

@ -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.

View file

@ -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

View file

@ -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

View file

@ -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'

View file

@ -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'

View file

@ -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.

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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]}")

View file

@ -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

View file

@ -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

View file

@ -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