From: Tom Hughes Date: Sun, 22 Jun 2008 12:23:43 +0000 (+0000) Subject: Merge 7922:8377 from trunk. X-Git-Tag: live~7719^2~5 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/960d13488a875245570ee498ee9a1ed7cac37bbe?hp=f053c8472336b386eaff72acdcdb8f8e148a3340 Merge 7922:8377 from trunk. --- diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 4eda7b00a..359b45326 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -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 diff --git a/app/controllers/application.rb b/app/controllers/application.rb index acb2f9162..7570fd82a 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -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 diff --git a/app/controllers/diary_entry_controller.rb b/app/controllers/diary_entry_controller.rb index a3b37b931..5159f7362 100644 --- a/app/controllers/diary_entry_controller.rb +++ b/app/controllers/diary_entry_controller.rb @@ -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' diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index cf35d0046..0467e66ba 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -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 diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index e998e83c6..5d26708fe 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -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 diff --git a/app/models/node.rb b/app/models/node.rb index cc646b768..4393f2526 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -10,11 +10,16 @@ class Node < GeoRecord validates_numericality_of :latitude, :longitude validate :validate_position - has_many :ways, :through => :way_nodes + belongs_to :user + has_many :old_nodes, :foreign_key => :id + has_many :way_nodes - belongs_to :user - + 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? diff --git a/app/models/old_relation_member.rb b/app/models/old_relation_member.rb index 9e2cce4c2..d8b685854 100644 --- a/app/models/old_relation_member.rb +++ b/app/models/old_relation_member.rb @@ -1,6 +1,3 @@ class OldRelationMember < ActiveRecord::Base - belongs_to :user - set_table_name 'relation_members' - end diff --git a/app/models/old_relation_tag.rb b/app/models/old_relation_tag.rb index 6ad4b452e..7ce6f694e 100644 --- a/app/models/old_relation_tag.rb +++ b/app/models/old_relation_tag.rb @@ -1,6 +1,3 @@ class OldRelationTag < ActiveRecord::Base - belongs_to :user - set_table_name 'relation_tags' - end diff --git a/app/models/relation.rb b/app/models/relation.rb index cedfaf656..cd2d67cdd 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -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 diff --git a/app/models/relation_member.rb b/app/models/relation_member.rb index 79102853e..9ff4f46f3 100644 --- a/app/models/relation_member.rb +++ b/app/models/relation_member.rb @@ -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 + + def after_find + self[:member_class] = self.member_type.capitalize + end - # 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_initialize + 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 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 diff --git a/app/models/trace.rb b/app/models/trace.rb index 0e9e7bcc1..d28c2c6f4 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -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 diff --git a/app/models/way.rb b/app/models/way.rb index f1dc76eb4..8ae6b4084 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -1,15 +1,19 @@ class Way < ActiveRecord::Base require 'xml/libxml' + set_table_name 'current_ways' + belongs_to :user - has_many :nodes, :through => :way_nodes, :order => 'sequence_id' + has_many :old_ways, :foreign_key => 'id', :order => 'version' + has_many :way_nodes, :foreign_key => 'id', :order => 'sequence_id' - has_many :way_tags, :foreign_key => 'id' + has_many :nodes, :through => :way_nodes, :order => 'sequence_id' - has_many :old_ways, :foreign_key => 'id', :order => 'version' + has_many :way_tags, :foreign_key => 'id' - set_table_name 'current_ways' + 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 diff --git a/app/views/layouts/site.rhtml b/app/views/layouts/site.rhtml index 33e02449d..52e7b6b24 100644 --- a/app/views/layouts/site.rhtml +++ b/app/views/layouts/site.rhtml @@ -52,7 +52,7 @@
  • <%= link_to 'Export', {:controller => 'site', :action => 'export'}, {:id => 'exportanchor', :title => 'export map data', :class => exportclass} %>
  • <% end %>
  • <%= link_to 'GPS Traces', {:controller => 'trace', :action => 'list'}, {:id => 'traceanchor', :title => 'manage traces', :class => traceclass} %>
  • -
  • <%= link_to 'User Diaries', {:controller => 'diary_entry', :action => 'list'}, {:id => 'diaryanchor', :title => 'view user diaries', :class => diaryclass} %>
  • +
  • <%= link_to 'User Diaries', {:controller => 'diary_entry', :action => 'list', :display_name => nil}, {:id => 'diaryanchor', :title => 'view user diaries', :class => diaryclass} %>
  • @@ -76,12 +76,12 @@ <% end %> - <% if API_STATUS == :offline %> + <% if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline %>
    The OpenStreetMap database is currently offline while essential database maintenance work is carried out.
    - <% elsif API_STATUS == :readonly %> + <% elsif OSM_STATUS == :api_readonly %>
    The OpenStreetMap database is currently in read-only mode while essential database maintenance work is carried out. diff --git a/app/views/site/edit.rhtml b/app/views/site/edit.rhtml index afd33e4ae..a3896bc48 100644 --- a/app/views/site/edit.rhtml +++ b/app/views/site/edit.rhtml @@ -1,8 +1,8 @@ -<% if API_STATUS == :offline %> +<% if OSM_STATUS == :database_offline or OSM_STATUS == :api_offline %>

    The OpenStreetMap database is currently offline while essential database maintenance work is carried out.

    -<% elsif API_STATUS == :readonly %> +<% elsif OSM_STATUS == :api_readonly %>

    The OpenStreetMap database is currently in read-only mode while essential database maintenance work is carried out.

    diff --git a/app/views/site/index.rhtml b/app/views/site/index.rhtml index 656db99c8..482ed85b8 100644 --- a/app/views/site/index.rhtml +++ b/app/views/site/index.rhtml @@ -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() { diff --git a/app/views/site/offline.rhtml b/app/views/site/offline.rhtml new file mode 100644 index 000000000..d97a6ca90 --- /dev/null +++ b/app/views/site/offline.rhtml @@ -0,0 +1,3 @@ +

    The OpenStreetMap database is currently offline while + essential database maintenance work is carried out. +

    diff --git a/app/views/trace/view.rhtml b/app/views/trace/view.rhtml index d4bdb9745..f547f05db 100644 --- a/app/views/trace/view.rhtml +++ b/app/views/trace/view.rhtml @@ -1,6 +1,10 @@

    <%= h(@title) %>

    - + <% if @trace.inserted %> + + <% else %> + PENDING + <% end %> diff --git a/app/views/user/confirm.rhtml b/app/views/user/confirm.rhtml index 8b1378917..5577b7068 100644 --- a/app/views/user/confirm.rhtml +++ b/app/views/user/confirm.rhtml @@ -1 +1,10 @@ +

    Confirm a user account

    + +

    Press the confirm button below to activate your account.

    + + + + + + diff --git a/config/environment.rb b/config/environment.rb index 02d99f20c..495f94d80 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -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. diff --git a/config/initializers/composite_primary_keys.rb b/config/initializers/composite_primary_keys.rb index 8fc935778..430bcfac2 100644 --- a/config/initializers/composite_primary_keys.rb +++ b/config/initializers/composite_primary_keys.rb @@ -1 +1,3 @@ +require 'rubygems' +gem 'composite_primary_keys', '= 0.9.93' require 'composite_primary_keys' diff --git a/config/routes.rb b/config/routes.rb index c23509372..52636b385 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/public/javascripts/map.js b/public/javascripts/map.js index 2bdba6229..291fd18fa 100644 --- a/public/javascripts/map.js +++ b/public/javascripts/map.js @@ -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); + } } } diff --git a/public/potlatch/potlatch.swf b/public/potlatch/potlatch.swf index 8c3d0c915..721840fe4 100755 Binary files a/public/potlatch/potlatch.swf and b/public/potlatch/potlatch.swf differ