]> git.openstreetmap.org Git - rails.git/commitdiff
Add a "database readonly" state that allows all writes to the database
authorTom Hughes <tom@compton.nu>
Tue, 14 Apr 2009 14:27:30 +0000 (14:27 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 14 Apr 2009 14:27:30 +0000 (14:27 +0000)
to be suppressed.

17 files changed:
app/controllers/amf_controller.rb
app/controllers/api_controller.rb
app/controllers/application.rb
app/controllers/diary_entry_controller.rb
app/controllers/message_controller.rb
app/controllers/node_controller.rb
app/controllers/old_node_controller.rb
app/controllers/old_way_controller.rb
app/controllers/relation_controller.rb
app/controllers/swf_controller.rb
app/controllers/trace_controller.rb
app/controllers/user_controller.rb
app/controllers/way_controller.rb
app/views/layouts/site.rhtml
app/views/site/edit.rhtml
app/views/site/offline.rhtml
config/environment.rb

index 03d952b9660ca363e9e3a368f063710922ee944f..7f85280b79d29d5b320460d01f028f14727a3fd0 100644 (file)
@@ -29,7 +29,7 @@ class AmfController < ApplicationController
   include Potlatch
 
   session :off
   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.
 
   # Main AMF handlers: process the raw AMF string (using AMF library) and
   # calls each action (private method) accordingly.
index 7a0a45fc8a333f346499ba8c4764c91a1a6950d6..029e4c8a6544353845213575e57243c49e67f5b4 100644 (file)
@@ -1,7 +1,7 @@
 class ApiController < ApplicationController
 
   session :off
 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
   after_filter :compress_output
 
   # Help methods for checking boundary sanity and area size
index ce13a6aa3a6ae625407d3ac7fe2eaa11f7ab6ed9..6150226569365df57a19a7e261e328ed2acb7879 100644 (file)
@@ -2,7 +2,7 @@
 # Likewise, all the methods added will be available for all controllers.
 class ApplicationController < ActionController::Base
 
 # 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
 
     session :off
   end
 
@@ -43,13 +43,20 @@ class ApplicationController < ActionController::Base
     end 
   end 
 
     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
 
     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
     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
 
     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
       response.headers['Error'] = "Database offline for maintenance"
       render :nothing => true, :status => :service_unavailable
       return false
index e0d6e44cdd8764f4aacc39bfcf8d664ca38ee83e..52e2ab22bcae7bb7742be8a98bed12c797220165 100644 (file)
@@ -3,7 +3,8 @@ class DiaryEntryController < ApplicationController
 
   before_filter :authorize_web
   before_filter :require_user, :only => [:new, :edit]
 
   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'
 
   def new
     @title = 'New diary entry'
index 85c0ac328f2fc0349bd733518f51dd343410a825..d6e5d7fdadc4b86c326bc06217530fc76a169f48 100644 (file)
@@ -3,6 +3,8 @@ class MessageController < ApplicationController
 
   before_filter :authorize_web
   before_filter :require_user
 
   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'
 
   def new
     @title = 'send message'
index edc3675e58382fce0b8b5801a2e7180ab280cec2..e13d846b00f4b3a535c912146393c333fb172d44 100644 (file)
@@ -5,8 +5,8 @@ class NodeController < ApplicationController
 
   session :off
   before_filter :authorize, :only => [:create, :update, :delete]
 
   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.
   after_filter :compress_output
 
   # Create a node from XML.
index e27898336361832ed193c9d1b3c8de04ddb14a41..40f4093e3d99171105c3a0a532e551cbb7a1222c 100644 (file)
@@ -2,7 +2,7 @@ class OldNodeController < ApplicationController
   require 'xml/libxml'
 
   session :off
   require 'xml/libxml'
 
   session :off
-  before_filter :check_read_availability
+  before_filter :check_api_readable
   after_filter :compress_output
 
   def history
   after_filter :compress_output
 
   def history
index e72c97a0078022650a8484d08c070b7d67fed6c7..3d913c0f7660ce49b86a251bf3a19ccc4918d229 100644 (file)
@@ -2,7 +2,7 @@ class OldWayController < ApplicationController
   require 'xml/libxml'
 
   session :off
   require 'xml/libxml'
 
   session :off
-  before_filter :check_read_availability
+  before_filter :check_api_readable
   after_filter :compress_output
 
   def history
   after_filter :compress_output
 
   def history
index 2b1ba6c753c70df6579d381facebc7bd451be754..32cbdaf6d81f10d8f029ed1d1456bcf064ccf0c1 100644 (file)
@@ -3,8 +3,8 @@ class RelationController < ApplicationController
 
   session :off
   before_filter :authorize, :only => [:create, :update, :delete]
 
   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
   after_filter :compress_output
 
   def create
index a96e71d05ee4ef99f9e4ff9e882e29a3fc2d3194..182fb8c549f934291c87f457dd4b069ae24e092a 100644 (file)
@@ -1,6 +1,6 @@
 class SwfController < ApplicationController
        session :off
 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]}")
 
 # to log:
 # RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}")
