Add a flag to allow the API to be placed in read-only mode.

This commit is contained in:
Tom Hughes 2007-07-26 17:15:23 +00:00
parent bd07221de5
commit 9dbe1a497a
10 changed files with 56 additions and 14 deletions

View file

@ -1,6 +1,8 @@
class AmfController < ApplicationController
require 'stringio'
before_filter :check_availability
# to log:
# RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}")

View file

@ -34,10 +34,19 @@ class ApplicationController < ActionController::Base
# no auth, the user does not exist or the password was wrong
response.headers["Status"] = "Unauthorized"
response.headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\""
render_text(errormessage, 401) # :unauthorized
render :text => errormessage, :status => :unauthorized
return false
end
end
def check_availability
if API_READONLY
response.headers['Error'] = "Database offline for maintenance"
render :nothing => true, :status => :service_unavailable
return false
end
end
# Report and error to the user
# (If anyone ever fixes Rails so it can set a http status "reason phrase",
# rather than only a status code and having the web engine make up a

View file

@ -2,6 +2,7 @@ class NodeController < ApplicationController
require 'xml/libxml'
before_filter :authorize, :only => [:create, :update, :delete]
before_filter :check_availability, :only => [:create, :update, :delete]
after_filter :compress_output
def create

View file

@ -2,6 +2,7 @@ class SegmentController < ApplicationController
require 'xml/libxml'
before_filter :authorize, :only => [:create, :update, :delete]
before_filter :check_availability, :only => [:create, :update, :delete]
after_filter :compress_output
def create

View file

@ -1,4 +1,5 @@
class SwfController < ApplicationController
before_filter :check_availability
# to log:
# RAILS_DEFAULT_LOGGER.error("Args: #{args[0]}, #{args[1]}, #{args[2]}, #{args[3]}")

View file

@ -2,6 +2,7 @@ class WayController < ApplicationController
require 'xml/libxml'
before_filter :authorize, :only => [:create, :update, :delete]
before_filter :check_availability, :only => [:create, :update, :delete]
after_filter :compress_output
def create

View file

@ -71,6 +71,13 @@
</div>
<% end %>
<% if API_READONLY %>
<div id="alert">
The OpenStreetMap database is currently in read-only mode while
essential database maintenance work is carried out.
</div>
<% end %>
<div id="left_menu" class="left_menu">
<a href="http://wiki.openstreetmap.org">Help &amp; Wiki</a><br />
<%= link_to "Users' diaries", {:controller => 'diary_entry', :action => 'list', :display_name => nil} %><br />
@ -78,7 +85,6 @@
<a href="http://wiki.openstreetmap.org/index.php/Merchandise">Shop</a><br />
</div>
<%= yield :optionals %>
<div id="cclogo">
<center>

View file

@ -1,3 +1,8 @@
<% if API_READONLY %>
<p>The OpenStreetMap database is currently in read-only mode while
essential database maintenance work is carried out.
</p>
<% else %>
<%= render :partial => 'search' %>
<% if params['mlon'] and params['mlat'] %>
@ -18,18 +23,20 @@
OpenStreetMap Flash editor. You can <a href="http://www.adobe.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">download Flash Player from Adobe.com</a>.
<a href="http://wiki.openstreetmap.org/index.php/Editing">Several other options</a> are also available
for editing OpenStreetMap.</div>
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<script type="text/javascript">
var fo = new SWFObject("/potlatch/potlatch.swf?d="+Math.round(Math.random()*1000), "potlatch", "700", "600", "6", "#FFFFFF");
function doSWF(lat,lon,sc) {
fo.addVariable('lat',lat);
fo.addVariable('long',lon);
fo.addVariable('scale',sc);
fo.addVariable('token','<%= @user.token %>');
fo.write("mapcontent");
}
for editing OpenStreetMap.
</div>
<script type="text/javascript" src="/javascripts/swfobject.js"></script>
<script type="text/javascript">
var fo = new SWFObject("/potlatch/potlatch.swf?d="+Math.round(Math.random()*1000), "potlatch", "700", "600", "6", "#FFFFFF");
doSWF(<%= lat %>,<%= lon %>,<%= zoom %>);
function doSWF(lat,lon,sc) {
fo.addVariable('lat',lat);
fo.addVariable('long',lon);
fo.addVariable('scale',sc);
fo.addVariable('token','<%= @user.token %>');
fo.write("mapcontent");
}
doSWF(<%= lat %>,<%= lon %>,<%= zoom %>);
</script>
<% end %>

View file

@ -67,6 +67,9 @@ end
# inflect.uncountable %w( fish sheep )
# end
# Set to true to put the API in read-only mode
API_READONLY = false
# Include your application configuration below
SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org'

View file

@ -80,6 +80,17 @@ body {
font-size: 11px;
}
#alert {
width: 150px;
margin: 10px;
padding: 10px;
border: 1px solid #ccc;
background: #d00;
line-height: 1.2em;
text-align: left;
font-size: 14px;
}
.left_menu {
width: 150px;
min-width: 150px;