From: Tom Hughes Date: Tue, 8 Mar 2022 20:30:19 +0000 (+0000) Subject: Merge remote-tracking branch 'upstream/pull/3493' X-Git-Tag: live~2295 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/44ac569d286ce1159f49b2cded184ff0cc4475f5?hp=c9e836a6cb070dc28deac3298994ba0118222e91 Merge remote-tracking branch 'upstream/pull/3493' --- diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 95e3be8fe..8c1ce723c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -54,15 +54,6 @@ Lint/AssignmentInCondition: - 'lib/osm.rb' - 'script/deliver-message' -# Offense count: 7 -# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. -Lint/DuplicateBranch: - Exclude: - - 'app/controllers/api_controller.rb' - - 'app/controllers/diary_entries_controller.rb' - - 'app/controllers/geocoder_controller.rb' - - 'app/helpers/browse_tags_helper.rb' - # Offense count: 665 # Configuration parameters: IgnoredMethods, CountRepeatedAttributes. Metrics/AbcSize: @@ -108,12 +99,10 @@ Metrics/PerceivedComplexity: Minitest/MultipleAssertions: Max: 52 -# Offense count: 3 +# Offense count: 1 Naming/AccessorMethodName: Exclude: - - 'app/controllers/application_controller.rb' - 'app/helpers/title_helper.rb' - - 'lib/osm.rb' # Offense count: 8 # Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros. diff --git a/Gemfile b/Gemfile index 8782fdfef..02e5e309f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" # Require rails -gem "rails", "7.0.2.2" +gem "rails", "7.0.2.3" # Require json for multi_json gem "json" diff --git a/Gemfile.lock b/Gemfile.lock index 58165e585..579654604 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,73 +3,73 @@ GEM specs: aasm (5.2.0) concurrent-ruby (~> 1.0) - actioncable (7.0.2.2) - actionpack (= 7.0.2.2) - activesupport (= 7.0.2.2) + actioncable (7.0.2.3) + actionpack (= 7.0.2.3) + activesupport (= 7.0.2.3) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (7.0.2.2) - actionpack (= 7.0.2.2) - activejob (= 7.0.2.2) - activerecord (= 7.0.2.2) - activestorage (= 7.0.2.2) - activesupport (= 7.0.2.2) + actionmailbox (7.0.2.3) + actionpack (= 7.0.2.3) + activejob (= 7.0.2.3) + activerecord (= 7.0.2.3) + activestorage (= 7.0.2.3) + activesupport (= 7.0.2.3) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.0.2.2) - actionpack (= 7.0.2.2) - actionview (= 7.0.2.2) - activejob (= 7.0.2.2) - activesupport (= 7.0.2.2) + actionmailer (7.0.2.3) + actionpack (= 7.0.2.3) + actionview (= 7.0.2.3) + activejob (= 7.0.2.3) + activesupport (= 7.0.2.3) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.0) - actionpack (7.0.2.2) - actionview (= 7.0.2.2) - activesupport (= 7.0.2.2) + actionpack (7.0.2.3) + actionview (= 7.0.2.3) + activesupport (= 7.0.2.3) rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) actionpack-page_caching (1.2.4) actionpack (>= 4.0.0) - actiontext (7.0.2.2) - actionpack (= 7.0.2.2) - activerecord (= 7.0.2.2) - activestorage (= 7.0.2.2) - activesupport (= 7.0.2.2) + actiontext (7.0.2.3) + actionpack (= 7.0.2.3) + activerecord (= 7.0.2.3) + activestorage (= 7.0.2.3) + activesupport (= 7.0.2.3) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.0.2.2) - activesupport (= 7.0.2.2) + actionview (7.0.2.3) + activesupport (= 7.0.2.3) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) active_record_union (1.3.0) activerecord (>= 4.0) - activejob (7.0.2.2) - activesupport (= 7.0.2.2) + activejob (7.0.2.3) + activesupport (= 7.0.2.3) globalid (>= 0.3.6) - activemodel (7.0.2.2) - activesupport (= 7.0.2.2) - activerecord (7.0.2.2) - activemodel (= 7.0.2.2) - activesupport (= 7.0.2.2) + activemodel (7.0.2.3) + activesupport (= 7.0.2.3) + activerecord (7.0.2.3) + activemodel (= 7.0.2.3) + activesupport (= 7.0.2.3) activerecord-import (1.3.0) activerecord (>= 4.2) - activestorage (7.0.2.2) - actionpack (= 7.0.2.2) - activejob (= 7.0.2.2) - activerecord (= 7.0.2.2) - activesupport (= 7.0.2.2) + activestorage (7.0.2.3) + actionpack (= 7.0.2.3) + activejob (= 7.0.2.3) + activerecord (= 7.0.2.3) + activesupport (= 7.0.2.3) marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (7.0.2.2) + activesupport (7.0.2.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -86,8 +86,8 @@ GEM autoprefixer-rails (10.4.2.0) execjs (~> 2) aws-eventstream (1.2.0) - aws-partitions (1.563.0) - aws-sdk-core (3.128.1) + aws-partitions (1.564.0) + aws-sdk-core (3.129.0) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.525.0) aws-sigv4 (~> 1.1) @@ -378,20 +378,20 @@ GEM rack-test (1.1.0) rack (>= 1.0, < 3) rack-uri_sanitizer (0.0.2) - rails (7.0.2.2) - actioncable (= 7.0.2.2) - actionmailbox (= 7.0.2.2) - actionmailer (= 7.0.2.2) - actionpack (= 7.0.2.2) - actiontext (= 7.0.2.2) - actionview (= 7.0.2.2) - activejob (= 7.0.2.2) - activemodel (= 7.0.2.2) - activerecord (= 7.0.2.2) - activestorage (= 7.0.2.2) - activesupport (= 7.0.2.2) + rails (7.0.2.3) + actioncable (= 7.0.2.3) + actionmailbox (= 7.0.2.3) + actionmailer (= 7.0.2.3) + actionpack (= 7.0.2.3) + actiontext (= 7.0.2.3) + actionview (= 7.0.2.3) + activejob (= 7.0.2.3) + activemodel (= 7.0.2.3) + activerecord (= 7.0.2.3) + activestorage (= 7.0.2.3) + activesupport (= 7.0.2.3) bundler (>= 1.15.0) - railties (= 7.0.2.2) + railties (= 7.0.2.3) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) @@ -404,9 +404,9 @@ GEM rails-i18n (7.0.3) i18n (>= 0.7, < 2) railties (>= 6.0.0, < 8) - railties (7.0.2.2) - actionpack (= 7.0.2.2) - activesupport (= 7.0.2.2) + railties (7.0.2.3) + actionpack (= 7.0.2.3) + activesupport (= 7.0.2.3) method_source rake (>= 12.2) thor (~> 1.0) @@ -574,7 +574,7 @@ DEPENDENCIES r2 (~> 0.2.7) rack-cors rack-uri_sanitizer - rails (= 7.0.2.2) + rails (= 7.0.2.3) rails-controller-testing rails-i18n (~> 7.0.0) rinku (>= 2.0.6) diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index a13897640..050c455cd 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -31,9 +31,8 @@ class ApiController < ApplicationController # as XML for backwards compatibility - all other formats are discarded # which will result in a 406 Not Acceptable response being sent formats = mimetypes.map do |mime| - if mime.symbol == :xml then :xml + if mime.symbol == :xml || mime == "*/*" then :xml elsif mime.symbol == :json then :json - elsif mime == "*/*" then :xml end end else @@ -101,7 +100,7 @@ class ApiController < ApplicationController elsif Authenticator.new(self, [:token]).allow? # self.current_user setup by OAuth else - username, passwd = get_auth_data # parse from headers + username, passwd = auth_data # parse from headers # authenticate per-scheme self.current_user = if username.nil? nil # no authentication provided - perhaps first connect (client should retry after 401) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bb32e7e6e..1d6865405 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -161,7 +161,7 @@ class ApplicationController < ActionController::Base response.headers["Error"] = message if request.headers["X-Error-Format"]&.casecmp("xml")&.zero? - result = OSM::API.new.get_xml_doc + result = OSM::API.new.xml_doc result.root.name = "osmError" result.root << (XML::Node.new("status") << "#{Rack::Utils.status_code(status)} #{Rack::Utils::HTTP_STATUS_CODES[status]}") result.root << (XML::Node.new("message") << message) @@ -363,7 +363,7 @@ class ApplicationController < ActionController::Base end # extract authorisation credentials from headers, returns user = nil if none - def get_auth_data + def auth_data if request.env.key? "X-HTTP_AUTHORIZATION" # where mod_rewrite might have put it authdata = request.env["X-HTTP_AUTHORIZATION"].to_s.split elsif request.env.key? "REDIRECT_X_HTTP_AUTHORIZATION" # mod_fcgi diff --git a/app/controllers/diary_entries_controller.rb b/app/controllers/diary_entries_controller.rb index 312e1e54c..467c4a38f 100644 --- a/app/controllers/diary_entries_controller.rb +++ b/app/controllers/diary_entries_controller.rb @@ -60,9 +60,8 @@ class DiaryEntriesController < ApplicationController @title = t "diary_entries.edit.title" @diary_entry = DiaryEntry.find(params[:id]) - if current_user != @diary_entry.user - redirect_to diary_entry_path(@diary_entry.user, @diary_entry) - elsif params[:diary_entry] && @diary_entry.update(entry_params) + if current_user != @diary_entry.user || + (params[:diary_entry] && @diary_entry.update(entry_params)) redirect_to diary_entry_path(@diary_entry.user, @diary_entry) else set_map_location diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 8d651fe0f..7417cab76 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -18,9 +18,8 @@ class GeocoderController < ApplicationController @sources.push "geonames_reverse" if Settings.key?(:geonames_username) elsif @params[:query] case @params[:query] - when /^\d{5}(-\d{4})?$/ - @sources.push "osm_nominatim" - when /^(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 + 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" @@ -291,19 +290,16 @@ class GeocoderController < ApplicationController if query = params[:query] query.strip! - if latlon = query.match(/^([NS])\s*(\d{1,3}(\.\d*)?)\W*([EW])\s*(\d{1,3}(\.\d*)?)$/).try(:captures) # [NSEW] decimal degrees - params.merge!(nsew_to_decdeg(latlon)).delete(:query) - elsif latlon = query.match(/^(\d{1,3}(\.\d*)?)\s*([NS])\W*(\d{1,3}(\.\d*)?)\s*([EW])$/).try(:captures) # decimal degrees [NSEW] + if latlon = query.match(/^([NS])\s*(\d{1,3}(\.\d*)?)\W*([EW])\s*(\d{1,3}(\.\d*)?)$/).try(:captures) || # [NSEW] decimal degrees + query.match(/^(\d{1,3}(\.\d*)?)\s*([NS])\W*(\d{1,3}(\.\d*)?)\s*([EW])$/).try(:captures) # decimal degrees [NSEW] params.merge!(nsew_to_decdeg(latlon)).delete(:query) - elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\W*([EW])\s*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?$/).try(:captures) # [NSEW] degrees, decimal minutes - params.merge!(ddm_to_decdeg(latlon)).delete(:query) - elsif latlon = query.match(/^(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\s*([NS])\W*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW] + elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\W*([EW])\s*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?$/).try(:captures) || # [NSEW] degrees, decimal minutes + query.match(/^(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\s*([NS])\W*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW] params.merge!(ddm_to_decdeg(latlon)).delete(:query) - elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds - params.merge!(dms_to_decdeg(latlon)).delete(:query) - elsif latlon = query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW] + elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?$/).try(:captures) || # [NSEW] degrees, minutes, decimal seconds + query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW] params.merge!(dms_to_decdeg(latlon)).delete(:query) elsif latlon = query.match(/^([+-]?\d+(\.\d*)?)(?:\s+|\s*,\s*)([+-]?\d+(\.\d*)?)$/) diff --git a/app/helpers/browse_tags_helper.rb b/app/helpers/browse_tags_helper.rb index d96bbef64..e7562081d 100644 --- a/app/helpers/browse_tags_helper.rb +++ b/app/helpers/browse_tags_helper.rb @@ -47,11 +47,10 @@ module BrowseTagsHelper # the correct page. lookup_us = lookup.tr(" ", "_") - if page = WIKI_PAGES.dig(locale, type, lookup_us) - url = "https://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}" - elsif page = WIKI_PAGES.dig("en", type, lookup_us) - url = "https://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}" - end + page = WIKI_PAGES.dig(locale, type, lookup_us) || + WIKI_PAGES.dig("en", type, lookup_us) + + url = "https://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}" if page url end diff --git a/lib/diff_reader.rb b/lib/diff_reader.rb index 1189c86d0..d1987a936 100644 --- a/lib/diff_reader.rb +++ b/lib/diff_reader.rb @@ -128,7 +128,7 @@ class DiffReader @reader.read raise OSM::APIBadUserInput, "Document element should be 'osmChange'." if @reader.name != "osmChange" - result = OSM::API.new.get_xml_doc + result = OSM::API.new.xml_doc result.root.name = "diffResult" # loop at the top level, within the element diff --git a/lib/osm.rb b/lib/osm.rb index ee0b8d903..e258aaaf0 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -445,7 +445,7 @@ module OSM end class API - def get_xml_doc + def xml_doc doc = XML::Document.new doc.encoding = XML::Encoding::UTF_8 root = XML::Node.new "osm" diff --git a/test/controllers/api/relations_controller_test.rb b/test/controllers/api/relations_controller_test.rb index ec86e07a5..eb8f8e022 100644 --- a/test/controllers/api/relations_controller_test.rb +++ b/test/controllers/api/relations_controller_test.rb @@ -1036,7 +1036,7 @@ module Api version = nil with_controller(Api::ChangesetsController.new) do - doc = OSM::API.new.get_xml_doc + doc = OSM::API.new.xml_doc change = XML::Node.new "osmChange" doc.root = change modify = XML::Node.new "modify" diff --git a/test/test_helper.rb b/test/test_helper.rb index 421ae8698..7157abf5a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -255,7 +255,7 @@ module ActiveSupport end def xml_for_node(node) - doc = OSM::API.new.get_xml_doc + doc = OSM::API.new.xml_doc doc.root << xml_node_for_node(node) doc end @@ -277,7 +277,7 @@ module ActiveSupport end def xml_for_way(way) - doc = OSM::API.new.get_xml_doc + doc = OSM::API.new.xml_doc doc.root << xml_node_for_way(way) doc end @@ -308,7 +308,7 @@ module ActiveSupport end def xml_for_relation(relation) - doc = OSM::API.new.get_xml_doc + doc = OSM::API.new.xml_doc doc.root << xml_node_for_relation(relation) doc end