From b7887b049fa1aae17f8b7020fe43542fffde1260 Mon Sep 17 00:00:00 2001 From: Richard Fairhurst Date: Mon, 9 Jan 2023 21:23:48 +0000 Subject: [PATCH] Remove Geonames and geocoder.ca --- app/abilities/ability.rb | 3 +- app/controllers/geocoder_controller.rb | 98 +------- config/locales/en.yml | 3 - config/routes.rb | 3 - config/settings.yml | 4 - config/settings/test.yml | 2 - test/abilities/abilities_test.rb | 4 +- test/controllers/geocoder_controller_test.rb | 83 +------ test/http/geocoder_ca.yml | 54 ----- test/http/geonames.yml | 228 ------------------- 10 files changed, 8 insertions(+), 474 deletions(-) delete mode 100644 test/http/geocoder_ca.yml delete mode 100644 test/http/geonames.yml diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index bb9cd6300..fd548c5f3 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -9,8 +9,7 @@ class Ability can :search, :direction can [:index, :permalink, :edit, :help, :fixthemap, :offline, :export, :about, :communities, :preview, :copyright, :key, :id], :site can [:finish, :embed], :export - can [:search, :search_latlon, :search_ca_postcode, :search_osm_nominatim, - :search_geonames, :search_osm_nominatim_reverse, :search_geonames_reverse], :geocoder + can [:search, :search_latlon, :search_osm_nominatim, :search_osm_nominatim_reverse], :geocoder can [:token, :request_token, :access_token, :test_request], :oauth if Settings.status != "database_offline" diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 4f9efa4dc..fc8b3a60b 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -15,19 +15,8 @@ class GeocoderController < ApplicationController if @params[:lat] && @params[:lon] @sources.push "latlon" @sources.push "osm_nominatim_reverse" - @sources.push "geonames_reverse" if Settings.key?(:geonames_username) elsif @params[:query] - case @params[:query] - when /^\d{5}(-\d{4})?$/, - /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i - @sources.push "osm_nominatim" - when /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i - @sources.push "ca_postcode" - @sources.push "osm_nominatim" - else - @sources.push "osm_nominatim" - @sources.push "geonames" if Settings.key?(:geonames_username) - end + @sources.push "osm_nominatim" end if @sources.empty? @@ -81,28 +70,6 @@ class GeocoderController < ApplicationController end end - def search_ca_postcode - # get query parameters - query = params[:query] - @results = [] - - # ask geocoder.ca (note - they have a per-day limit) - response = fetch_xml("https://geocoder.ca/?geoit=XML&postal=#{escape_query(query)}") - - # parse the response - if response.get_elements("geodata/error").empty? - @results.push(:lat => response.text("geodata/latt"), - :lon => response.text("geodata/longt"), - :zoom => Settings.postcode_zoom, - :name => query.upcase) - end - - render :action => "results" - rescue StandardError => e - @error = "Error contacting geocoder.ca: #{e}" - render :action => "error" - end - def search_osm_nominatim # get query parameters query = params[:query] @@ -172,38 +139,6 @@ class GeocoderController < ApplicationController render :action => "error" end - def search_geonames - # get query parameters - query = params[:query] - - # get preferred language - lang = I18n.locale.to_s.split("-").first - - # create result array - @results = [] - - # ask geonames.org - response = fetch_xml("http://api.geonames.org/search?q=#{escape_query(query)}&lang=#{lang}&maxRows=20&username=#{Settings.geonames_username}") - - # parse the response - response.elements.each("geonames/geoname") do |geoname| - lat = geoname.text("lat") - lon = geoname.text("lng") - name = geoname.text("name") - country = geoname.text("countryName") - - @results.push(:lat => lat, :lon => lon, - :zoom => Settings.geonames_zoom, - :name => name, - :suffix => ", #{country}") - end - - render :action => "results" - rescue StandardError => e - @error = "Error contacting api.geonames.org: #{e}" - render :action => "error" - end - def search_osm_nominatim_reverse # get query parameters lat = params[:lat] @@ -237,37 +172,6 @@ class GeocoderController < ApplicationController render :action => "error" end - def search_geonames_reverse - # get query parameters - lat = params[:lat] - lon = params[:lon] - - # get preferred language - lang = I18n.locale.to_s.split("-").first - - # create result array - @results = [] - - # ask geonames.org - response = fetch_xml("http://api.geonames.org/countrySubdivision?lat=#{lat}&lng=#{lon}&lang=#{lang}&username=#{Settings.geonames_username}") - - # parse the response - response.elements.each("geonames/countrySubdivision") do |geoname| - name = geoname.text("adminName1") - country = geoname.text("countryName") - - @results.push(:lat => lat, :lon => lon, - :zoom => Settings.geonames_zoom, - :name => name, - :suffix => ", #{country}") - end - - render :action => "results" - rescue StandardError => e - @error = "Error contacting api.geonames.org: #{e}" - render :action => "error" - end - private def fetch_text(url) diff --git a/config/locales/en.yml b/config/locales/en.yml index dbc5272c5..0d2da3a32 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -590,11 +590,8 @@ en: search: title: latlon_html: 'Results from Internal' - ca_postcode_html: 'Results from Geocoder.CA' osm_nominatim_html: 'Results from OpenStreetMap Nominatim' - geonames_html: 'Results from GeoNames' osm_nominatim_reverse_html: 'Results from OpenStreetMap Nominatim' - geonames_reverse_html: 'Results from GeoNames' search_osm_nominatim: prefix_format: "%{name}" prefix: diff --git a/config/routes.rb b/config/routes.rb index 80b897d08..8fd11c091 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -261,11 +261,8 @@ OpenStreetMap::Application.routes.draw do # geocoder get "/search" => "geocoder#search" get "/geocoder/search_latlon" => "geocoder#search_latlon" - get "/geocoder/search_ca_postcode" => "geocoder#search_ca_postcode" get "/geocoder/search_osm_nominatim" => "geocoder#search_osm_nominatim" - get "/geocoder/search_geonames" => "geocoder#search_geonames" get "/geocoder/search_osm_nominatim_reverse" => "geocoder#search_osm_nominatim_reverse" - get "/geocoder/search_geonames_reverse" => "geocoder#search_geonames_reverse" # directions get "/directions" => "directions#search" diff --git a/config/settings.yml b/config/settings.yml index 6e3f431f7..1c2d26a5a 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -37,8 +37,6 @@ max_number_of_relation_members: 32000 max_note_request_area: 25 # Zoom level to use for postcode results from the geocoder postcode_zoom: 15 -# Zoom level to use for geonames results from the geocoder -geonames_zoom: 12 # Timeout for API calls in seconds api_timeout: 300 # Timeout for web pages in seconds @@ -51,8 +49,6 @@ max_messages_per_hour: 60 max_friends_per_hour: 60 # Domain for handling message replies #messages_domain: "messages.openstreetmap.org" -# Geonames authentication details -#geonames_username: "" # MaxMind GeoIPv2 database #maxmind_database: "" # Users to show as being nearby diff --git a/config/settings/test.yml b/config/settings/test.yml index 5c5673f7d..1f951e872 100644 --- a/config/settings/test.yml +++ b/config/settings/test.yml @@ -1,7 +1,5 @@ # Ignore the diary feed delay unless we're specifically testing it diary_feed_delay: 0 -# Geonames credentials for testing -geonames_username: "dummy" # External authentication credentials for testing google_auth_id: "dummy" google_auth_secret: "dummy" diff --git a/test/abilities/abilities_test.rb b/test/abilities/abilities_test.rb index c27f75833..139f270fe 100644 --- a/test/abilities/abilities_test.rb +++ b/test/abilities/abilities_test.rb @@ -9,8 +9,8 @@ class GuestAbilityTest < AbilityTest test "geocoder permission for a guest" do ability = Ability.new nil - [:search, :search_latlon, :search_ca_postcode, :search_osm_nominatim, - :search_geonames, :search_osm_nominatim_reverse, :search_geonames_reverse].each do |action| + [:search, :search_latlon, :search_osm_nominatim, + :search_osm_nominatim_reverse].each do |action| assert ability.can?(action, :geocoder), "should be able to #{action} geocoder" end end diff --git a/test/controllers/geocoder_controller_test.rb b/test/controllers/geocoder_controller_test.rb index d0f0ce086..0d3b80e9e 100644 --- a/test/controllers/geocoder_controller_test.rb +++ b/test/controllers/geocoder_controller_test.rb @@ -12,26 +12,14 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest { :path => "/geocoder/search_latlon", :method => :get }, { :controller => "geocoder", :action => "search_latlon" } ) - assert_routing( - { :path => "/geocoder/search_ca_postcode", :method => :get }, - { :controller => "geocoder", :action => "search_ca_postcode" } - ) assert_routing( { :path => "/geocoder/search_osm_nominatim", :method => :get }, { :controller => "geocoder", :action => "search_osm_nominatim" } ) - assert_routing( - { :path => "/geocoder/search_geonames", :method => :get }, - { :controller => "geocoder", :action => "search_geonames" } - ) assert_routing( { :path => "/geocoder/search_osm_nominatim_reverse", :method => :get }, { :controller => "geocoder", :action => "search_osm_nominatim_reverse" } ) - assert_routing( - { :path => "/geocoder/search_geonames_reverse", :method => :get }, - { :controller => "geocoder", :action => "search_geonames_reverse" } - ) end ## @@ -263,13 +251,13 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest ## # Test identification of Canadian postcodes def test_identify_ca_postcode - search_check "A1B 2C3", %w[ca_postcode osm_nominatim] + search_check "A1B 2C3", %w[osm_nominatim] end ## # Test identification fall through to the default case def test_identify_default - search_check "foo bar baz", %w[osm_nominatim geonames] + search_check "foo bar baz", %w[osm_nominatim] end ## @@ -315,28 +303,6 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest results_check_error "Latitude or longitude are out of range" end - ## - # Test the Canadian postcode search - def test_search_ca_postcode - with_http_stubs "geocoder_ca" do - get geocoder_search_ca_postcode_path(:query => "A1B 2C3", :zoom => 10, - :minlon => -0.559, :minlat => 51.217, - :maxlon => 0.836, :maxlat => 51.766), :xhr => true - - results_check :name => "A1B 2C3", :lat => "47.172520", :lon => "-55.440515" - - get geocoder_search_ca_postcode_path(:query => "k1a 0b1", :zoom => 10, - :minlon => -0.559, :minlat => 51.217, - :maxlon => 0.836, :maxlat => 51.766), :xhr => true - results_check :name => "K1A 0B1", :lat => "45.375437", :lon => "-75.691041" - - get geocoder_search_ca_postcode_path(:query => "Q0Q 0Q0", :zoom => 10, - :minlon => -0.559, :minlat => 51.217, - :maxlon => 0.836, :maxlat => 51.766), :xhr => true - results_check - end - end - ## # Test the nominatim forward search def test_search_osm_nominatim @@ -370,37 +336,6 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest end end - ## - # Test the geonames forward search - def test_search_geonames - with_http_stubs "geonames" do - get geocoder_search_geonames_path(:query => "Hoddesdon", :zoom => 10, :minlon => -0.559, :minlat => 51.217, - :maxlon => 0.836, :maxlat => 51.766), :xhr => true - results_check :name => "Hoddesdon", :lat => 51.76148, :lon => -0.01144 - - get geocoder_search_geonames_path(:query => "Broxbourne", :zoom => 10, - :minlon => -0.559, :minlat => 51.217, - :maxlon => 0.836, :maxlat => 51.766), :xhr => true - results_check({ :name => "Broxbourne", :lat => 51.74712, :lon => -0.01923 }, - { :name => "Broxbourne District", :lat => 51.73026, :lon => -0.04821 }, - { :name => "Cheshunt", :lat => 51.70791, :lon => -0.03739 }, - { :name => "Hoddesdon", :lat => 51.76148, :lon => -0.01144 }, - { :name => "Waltham Cross", :lat => 51.68905, :lon => -0.0333 }, - { :name => "Goffs Oak", :lat => 51.71015, :lon => -0.0872 }, - { :name => "Wormley", :lat => 51.7324, :lon => -0.0242 }, - { :name => "Broxbourne", :lat => -27.50314, :lon => 151.378 }, - { :name => "Lee Valley White Water Centre", :lat => 51.68814, :lon => -0.01682 }, - { :name => "Cheshunt Railway Station", :lat => 51.703, :lon => -0.024 }, - { :name => "Theobalds Grove Railway Station", :lat => 51.692, :lon => -0.035 }, - { :name => "Waltham Cross Railway Station", :lat => 51.685, :lon => -0.027 }, - { :name => "Rye House Station", :lat => 51.76938, :lon => 0.00562 }, - { :name => "Broxbourne Station", :lat => 51.74697, :lon => -0.01105 }, - { :name => "Broxbornebury Park", :lat => 51.75252, :lon => -0.03839 }, - { :name => "Marriott Cheshunt", :lat => 51.7208, :lon => -0.0324 }, - { :name => "Cheshunt Community Hospital", :lat => 51.68396, :lon => -0.03951 }) - end - end - ## # Test the nominatim reverse search def test_search_osm_nominatim_reverse @@ -422,16 +357,6 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest end end - ## - # Test the geonames reverse search - def test_search_geonames_reverse - with_http_stubs "geonames" do - get geocoder_search_geonames_reverse_path(:lat => 51.7632, :lon => -0.0076, :zoom => 15), :xhr => true - results_check :name => "England", :suffix => ", United Kingdom", - :lat => 51.7632, :lon => -0.0076 - end - end - private def latlon_check(query, lat, lon) @@ -439,7 +364,7 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_template :search assert_template :layout => "map" - assert_equal %w[latlon osm_nominatim_reverse geonames_reverse], assigns(:sources) + assert_equal %w[latlon osm_nominatim_reverse], assigns(:sources) assert_nil @controller.params[:query] assert_in_delta lat, @controller.params[:lat] assert_in_delta lon, @controller.params[:lon] @@ -448,7 +373,7 @@ class GeocoderControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_template :search assert_template :layout => "xhr" - assert_equal %w[latlon osm_nominatim_reverse geonames_reverse], assigns(:sources) + assert_equal %w[latlon osm_nominatim_reverse], assigns(:sources) assert_nil @controller.params[:query] assert_in_delta lat, @controller.params[:lat] assert_in_delta lon, @controller.params[:lon] diff --git a/test/http/geocoder_ca.yml b/test/http/geocoder_ca.yml deleted file mode 100644 index 0fbaa105d..000000000 --- a/test/http/geocoder_ca.yml +++ /dev/null @@ -1,54 +0,0 @@ -/?geoit=XML&postal=A1B%202C3: - code: 200 - body: | - - - 47.172520 - -55.440515 - A1B2C3 - - 1 - - ST. JOHN&'S - NL - 0.9 - - - -/?geoit=XML&postal=k1a%200b1: - code: 200 - body: | - - - 45.375437 - -75.691041 - K1A0B1 - - 1 - - OTTAWA - ON - 0.9 - - - -/?geoit=XML&postal=Q0Q%200Q0: - code: 200 - body: | - - - - 008 - Your request did not produce any results. Check your spelling and try again. - - - - - Q0Q0Q0 - - 1 - - - - 0.9 - - diff --git a/test/http/geonames.yml b/test/http/geonames.yml deleted file mode 100644 index 65356c807..000000000 --- a/test/http/geonames.yml +++ /dev/null @@ -1,228 +0,0 @@ -/search?lang=en&maxRows=20&q=Hoddesdon&username=dummy: - code: 200 - body: | - - - 1 - - Hoddesdon - Hoddesdon - 51.76148 - -0.01144 - 2646807 - GB - United Kingdom - P - PPL - - - -/search?lang=en&maxRows=20&q=Broxbourne&username=dummy: - code: 200 - body: | - - - 17 - - Broxbourne - Broxbourne - 51.74712 - -0.01923 - 2654481 - GB - United Kingdom - P - PPL - - - Broxbourne District - Broxbourne District - 51.73026 - -0.04821 - 7290563 - GB - United Kingdom - A - ADM3 - - - Cheshunt - Cheshunt - 51.70791 - -0.03739 - 2653232 - GB - United Kingdom - P - PPL - - - Hoddesdon - Hoddesdon - 51.76148 - -0.01144 - 2646807 - GB - United Kingdom - P - PPL - - - Waltham Cross - Waltham Cross - 51.68905 - -0.0333 - 2634842 - GB - United Kingdom - P - PPL - - - Goffs Oak - Goffs Oak - 51.71015 - -0.0872 - 2648362 - GB - United Kingdom - P - PPL - - - Wormley - Wormley - 51.7324 - -0.0242 - 2633535 - GB - United Kingdom - P - PPL - - - Broxbourne - Broxbourne - -27.50314 - 151.378 - 8792801 - AU - Australia - S - HMSD - - - Lee Valley White Water Centre - Lee Valley White Water Centre - 51.68814 - -0.01682 - 7670551 - GB - United Kingdom - S - FCL - - - Cheshunt Railway Station - Cheshunt Railway Station - 51.703 - -0.024 - 6952282 - GB - United Kingdom - S - RSTN - - - Theobalds Grove Railway Station - Theobalds Grove Railway Station - 51.692 - -0.035 - 6953715 - GB - United Kingdom - S - RSTN - - - Waltham Cross Railway Station - Waltham Cross Railway Station - 51.685 - -0.027 - 6953801 - GB - United Kingdom - S - RSTN - - - Rye House Station - Rye House Station - 51.76938 - 0.00562 - 6691700 - GB - United Kingdom - S - RSTN - - - Broxbourne Station - Broxbourne Station - 51.74697 - -0.01105 - 6691701 - GB - United Kingdom - S - RSTN - - - Broxbornebury Park - Broxbornebury Park - 51.75252 - -0.03839 - 6286417 - GB - United Kingdom - S - CSTL - - - Marriott Cheshunt - Marriott Cheshunt - 51.7208 - -0.0324 - 6512481 - GB - United Kingdom - S - HTL - - - Cheshunt Community Hospital - Cheshunt Community Hospital - 51.68396 - -0.03951 - 6289233 - GB - United Kingdom - S - HSP - - - -/countrySubdivision?lang=en&lat=51.7632&lng=-0.0076&username=dummy: - code: 200 - body: | - - - - GB - United Kingdom - ENG - England - ENG - 0.0 - - -- 2.43.2