From: Shaun McDonald Date: Mon, 3 Nov 2008 00:12:18 +0000 (+0000) Subject: Adding a restriction to prevent more than 2000 nodes to be added to any way. Tests... X-Git-Tag: live~7601^2~228 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/635daf1773f5e2795c87619aa527adde965ce938 Adding a restriction to prevent more than 2000 nodes to be added to any way. Tests still need to be written. Capabilities api request also updated. --- diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index c337038a0..fa14cd79e 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -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 diff --git a/app/models/way.rb b/app/models/way.rb index b413ccb28..9d4d8ba87 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -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 diff --git a/config/application.yml b/config/application.yml index 85ebe9f21..7400a7b9a 100644 --- a/config/application.yml +++ b/config/application.yml @@ -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 diff --git a/lib/osm.rb b/lib/osm.rb index 246fedf54..b002ebbe8 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -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