]> git.openstreetmap.org Git - rails.git/commitdiff
Adding a restriction to prevent more than 2000 nodes to be added to any way. Tests...
authorShaun McDonald <shaun@shaunmcdonald.me.uk>
Mon, 3 Nov 2008 00:12:18 +0000 (00:12 +0000)
committerShaun McDonald <shaun@shaunmcdonald.me.uk>
Mon, 3 Nov 2008 00:12:18 +0000 (00:12 +0000)
app/controllers/api_controller.rb
app/models/way.rb
config/application.yml
lib/osm.rb

index c337038a0f4a7827372ef4cf8608a4423f4bce10..fa14cd79eb4f23c905762988a17e871b71cfb28e 100644 (file)
@@ -281,6 +281,9 @@ class ApiController < ApplicationController
     tracepoints = XML::Node.new 'tracepoints'
     tracepoints['per_page'] = APP_CONFIG['tracepoints_per_page'].to_s
     api << tracepoints
+    waynodes = XML::Node.new 'waynodes'
+    waynodes['maximum'] = APP_CONFIG['max_number_of_way_nodes'].to_s
+    api << waynodes
     
     doc.root << api
 
index b413ccb280d24c4e56fdb287b4b57a3029298ed0..9d4d8ba87c0ac13c1ef635a612dfa191577e21e7 100644 (file)
@@ -238,6 +238,9 @@ class Way < ActiveRecord::Base
 
   def preconditions_ok?
     return false if self.nds.empty?
+    if self.nds.length > APP_CONFIG['max_number_of_way_nodes']
+      raise OSM::APITooManyWayNodesError.new(self.nds.count, APP_CONFIG['max_number_of_way_nodes'])
+    end
     self.nds.each do |n|
       node = Node.find(:first, :conditions => ["id = ?", n])
       unless node and node.visible
index 85ebe9f2152884b044c2f73c136ffaee0cd642fa..7400a7b9a916088639aa0a092198f9c3000d82f4 100644 (file)
@@ -3,8 +3,10 @@ standard_settings: &standard_settings
   max_request_area: 0.25
   # Number of GPS trace/trackpoints returned per-page
   tracepoints_per_page: 5000
-  # Maximum number of nodes
+  # Maximum number of nodes that will be returned by the api in a map request
   max_number_of_nodes: 50000
+  # Maximum number of nodes that can be in a way (checked on save)
+  max_number_of_way_nodes: 2000
  
 development:
   <<: *standard_settings
index 246fedf54b915dd066263e90afc2642689f5a6f3..b002ebbe899b824fdb3d2f818681bb961d80b310 100644 (file)
@@ -108,6 +108,21 @@ module OSM
         :status => :bad_request }
     end
   end
+  
+  # Raised when a way has more than the configured number of way nodes.
+  # This prevents ways from being to long and difficult to work with
+  class APITooManyWayNodesError < APIError
+    def initialize(provided, max)
+      @provided, @max = provided, max
+    end
+    
+    attr_reader :provided, :max
+    
+    def render_opts
+      { :text => "You tried to add #{provided} nodes to the way, however only #{max} are allowed",
+      :status => :bad_request }
+    end
+  end
 
   # Helper methods for going to/from mercator and lat/lng.
   class Mercator