Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pull/4187'
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Aug 19, 2023
2 parents 3c38bad + 3f6e344 commit 406d90c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
6 changes: 3 additions & 3 deletions app/controllers/api/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,13 @@ def search
# Get the maximum number of results to return
def result_limit
if params[:limit]
if params[:limit].to_i.positive? && params[:limit].to_i <= 10000
if params[:limit].to_i.positive? && params[:limit].to_i <= Settings.max_note_query_limit
params[:limit].to_i
else
raise OSM::APIBadUserInput, "Note limit must be between 1 and 10000"
raise OSM::APIBadUserInput, "Note limit must be between 1 and #{Settings.max_note_query_limit}"
end
else
100
Settings.default_note_query_limit
end
end

Expand Down
2 changes: 2 additions & 0 deletions app/views/api/capabilities/show.builder
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ xml.osm(OSM::API.new.xml_root_attributes) do |osm|
api.changesets(:maximum_elements => Changeset::MAX_ELEMENTS,
:default_query_limit => Settings.default_changeset_query_limit,
:maximum_query_limit => Settings.max_changeset_query_limit)
api.notes(:default_query_limit => Settings.default_note_query_limit,
:maximum_query_limit => Settings.max_note_query_limit)
api.timeout(:seconds => Settings.api_timeout)
api.status(:database => @database_status,
:api => @api_status,
Expand Down
4 changes: 4 additions & 0 deletions app/views/api/capabilities/show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ json.api do
json.default_query_limit Settings.default_changeset_query_limit
json.maximum_query_limit Settings.max_changeset_query_limit
end
json.notes do
json.default_query_limit Settings.default_note_query_limit
json.maximum_query_limit Settings.max_note_query_limit
end
json.timeout do
json.seconds Settings.api_timeout
end
Expand Down
4 changes: 4 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ max_number_of_way_nodes: 2000
max_number_of_relation_members: 32000
# The maximum area you're allowed to request notes from, in square degrees
max_note_request_area: 25
# Default limit on the number of notes returned by the note search api method
default_note_query_limit: 100
# Maximum limit on the number of notes returned by the note search api method
max_note_query_limit: 10000
# Zoom level to use for postcode results from the geocoder
postcode_zoom: 15
# Timeout for API calls in seconds
Expand Down
10 changes: 9 additions & 1 deletion test/controllers/api/capabilities_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ def test_capabilities
assert_select "area[maximum='#{Settings.max_request_area}']", :count => 1
assert_select "note_area[maximum='#{Settings.max_note_request_area}']", :count => 1
assert_select "tracepoints[per_page='#{Settings.tracepoints_per_page}']", :count => 1
assert_select "changesets[maximum_elements='#{Changeset::MAX_ELEMENTS}']", :count => 1
assert_select "changesets" \
"[maximum_elements='#{Changeset::MAX_ELEMENTS}']" \
"[default_query_limit='#{Settings.default_changeset_query_limit}']" \
"[maximum_query_limit='#{Settings.max_changeset_query_limit}']", :count => 1
assert_select "relationmembers[maximum='#{Settings.max_number_of_relation_members}']", :count => 1
assert_select "notes" \
"[default_query_limit='#{Settings.default_note_query_limit}']" \
"[maximum_query_limit='#{Settings.max_note_query_limit}']", :count => 1
assert_select "status[database='online']", :count => 1
assert_select "status[api='online']", :count => 1
assert_select "status[gpx='online']", :count => 1
Expand All @@ -58,6 +64,8 @@ def test_capabilities_json
assert_equal Settings.default_changeset_query_limit, js["api"]["changesets"]["default_query_limit"]
assert_equal Settings.max_changeset_query_limit, js["api"]["changesets"]["maximum_query_limit"]
assert_equal Settings.max_number_of_relation_members, js["api"]["relationmembers"]["maximum"]
assert_equal Settings.default_note_query_limit, js["api"]["notes"]["default_query_limit"]
assert_equal Settings.max_note_query_limit, js["api"]["notes"]["maximum_query_limit"]
assert_equal "online", js["api"]["status"]["database"]
assert_equal "online", js["api"]["status"]["api"]
assert_equal "online", js["api"]["status"]["gpx"]
Expand Down
15 changes: 12 additions & 3 deletions test/controllers/api/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,9 @@ def test_index_limit
assert_select "gpx", :count => 1 do
assert_select "wpt", :count => 1
end

get api_notes_path(:bbox => "1,1,1.2,1.2", :limit => Settings.max_note_query_limit, :format => "rss")
assert_response :success
end

def test_index_empty_area
Expand Down Expand Up @@ -804,7 +807,7 @@ def test_index_bad_params
get api_notes_path(:bbox => "1,1,1.7,1.7", :limit => "0", :format => "json")
assert_response :bad_request

get api_notes_path(:bbox => "1,1,1.7,1.7", :limit => "10001", :format => "json")
get api_notes_path(:bbox => "1,1,1.7,1.7", :limit => Settings.max_note_query_limit + 1, :format => "json")
assert_response :bad_request
end

Expand Down Expand Up @@ -841,6 +844,9 @@ def test_search_success
assert_select "gpx", :count => 1 do
assert_select "wpt", :count => 1
end

get search_api_notes_path(:q => "note comment", :limit => Settings.max_note_query_limit, :format => "xml")
assert_response :success
end

def test_search_by_display_name_success
Expand Down Expand Up @@ -995,7 +1001,7 @@ def test_search_bad_params
get search_api_notes_path(:q => "no match", :limit => "0", :format => "json")
assert_response :bad_request

get search_api_notes_path(:q => "no match", :limit => "10001", :format => "json")
get search_api_notes_path(:q => "no match", :limit => Settings.max_note_query_limit + 1, :format => "json")
assert_response :bad_request

get search_api_notes_path(:display_name => "non-existent")
Expand Down Expand Up @@ -1037,6 +1043,9 @@ def test_feed_success
assert_select "item", :count => 2
end
end

get feed_api_notes_path(:bbox => "1,1,1.2,1.2", :limit => Settings.max_note_query_limit, :format => "rss")
assert_response :success
end

def test_feed_fail
Expand All @@ -1049,7 +1058,7 @@ def test_feed_fail
get feed_api_notes_path(:bbox => "1,1,1.2,1.2", :limit => "0", :format => "rss")
assert_response :bad_request

get feed_api_notes_path(:bbox => "1,1,1.2,1.2", :limit => "10001", :format => "rss")
get feed_api_notes_path(:bbox => "1,1,1.2,1.2", :limit => Settings.max_note_query_limit + 1, :format => "rss")
assert_response :bad_request
end
end
Expand Down

0 comments on commit 406d90c

Please sign in to comment.