Merge 7922:8377 from trunk.
This commit is contained in:
commit
960d13488a
23 changed files with 122 additions and 75 deletions
|
@ -376,10 +376,11 @@ class AmfController < ApplicationController
|
|||
|
||||
RAILS_DEFAULT_LOGGER.info(" Message: putway, id=#{originalway}")
|
||||
|
||||
# -- Check for null IDs or short ways
|
||||
# -- Check for null IDs, short ways or lats=90
|
||||
|
||||
points.each do |a|
|
||||
if a[2]==0 or a[2].nil? then return -2,"Server error - node with id 0 found in way #{originalway}." end
|
||||
if coord2lat(a[1],masterscale,basey)==90 then return -2,"Server error - node with lat -90 found in way #{originalway}." end
|
||||
end
|
||||
|
||||
if points.length<2 then return -2,"Server error - way is only #{points.length} points long." end
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -143,17 +145,19 @@ class UserController < ApplicationController
|
|||
end
|
||||
|
||||
def confirm
|
||||
token = UserToken.find_by_token(params[:confirm_string])
|
||||
if token and !token.user.active?
|
||||
@user = token.user
|
||||
@user.active = true
|
||||
@user.save!
|
||||
token.destroy
|
||||
flash[:notice] = 'Confirmed your account, thanks for signing up!'
|
||||
session[:user] = @user.id
|
||||
redirect_to :action => 'account', :display_name => @user.display_name
|
||||
else
|
||||
flash[:notice] = 'Something went wrong confirming that user.'
|
||||
if params[:confirm_action]
|
||||
token = UserToken.find_by_token(params[:confirm_string])
|
||||
if token and !token.user.active?
|
||||
@user = token.user
|
||||
@user.active = true
|
||||
@user.save!
|
||||
token.destroy
|
||||
flash[:notice] = 'Confirmed your account, thanks for signing up!'
|
||||
session[:user] = @user.id
|
||||
redirect_to :action => 'account', :display_name => @user.display_name
|
||||
else
|
||||
flash[:notice] = 'Something went wrong confirming that user.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -10,11 +10,16 @@ class Node < GeoRecord
|
|||
validates_numericality_of :latitude, :longitude
|
||||
validate :validate_position
|
||||
|
||||
has_many :ways, :through => :way_nodes
|
||||
has_many :old_nodes, :foreign_key => :id
|
||||
has_many :way_nodes
|
||||
belongs_to :user
|
||||
|
||||
|
||||
has_many :old_nodes, :foreign_key => :id
|
||||
|
||||
has_many :way_nodes
|
||||
has_many :ways, :through => :way_nodes
|
||||
|
||||
has_many :containing_relation_members, :as => :member
|
||||
has_many :containing_relations, :through => :containing_relation_members
|
||||
|
||||
# Sanity check the latitude and longitude and add an error if it's broken
|
||||
def validate_position
|
||||
errors.add_to_base("Node is not in the world") unless in_world?
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
class OldRelationMember < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
|
||||
set_table_name 'relation_members'
|
||||
|
||||
end
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
class OldRelationTag < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
|
||||
set_table_name 'relation_tags'
|
||||
|
||||
end
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
class Relation < ActiveRecord::Base
|
||||
require 'xml/libxml'
|
||||
|
||||
set_table_name 'current_relations'
|
||||
|
||||
belongs_to :user
|
||||
|
||||
has_many :old_relations, :foreign_key => 'id', :order => 'version'
|
||||
|
||||
has_many :relation_members, :foreign_key => 'id'
|
||||
has_many :relation_tags, :foreign_key => 'id'
|
||||
|
||||
has_many :old_relations, :foreign_key => 'id', :order => 'version'
|
||||
|
||||
set_table_name 'current_relations'
|
||||
has_many :containing_relation_members, :as => :member
|
||||
has_many :containing_relations, :through => :containing_relation_members
|
||||
|
||||
def self.from_xml(xml, create=false)
|
||||
begin
|
||||
|
|
|
@ -1,30 +1,23 @@
|
|||
class RelationMember < ActiveRecord::Base
|
||||
set_table_name 'current_relation_members'
|
||||
|
||||
# problem with RelationMember is that it may link to any one
|
||||
# object (a node, a way, another relation), and belongs_to is
|
||||
# not flexible enough for that. So we do this, which is ugly,
|
||||
# but fortunately rails won't actually run the SQL behind that
|
||||
# unless someone really accesses .node, .way, or
|
||||
# .relation - which is what we do below based on member_type.
|
||||
# (and no: the :condition on belongs_to doesn't work here as
|
||||
# it is a condition on the *referenced* object not the
|
||||
# *referencing* object!)
|
||||
|
||||
belongs_to :node, :foreign_key => "member_id"
|
||||
belongs_to :way, :foreign_key => "member_id"
|
||||
belongs_to :relation, :foreign_key => "member_id"
|
||||
belongs_to :member, :polymorphic => true, :foreign_type => :member_class
|
||||
belongs_to :relation, :foreign_key => :id
|
||||
|
||||
# so we define this "member" function that returns whatever it
|
||||
# is.
|
||||
|
||||
def member()
|
||||
return (member_type == "node") ? node : (member_type == "way") ? way : relation
|
||||
def after_find
|
||||
self[:member_class] = self.member_type.capitalize
|
||||
end
|
||||
|
||||
# NOTE - relations are SUBJECTS of memberships. The fact that nodes,
|
||||
# ways, and relations can be the OBJECT of a membership,
|
||||
# i.e. a node/way/relation can be referenced throgh a
|
||||
# RelationMember object, is NOT modelled in rails, i.e. these links
|
||||
# have to be resolved manually, on demand.
|
||||
def after_initialize
|
||||
self[:member_class] = self.member_type.capitalize
|
||||
end
|
||||
|
||||
def before_save
|
||||
self.member_type = self[:member_class].downcase
|
||||
end
|
||||
|
||||
def member_type=(type)
|
||||
self[:member_type] = type
|
||||
self[:member_class] = type.capitalize
|
||||
end
|
||||
end
|
||||
|
|
|
@ -183,7 +183,7 @@ class Trace < ActiveRecord::Base
|
|||
# If there are any existing points for this trace then delete
|
||||
# them - we check for existing points first to avoid locking
|
||||
# the table in the common case where there aren't any.
|
||||
if Tracepoint.exists?(['gpx_id = ?', self.id])
|
||||
if Tracepoint.find(:first, :conditions => ['gpx_id = ?', self.id])
|
||||
Tracepoint.delete_all(['gpx_id = ?', self.id])
|
||||
end
|
||||
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
class Way < ActiveRecord::Base
|
||||
require 'xml/libxml'
|
||||
|
||||
belongs_to :user
|
||||
set_table_name 'current_ways'
|
||||
|
||||
has_many :nodes, :through => :way_nodes, :order => 'sequence_id'
|
||||
has_many :way_nodes, :foreign_key => 'id', :order => 'sequence_id'
|
||||
has_many :way_tags, :foreign_key => 'id'
|
||||
belongs_to :user
|
||||
|
||||
has_many :old_ways, :foreign_key => 'id', :order => 'version'
|
||||
|
||||
set_table_name 'current_ways'
|
||||
has_many :way_nodes, :foreign_key => 'id', :order => 'sequence_id'
|
||||
has_many :nodes, :through => :way_nodes, :order => 'sequence_id'
|
||||
|
||||
has_many :way_tags, :foreign_key => 'id'
|
||||
|
||||
has_many :containing_relation_members, :class_name => "RelationMember", :as => :member
|
||||
has_many :containing_relations, :class_name => "Relation", :through => :containing_relation_members, :source => :relation
|
||||
|
||||
def self.from_xml(xml, create=false)
|
||||
begin
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
<li><%= link_to 'Export', {:controller => 'site', :action => 'export'}, {:id => 'exportanchor', :title => 'export map data', :class => exportclass} %></li>
|
||||
<% end %>
|
||||
<li><%= link_to 'GPS Traces', {:controller => 'trace', :action => 'list'}, {:id => 'traceanchor', :title => 'manage traces', :class => traceclass} %></li>
|
||||
<li><%= link_to 'User Diaries', {:controller => 'diary_entry', :action => 'list'}, {:id => 'diaryanchor', :title => 'view user diaries', :class => diaryclass} %></li>
|
||||
<li><%= link_to 'User Diaries', {:controller => 'diary_entry', :action => 'list', :display_name => nil}, {:id => 'diaryanchor', :title => 'view user diaries', :class => diaryclass} %></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
@ -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>
|
||||
|
|
|
@ -58,8 +58,8 @@ by the OpenStreetMap project and its contributors.
|
|||
<% lat = h(params['mlat']) %>
|
||||
<% zoom = h(params['zoom'] || '12') %>
|
||||
<% layers = h(params['layers']) %>
|
||||
<% elsif cookies.key?("location") %>
|
||||
<% lon,lat,zoom,layers = cookies["location"].split(",") %>
|
||||
<% elsif cookies.key?("_osm_location") %>
|
||||
<% lon,lat,zoom,layers = cookies["_osm_location"].split("|") %>
|
||||
<% elsif @user and !@user.home_lon.nil? and !@user.home_lat.nil? %>
|
||||
<% lon = @user.home_lon %>
|
||||
<% lat = @user.home_lat %>
|
||||
|
@ -76,8 +76,8 @@ by the OpenStreetMap project and its contributors.
|
|||
<% lon = '-0.1' %>
|
||||
<% lat = '51.5' %>
|
||||
<% zoom = h(params['zoom'] || '5') %>
|
||||
<% layers = h(params['layers']) %>
|
||||
<% end %>
|
||||
<% layers = h(params['layers']) %>
|
||||
<% end %>
|
||||
|
||||
<%= javascript_include_tag '/openlayers/OpenLayers.js' %>
|
||||
|
@ -113,7 +113,7 @@ by the OpenStreetMap project and its contributors.
|
|||
setMapCenter(centre, zoom);
|
||||
<% end %>
|
||||
|
||||
<% if layers %>
|
||||
<% if !layers.nil? and !layers.empty? %>
|
||||
setMapLayers("<%= layers %>");
|
||||
<% end %>
|
||||
|
||||
|
@ -160,7 +160,7 @@ by the OpenStreetMap project and its contributors.
|
|||
|
||||
updatelinks(lonlat.lon, lonlat.lat, zoom, layers);
|
||||
|
||||
document.cookie = "location=" + lonlat.lon + "," + lonlat.lat + "," + zoom + "," + layers;
|
||||
document.cookie = "_osm_location=" + lonlat.lon + "|" + lonlat.lat + "|" + zoom + "|" + layers;
|
||||
}
|
||||
|
||||
function resizeContent() {
|
||||
|
|
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>
|
|
@ -1,6 +1,10 @@
|
|||
<h2><%= h(@title) %></h2>
|
||||
|
||||
<img src="<%= url_for :controller => 'trace', :action => 'picture', :id => @trace.id, :display_name => @trace.user.display_name %>">
|
||||
<% if @trace.inserted %>
|
||||
<img src="<%= url_for :controller => 'trace', :action => 'picture', :id => @trace.id, :display_name => @trace.user.display_name %>">
|
||||
<% else %>
|
||||
<span style="color:red">PENDING</span>
|
||||
<% end %>
|
||||
|
||||
<table border="0">
|
||||
<tr>
|
||||
|
|
|
@ -1 +1,10 @@
|
|||
<h1>Confirm a user account</h1>
|
||||
|
||||
<p>Press the confirm button below to activate your account.</p>
|
||||
|
||||
<form method="post">
|
||||
<input type="hidden" name="confirm_string" value="<%= params[:confirm_string] %>">
|
||||
<input type="submit" name="confirm_action" value="Confrm">
|
||||
</form>
|
||||
|
||||
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
ENV['RAILS_ENV'] ||= 'production'
|
||||
|
||||
# Specifies gem version of Rails to use when vendor/rails is not present
|
||||
# DO NOT BUMP THIS TO 2.0.2 AS THE LIVE SERVERS CAN'T RUN THAT
|
||||
RAILS_GEM_VERSION = '2.0.1' unless defined? RAILS_GEM_VERSION
|
||||
RAILS_GEM_VERSION = '2.0.2' unless defined? RAILS_GEM_VERSION
|
||||
|
||||
# Set the server URL
|
||||
SERVER_URL = ENV['OSM_SERVER_URL'] || 'www.openstreetmap.org'
|
||||
|
@ -14,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')
|
||||
|
@ -29,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.
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
require 'rubygems'
|
||||
gem 'composite_primary_keys', '= 0.9.93'
|
||||
require 'composite_primary_keys'
|
||||
|
|
|
@ -74,6 +74,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'
|
||||
|
|
|
@ -157,7 +157,11 @@ function setMapLayers(layerConfig) {
|
|||
for (var layers = map.getLayersBy("isBaseLayer", false), i = 0; i < layers.length; i++) {
|
||||
var c = layerConfig.charAt(l++);
|
||||
|
||||
layers[i].setVisibility(c == "T");
|
||||
if (c == "T") {
|
||||
layers[i].setVisibility(true);
|
||||
} else if(c == "F") {
|
||||
layers[i].setVisibility(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue