Add support for putting the site in an offline mode where it operates
without a database but with most features disabled.
This commit is contained in:
parent
b527d27674
commit
2cf15b549e
9 changed files with 38 additions and 11 deletions
|
@ -2,6 +2,10 @@
|
|||
# Likewise, all the methods added will be available for all controllers.
|
||||
class ApplicationController < ActionController::Base
|
||||
|
||||
if OSM_STATUS == :database_offline
|
||||
session :off
|
||||
end
|
||||
|
||||
def authorize_web
|
||||
if session[:user]
|
||||
@user = User.find(session[:user])
|
||||
|
@ -39,8 +43,14 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def check_database_availability
|
||||
if OSM_STATUS == :database_offline
|
||||
redirect_to :controller => 'site', :action => 'offline'
|
||||
end
|
||||
end
|
||||
|
||||
def check_read_availability
|
||||
if API_STATUS == :offline
|
||||
if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline
|
||||
response.headers['Error'] = "Database offline for maintenance"
|
||||
render :nothing => true, :status => :service_unavailable
|
||||
return false
|
||||
|
@ -48,7 +58,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def check_write_availability
|
||||
if API_STATUS == :offline or API_STATUS == :readonly
|
||||
if OSM_STATUS == :database_offline 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
|
||||
|
|
|
@ -3,6 +3,7 @@ class DiaryEntryController < ApplicationController
|
|||
|
||||
before_filter :authorize_web
|
||||
before_filter :require_user, :only => [:new]
|
||||
before_filter :check_database_availability
|
||||
|
||||
def new
|
||||
@title = 'new diary entry'
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
class TraceController < ApplicationController
|
||||
layout 'site'
|
||||
|
||||
before_filter :authorize_web
|
||||
before_filter :authorize, :only => [:api_details, :api_data, :api_create]
|
||||
layout 'site'
|
||||
before_filter :check_database_availability, :except => [:api_details, :api_data, :api_create]
|
||||
before_filter :check_read_availability, :only => [:api_details, :api_data, :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
|
||||
|
|
|
@ -4,6 +4,8 @@ class UserController < ApplicationController
|
|||
before_filter :authorize, :only => [:api_details, :api_gpx_files]
|
||||
before_filter :authorize_web, :only => [:account, :go_public, :view, :diary, :make_friend, :remove_friend, :upload_image]
|
||||
before_filter :require_user, :only => [:set_home, :account, :go_public, :make_friend, :remove_friend, :upload_image]
|
||||
before_filter :check_database_availability, :except => [:api_details, :api_gpx_files]
|
||||
before_filter :check_read_availability, :only => [:api_details, :api_gpx_files]
|
||||
|
||||
filter_parameter_logging :password, :pass_crypt, :pass_crypt_confirmation
|
||||
|
||||
|
|
|
@ -76,12 +76,12 @@
|
|||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if API_STATUS == :offline %>
|
||||
<% if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline %>
|
||||
<div id="alert">
|
||||
The OpenStreetMap database is currently offline while
|
||||
essential database maintenance work is carried out.
|
||||
</div>
|
||||
<% elsif API_STATUS == :readonly %>
|
||||
<% elsif OSM_STATUS == :api_readonly %>
|
||||
<div id="alert">
|
||||
The OpenStreetMap database is currently in read-only mode while
|
||||
essential database maintenance work is carried out.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<% if API_STATUS == :offline %>
|
||||
<% if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline %>
|
||||
<p>The OpenStreetMap database is currently offline while
|
||||
essential database maintenance work is carried out.
|
||||
</p>
|
||||
<% elsif API_STATUS == :readonly %>
|
||||
<% elsif OSM_STATUS == :api_readonly %>
|
||||
<p>The OpenStreetMap database is currently in read-only mode while
|
||||
essential database maintenance work is carried out.
|
||||
</p>
|
||||
|
|
3
app/views/site/offline.rhtml
Normal file
3
app/views/site/offline.rhtml
Normal file
|
@ -0,0 +1,3 @@
|
|||
<p>The OpenStreetMap database is currently offline while
|
||||
essential database maintenance work is carried out.
|
||||
</p>
|
|
@ -13,9 +13,14 @@ SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org'
|
|||
# Application constants needed for routes.rb - must go before Initializer call
|
||||
API_VERSION = ENV['OSM_API_VERSION'] || '0.5'
|
||||
|
||||
# Set to :readonly to put the API in read-only mode or :offline to
|
||||
# take it completely offline
|
||||
API_STATUS = :online
|
||||
# Set application status - possible settings are:
|
||||
#
|
||||
# :online - online and operating normally
|
||||
# :api_readonly - site online but API in read-only mode
|
||||
# :api_offline - site online but API offline
|
||||
# :database_offline - database offline with site in emergency mode
|
||||
#
|
||||
OSM_STATUS = :online
|
||||
|
||||
# Bootstrap the Rails environment, frameworks, and default configuration
|
||||
require File.join(File.dirname(__FILE__), 'boot')
|
||||
|
@ -28,7 +33,9 @@ Rails::Initializer.run do |config|
|
|||
|
||||
# Skip frameworks you're not going to use (only works if using vendor/rails).
|
||||
# To use Rails without a database, you must remove the Active Record framework
|
||||
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
|
||||
if OSM_STATUS == :database_offline
|
||||
config.frameworks -= [ :active_record ]
|
||||
end
|
||||
|
||||
# Only load the plugins named here, in the order given. By default, all plugins
|
||||
# in vendor/plugins are loaded in alphabetical order.
|
||||
|
|
|
@ -64,6 +64,7 @@ ActionController::Routing::Routes.draw do |map|
|
|||
map.connect '/export', :controller => 'site', :action => 'export'
|
||||
map.connect '/login', :controller => 'user', :action => 'login'
|
||||
map.connect '/logout', :controller => 'user', :action => 'logout'
|
||||
map.connect '/offline', :controller => 'site', :action => 'offline'
|
||||
map.connect '/user/new', :controller => 'user', :action => 'new'
|
||||
map.connect '/user/save', :controller => 'user', :action => 'save'
|
||||
map.connect '/user/confirm', :controller => 'user', :action => 'confirm'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue