]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/3493'
authorTom Hughes <tom@compton.nu>
Tue, 8 Mar 2022 20:30:19 +0000 (20:30 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 8 Mar 2022 20:30:19 +0000 (20:30 +0000)
12 files changed:
.rubocop_todo.yml
Gemfile
Gemfile.lock
app/controllers/api_controller.rb
app/controllers/application_controller.rb
app/controllers/diary_entries_controller.rb
app/controllers/geocoder_controller.rb
app/helpers/browse_tags_helper.rb
lib/diff_reader.rb
lib/osm.rb
test/controllers/api/relations_controller_test.rb
test/test_helper.rb

index 95e3be8febbabc95db4766080f68b8722b857ec1..8c1ce723c67b165f5c4c9dba4de51d2437358591 100644 (file)
@@ -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 8782fdfeffd47aef046f2f1db90366ffb6c8012d..02e5e309f791175753493011d21ed8aed5c88f71 100644 (file)
--- 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"
index 58165e5858f2d53ebb5da79a5ed364bc0de70d8c..57965460438f90c45c492244af3daba2a7ea0020 100644 (file)
@@ -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)
index a138976409bba94bb259fbc1caac61935aa1f325..050c455cdf64f6bf09bf4e01db8849683fb0cc31 100644 (file)
@@ -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)
index bb32e7e6e5cbbe25da6787efc37dce39266e8c8d..1d68654055538fd597265043e2adcb52e3ceb94f 100644 (file)
@@ -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
index 312e1e54caf3464649fc52e71ff34e5a8fec32f4..467c4a38f280db468be0b611d6c336eee83eedd8 100644 (file)
@@ -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
index 8d651fe0f1345b27cbaeff18044e19164d99a992..7417cab762fdcdbbe3852d2a96cd73b3b973707e 100644 (file)
@@ -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*)?)$/)
index d96bbef64b349d96f8582988e1bf2d6393889000..e7562081dfd0415b2684ec0c0516607b11582a77 100644 (file)
@@ -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
index 1189c86d0e3236307ec4f4fdb50d42c7c5ecc150..d1987a93622f0d1a44eb128555f6f6cc4258bd26 100644 (file)
@@ -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 <osmChange> element
index ee0b8d9030ee719c769cdb0039edef17d8631e01..e258aaaf03a5aaadcb3b3b4ea7a509ec465f4cfc 100644 (file)
@@ -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"
index ec86e07a57ac242f60c71f11b90750695731b3df..eb8f8e02256eb5c3d8e97341a2f2758316199ba6 100644 (file)
@@ -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"
index 421ae8698847a0d1cbe7090045b69e37d37db389..7157abf5a71ed0ef153b70c50c3436a6b99c00c2 100644 (file)
@@ -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