]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/3264'
authorTom Hughes <tom@compton.nu>
Wed, 21 Jul 2021 14:41:31 +0000 (15:41 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 21 Jul 2021 14:41:31 +0000 (15:41 +0100)
20 files changed:
app/assets/javascripts/oauth.js
app/controllers/api/user_preferences_controller.rb
app/controllers/application_controller.rb
app/controllers/issues_controller.rb
app/helpers/application_helper.rb
app/helpers/banner_helper.rb
app/models/concerns/consistency_validations.rb
app/models/user.rb
config/settings.yml
package.json
test/controllers/api/map_controller_test.rb
test/controllers/api/relations_controller_test.rb
test/controllers/api/tracepoints_controller_test.rb
test/controllers/api/traces_controller_test.rb
test/controllers/traces_controller_test.rb
test/lib/utf8_test.rb
test/models/message_test.rb
test/models/user_test.rb
test/test_helper.rb
yarn.lock

index d688590b05c0ce0ed8e6bbb25f307b3e2a32177f..0c3538c511089ae087da3aafb678d37f9979b458 100644 (file)
@@ -1,26 +1,11 @@
-//= require ohauth/ohauth
-
 $(document).ready(function () {
   var application_data = $("head").data();
 
-  function makeAbsolute(url) {
-    var a = document.createElement("a");
-    a.href = url;
-    return a.href;
-  }
-
-  if (application_data.token) {
-    var headerGenerator = window.ohauth.headerGenerator({
-      consumer_key: application_data.consumerKey,
-      consumer_secret: application_data.consumerSecret,
-      token: application_data.token,
-      token_secret: application_data.tokenSecret
-    });
-
-    $.ajaxPrefilter(function (options, jqxhr) {
+  if (application_data.oauthToken) {
+    $.ajaxPrefilter(function (options) {
       if (options.oauth) {
         options.headers = options.headers || {};
-        options.headers.Authorization = headerGenerator(options.type, makeAbsolute(options.url), jqxhr.data);
+        options.headers.Authorization = "Bearer " + application_data.oauthToken;
       }
     });
   }
index 40ccfccbbc4a222a841c67f312d6665a13998a10..02a23095addd70ef9a72dde3d84cad35a257b308 100644 (file)
@@ -1,4 +1,4 @@
-# Update and read user preferences, which are arbitrayr key/val pairs
+# Update and read user preferences, which are arbitrary key/val pairs
 module Api
   class UserPreferencesController < ApiController
     before_action :authorize
index fc8b75b60144ec40e2bf2a851ae7fcdce8c171da..8df126a04e3a5ea02325b652dc0f0432cf08b5ab 100644 (file)
@@ -67,7 +67,7 @@ class ApplicationController < ActionController::Base
   end
 
   def require_oauth
-    @oauth_token = current_user.access_token(Settings.oauth_key) if current_user && Settings.key?(:oauth_key)
+    @oauth_token = current_user.oauth_token(Settings.oauth_application) if current_user && Settings.key?(:oauth_application)
   end
 
   ##
index f30ece3ec023d3dcef7523d8ad7584a8919d2c40..5940389397ca76e8b7b6d9a524a76d9df41185c0 100644 (file)
@@ -47,7 +47,7 @@ class IssuesController < ApplicationController
     @new_comment = IssueComment.new(:issue => @issue)
   end
 
-  # Status Transistions
+  # Status Transitions
   def resolve
     if @issue.resolve
       @issue.updated_by = current_user.id
index faf538fa926917dc429136d1a960eebd4ba7e13e..c9f165d528af8f7d32bd6ee94e03035e02d3a2e8 100644 (file)
@@ -58,13 +58,7 @@ module ApplicationHelper
     end
 
     data[:location] = session[:location] if session[:location]
-
-    if oauth_token
-      data[:token] = oauth_token.token
-      data[:token_secret] = oauth_token.secret
-      data[:consumer_key] = oauth_token.client_application.key
-      data[:consumer_secret] = oauth_token.client_application.secret
-    end
+    data[:oauth_token] = oauth_token.token if oauth_token
 
     data
   end
index fef6eaa5e77c989c177eb0c15aed84687c844fbf..17c6eace3d4eb2cf4c4f24e5d208ab07925acdd7 100644 (file)
@@ -28,7 +28,7 @@ module BannerHelper
       index = cval.to_i
       cookies[ckey] = index - 1 if index.positive?
 
-      # pick banner with mininum queue position
+      # pick banner with minimum queue position
       next if index > min_index
 
       # or if equal queue position, pick banner with soonest end date (i.e. next expiring)
index 00c6ce9934b7b37c6a95f74e32a68d4678714668..8c89f61de9dfad633a31e65fa8356ad963d75817 100644 (file)
@@ -3,7 +3,7 @@ module ConsistencyValidations
 
   # Generic checks that are run for the updates and deletes of
   # node, ways and relations. This code is here to avoid duplication,
-  # and allow the extention of the checks without having to modify the
+  # and allow the extension of the checks without having to modify the
   # code in 6 places for all the updates and deletes. Some of these tests are
   # needed for creates, but are currently not run :-(
   # This will throw an exception if there is an inconsistency
index 964359e9cd4cec972f596f08eec1b45c71de3fe2..cca894a6bf291e54e5a3424c51e8ebcfa8374d9b 100644 (file)
@@ -68,7 +68,7 @@ class User < ApplicationRecord
   has_many :client_applications
   has_many :oauth_tokens, -> { order(:authorized_at => :desc).preload(:client_application) }, :class_name => "OauthToken"
 
-  has_many :oauth2_applications, :class_name => Doorkeeper.config.application_model.name, :foreign_key => :owner_id
+  has_many :oauth2_applications, :class_name => Doorkeeper.config.application_model.name, :as => :owner
   has_many :access_grants, :class_name => Doorkeeper.config.access_grant_model.name, :foreign_key => :resource_owner_id
   has_many :access_tokens, :class_name => Doorkeeper.config.access_token_model.name, :foreign_key => :resource_owner_id
 
@@ -288,11 +288,23 @@ class User < ApplicationRecord
   end
 
   ##
-  # return an oauth access token for a specified application
+  # return an oauth access token for a specified application
   def access_token(application_key)
     ClientApplication.find_by(:key => application_key).access_token_for_user(self)
   end
 
+  ##
+  # return an oauth 2 access token for a specified application
+  def oauth_token(application_id)
+    application = Doorkeeper.config.application_model.find_by(:uid => application_id)
+
+    Doorkeeper.config.access_token_model.find_or_create_for(
+      :application => application,
+      :resource_owner => self,
+      :scopes => application.scopes
+    )
+  end
+
   def fingerprint
     digest = Digest::SHA256.new
     digest.update(email)
index 81ab3701597a304a314adb95e6bcf2a4adf525c8..6f77efcfd835ea3b83e00e6706225839b2ac2166 100644 (file)
@@ -84,8 +84,8 @@ oauth_10_support: true
 nominatim_url: "https://nominatim.openstreetmap.org/"
 # Default editor
 default_editor: "id"
-# OAuth consumer key for the web site
-#oauth_key: ""
+# OAuth application for the web site
+#oauth_application: ""
 # OAuth consumer key for iD
 #id_key: ""
 # Imagery to return in capabilities as blacklisted
index 60da79b05fb7deb051a12bdcca089fd095bc8bd3..4e5538cfde6494160bedd546d787eae5f4dad60c 100644 (file)
@@ -8,7 +8,6 @@
     "js-cookie": "^2.2.1",
     "leaflet": "^1.6.0",
     "leaflet.locatecontrol": "^0.74.0",
-    "ohauth": "^1.0.0",
     "qs": "^6.9.4"
   },
   "devDependencies": {
index e9459b6a283692196b3ab26897f0979b5effcf0f..433e7a2afd6d0a386b83ef6421b8282edc700cd5 100644 (file)
@@ -13,7 +13,7 @@ module Api
       @goodbbox = %w[-0.1,-0.1,0.1,0.1 51.1,-0.1,51.2,0
                      -0.1,%20-0.1,%200.1,%200.1 -0.1edcd,-0.1d,0.1,0.1 -0.1E,-0.1E,0.1S,0.1N S0.1,W0.1,N0.1,E0.1]
       # That last item in the goodbbox really shouldn't be there, as the API should
-      # reall reject it, however this is to test to see if the api changes.
+      # really reject it, however this is to test to see if the api changes.
     end
 
     ##
index 44c6cd4eec1e817db0d615389403266f1f9e65a0..ec86e07a57ac242f60c71f11b90750695731b3df 100644 (file)
@@ -1009,7 +1009,7 @@ module Api
     ##
     # updates the relation (XML) +rel+ and
     # yields the new version of that relation into the block.
-    # the parsed XML doc is retured.
+    # the parsed XML doc is returned.
     def with_update(rel, headers)
       rel_id = rel.find("//osm/relation").first["id"].to_i
       put api_relation_path(:id => rel_id), :params => rel.to_s, :headers => headers
@@ -1029,7 +1029,7 @@ module Api
     ##
     # updates the relation (XML) +rel+ via the diff-upload API and
     # yields the new version of that relation into the block.
-    # the parsed XML doc is retured.
+    # the parsed XML doc is returned.
     def with_update_diff(rel, headers)
       rel_id = rel.find("//osm/relation").first["id"].to_i
       cs_id = rel.find("//osm/relation").first["changeset"].to_i
index d3fb195feb6ce42950b00bdbc03e83e645707679..a904e8127693f37e7ccb48900a3e8b0259311074 100644 (file)
@@ -13,7 +13,7 @@ module Api
       @goodbbox = %w[-0.1,-0.1,0.1,0.1 51.1,-0.1,51.2,0
                      -0.1,%20-0.1,%200.1,%200.1 -0.1edcd,-0.1d,0.1,0.1 -0.1E,-0.1E,0.1S,0.1N S0.1,W0.1,N0.1,E0.1]
       # That last item in the goodbbox really shouldn't be there, as the API should
-      # reall reject it, however this is to test to see if the api changes.
+      # really reject it, however this is to test to see if the api changes.
     end
 
     ##
index c2ddb6031f6742274d49854530ef1fdd369a22d0..52df899ba0778e8f2b600ddf14d6272827aa66da 100644 (file)
@@ -70,7 +70,7 @@ module Api
       assert_response :success
     end
 
-    # Check an anoymous trace can't be specifically fetched by another user
+    # Check an anonymous trace can't be specifically fetched by another user
     def test_show_anon
       anon_trace_file = create(:trace, :visibility => "private")
 
index 39a72568fe2eeff7bf94a0f16c13b31d0ffbc699..1c3dc2d31def9fc85db02a1d437d5593ea1143b4 100644 (file)
@@ -133,7 +133,7 @@ class TracesControllerTest < ActionDispatch::IntegrationTest
   # Check that the index of traces is displayed
   def test_index
     user = create(:user)
-    # The fourth test below is surpisingly sensitive to timestamp ordering when the timestamps are equal.
+    # The fourth test below is surprisingly sensitive to timestamp ordering when the timestamps are equal.
     trace_a = create(:trace, :visibility => "public", :timestamp => 4.seconds.ago) do |trace|
       create(:tracetag, :trace => trace, :tag => "London")
     end
@@ -255,7 +255,7 @@ class TracesControllerTest < ActionDispatch::IntegrationTest
   # Check the RSS feed
   def test_rss
     user = create(:user)
-    # The fourth test below is surpisingly sensitive to timestamp ordering when the timestamps are equal.
+    # The fourth test below is surprisingly sensitive to timestamp ordering when the timestamps are equal.
     trace_a = create(:trace, :visibility => "public", :timestamp => 4.seconds.ago) do |trace|
       create(:tracetag, :trace => trace, :tag => "London")
     end
index d90d5efa9787d6cf99cdf560d929faa3b02e3dcc..0eac9253db7db8bfab941a5d4144874d18098b9f 100644 (file)
@@ -12,6 +12,6 @@ class UTF8Test < ActiveSupport::TestCase
     assert_not UTF8.valid?("\xC2\xC2")     # 2-byte multibyte identifier, followed by another one
     assert_not UTF8.valid?("\x4a\x82")     # plain ASCII, followed by multibyte continuation
     assert_not UTF8.valid?("\x82\x82")     # multibyte continuations without multibyte identifier
-    assert_not UTF8.valid?("\xe1\x82\x4a") # three-byte identifier, contination and (incorrectly) plain ASCII
+    assert_not UTF8.valid?("\xe1\x82\x4a") # three-byte identifier, continuation and (incorrectly) plain ASCII
   end
 end
index 99a4710753a4ec4fef62eddc79c6d26d02b0bc80..d5391c6f8e2e6ad136154e5cbe02ca77482f67da 100644 (file)
@@ -51,7 +51,7 @@ class MessageTest < ActiveSupport::TestCase
                          "\xC2\xC2",     # 2-byte multibyte identifier, followed by another one
                          "\x4a\x82",     # plain ASCII, followed by multibyte continuation
                          "\x82\x82",     # multibyte continuations without multibyte identifier
-                         "\xe1\x82\x4a"] # three-byte identifier, contination and (incorrectly) plain ASCII
+                         "\xe1\x82\x4a"] # three-byte identifier, continuation and (incorrectly) plain ASCII
     invalid_sequences.each do |char|
       # create a message and save to the database
       msg = make_message(char, 1)
index 4c863272bf7d3cb92130b3b4c56486362c2f1a8f..c34b4b81fe310f092b02088ce8b321711ad45865 100644 (file)
@@ -76,7 +76,7 @@ class UserTest < ActiveSupport::TestCase
 
   def test_display_name_valid
     # Due to sanitisation in the view some of these that you might not
-    # expact are allowed
+    # expect are allowed
     # However, would they affect the xml planet dumps?
     ok = ["Name", "'me", "he\"", "<hr>", "*ho", "\"help\"@",
           "vergrößern", "ルシステムにも対応します", "輕觸搖晃的遊戲", "space space"]
index 505fa256876b2a9000965d59fda9923b67f6580d..6c8a798aac1d4106b6ac29dec0957c216d7323d6 100644 (file)
@@ -195,7 +195,7 @@ module ActiveSupport
 
     ##
     # Used to check that the error header and the forbidden responses are given
-    # when the owner of the changset has their data not marked as public
+    # when the owner of the changeset has their data not marked as public
     def assert_require_public_data(msg = "Shouldn't be able to use API when the user's data is not public")
       assert_response :forbidden, msg
       assert_equal("You must make your edits public to upload new data", @response.headers["Error"], "Wrong error message")
index 9e26ca931f96a3754addfd9be561a58451c90556..f92004bcba13130564957cddc9f0ad1ae70d4750 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -565,11 +565,6 @@ js-yaml@^3.13.1:
     argparse "^1.0.7"
     esprima "^4.0.0"
 
-jshashes@~1.0.8:
-  version "1.0.8"
-  resolved "https://registry.yarnpkg.com/jshashes/-/jshashes-1.0.8.tgz#f60d837428383abf73ab022e1542e6614bd75514"
-  integrity sha512-btmQZ/w1rj8Lb6nEwvhjM7nBYoj54yaEFo2PWh3RkxZ8qNwuvOxvQYN/JxVuwoMmdIluL+XwYVJ+pEEZoSYybQ==
-
 json-schema-traverse@^0.4.1:
   version "0.4.1"
   resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660"
@@ -640,13 +635,6 @@ object-inspect@^1.9.0:
   resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.9.0.tgz#c90521d74e1127b67266ded3394ad6116986533a"
   integrity sha512-i3Bp9iTqwhaLZBxGkRfo5ZbE07BQRT7MGu8+nNgwW9ItGp1TzCTw2DLEoWwjClxBjOFI/hWljTAmYGCEwmtnOw==
 
-ohauth@^1.0.0:
-  version "1.0.1"
-  resolved "https://registry.yarnpkg.com/ohauth/-/ohauth-1.0.1.tgz#a5d4ab8e5390bb1cad68a58cc9c58630173c02f2"
-  integrity sha512-R9ZUN3+FVCwzeOOHCJpzA9jw/byRxp5O9X06mTL6Sp/LIQn/rLrMv6cwYctX+hoIKzRUsalGJXZ1kG5wBmSskQ==
-  dependencies:
-    jshashes "~1.0.8"
-
 once@^1.3.0:
   version "1.4.0"
   resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"