index 0c4fc9e58f33f6612565a60e15a01f78864b7e3d..3942cb7fe3d8964eb80eb7733eacee0f9c490de3 100644 (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 :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
  
   # 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 6a60917f28c6922afff61c8fa5c5529ff48d8870..1cd34900a19835b6553e29b676a9c5c61a9ef38f 100644 (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 :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
 
 
   filter_parameter_logging :password, :pass_crypt, :pass_crypt_confirmation
 
index 3b6491cf0b3ceda5ed90ee7e1da5e49579c6af21..836b9f4861bd70d44b24f53e1344f2b2b98bbcad 100644 (file)
@@ -3,8 +3,8 @@ class WayController < ApplicationController
 
   session :off
   before_filter :authorize, :only => [:create, :update, :delete]
 
   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
   after_filter :compress_output
 
   def create
index d1d3bba7931878a22644057f5cb9ba8aeb0d25e1..ff17fcf1d3c071cbe798e2fbda5c0a6f173af6cc 100644 (file)
@@ -90,7 +90,7 @@
         The OpenStreetMap database is currently offline while
         essential database maintenance work is carried out.
       </div>
         The OpenStreetMap database is currently offline while
         essential database maintenance work is carried out.
       </div>
-      <% elsif OSM_STATUS == :api_readonly %>
+      <% elsif OSM_STATUS == :database_readonly or OSM_STATUS == :api_readonly %>
       <div id="alert">
         The OpenStreetMap database is currently in read-only mode while
         essential database maintenance work is carried out.
       <div id="alert">
         The OpenStreetMap database is currently in read-only mode while
         essential database maintenance work is carried out.
index 9c3c78fda9d06771e3d6ffd09c94852de0060639..7d80a1705be3c51473f16589e7afddfcc114c5b1 100644 (file)
@@ -2,7 +2,7 @@
 <p>The OpenStreetMap database is currently offline while
    essential database maintenance work is carried out.
 </p>
 <p>The OpenStreetMap database is currently offline while
    essential database maintenance work is carried out.
 </p>
-<% elsif OSM_STATUS == :api_readonly %>
+<% elsif OSM_STATUS == :database_readonly or OSM_STATUS == :api_readonly %>
 <p>The OpenStreetMap database is currently in read-only mode while
    essential database maintenance work is carried out.
 </p>
 <p>The OpenStreetMap database is currently in read-only mode while
    essential database maintenance work is carried out.
 </p>
index d97a6ca90cb41a72f071e8e4b7500b0371ef4484..22cf37ca9b1e3e8979b86a123284aa67afafd081 100644 (file)
@@ -1,3 +1,9 @@
+<% if OSM_STATUS == :database_offline %>
 <p>The OpenStreetMap database is currently offline while
    essential database maintenance work is carried out.
 </p>
 <p>The OpenStreetMap database is currently offline while
    essential database maintenance work is carried out.
 </p>
+<% else %>
+<p>The OpenStreetMap database is currently in read-only mode while
+   essential database maintenance work is carried out.
+</p>
+<% end  %>
index e6af619eb82b03aaaf8400db39ea951dbba227b6..930fc81e9bdbf30143b82bf6f7bc2c66c33e2269 100644 (file)
@@ -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
 #   :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
 #   :database_offline - database offline with site in emergency mode
 #
 OSM_STATUS = :online