]> git.openstreetmap.org Git - rails.git/commitdiff
Add support for putting the site in an offline mode where it operates
authorTom Hughes <tom@compton.nu>
Sun, 22 Jun 2008 12:10:32 +0000 (12:10 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 22 Jun 2008 12:10:32 +0000 (12:10 +0000)
without a database but with most features disabled.

app/controllers/application.rb
app/controllers/diary_entry_controller.rb
app/controllers/trace_controller.rb
app/controllers/user_controller.rb
app/views/layouts/site.rhtml
app/views/site/edit.rhtml
app/views/site/offline.rhtml [new file with mode: 0644]
config/environment.rb
config/routes.rb

index acb2f916291ab02aced0486022b4688c2b109677..7570fd82a072d2af2d2e70dd0e33cd2d83df391d 100644 (file)
@@ -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
index a3b37b931beabf3c7cd9fcbca435d62c41c37914..5159f73624b2bcf53f2c3344310da59ee5f147b3 100644 (file)
@@ -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'
index cf35d00462c0c7461be2928737345048033dffdb..0467e66bac49028fff5a56f21c4d84b55fe1e8ba 100644 (file)
@@ -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
index 31955d019dd13417f98421898733575c40b441bd..5d26708fe0df2846058c3c869528192334346f48 100644 (file)
@@ -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
 
index 7283ebb32c6ad8bfcc0a399d3b0760d61d25c026..52e7b6b242847869e54c8feb7f2f1ab9530c74bb 100644 (file)
       </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.
index afd33e4ae1cbb1371dfec634cfae140374d6ea57..a3896bc4824ea99966f5850592fb100c3ed1ac76 100644 (file)
@@ -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>
diff --git a/app/views/site/offline.rhtml b/app/views/site/offline.rhtml
new file mode 100644 (file)
index 0000000..d97a6ca
--- /dev/null
@@ -0,0 +1,3 @@
+<p>The OpenStreetMap database is currently offline while
+   essential database maintenance work is carried out.
+</p>
index cfabe365f4ce7aafea69bb93e563a54ab7396540..495f94d80a63f08b22f639bdcbaaace8c6d946e0 100644 (file)
@@ -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.
index dc26259fa8ffb76ce8263b01d863e02c58f71710..290ad6e08d8623229de33769a5723a680c535945 100644 (file)
@@ -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'