From: Tom Hughes Date: Wed, 21 Jul 2021 18:24:31 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/pull/3257' X-Git-Tag: live~2056 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/f1935b1c5786de8f27bee9b6b2da2f28f650468f?hp=-c Merge remote-tracking branch 'upstream/pull/3257' --- f1935b1c5786de8f27bee9b6b2da2f28f650468f diff --combined app/controllers/application_controller.rb index 2a1c3d675,2083627f5..0884964ed --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@@ -17,6 -17,7 +17,6 @@@ class ApplicationController < ActionCon helper_method :current_user helper_method :oauth_token - helper_method :preferred_langauges private @@@ -66,7 -67,7 +66,7 @@@ 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 ## @@@ -172,8 -173,7 +172,7 @@@ end end - def preferred_languages(reset: false) - @preferred_languages = nil if reset + def preferred_languages @preferred_languages ||= if params[:locale] Locale.list(params[:locale]) elsif current_user @@@ -185,13 -185,13 +184,13 @@@ helper_method :preferred_languages - def set_locale(reset: false) + def set_locale if current_user&.languages&.empty? && !http_accept_language.user_preferred_languages.empty? current_user.languages = http_accept_language.user_preferred_languages current_user.save end - I18n.locale = Locale.available.preferred(preferred_languages(:reset => reset)) + I18n.locale = Locale.available.preferred(preferred_languages) response.headers["Vary"] = "Accept-Language" response.headers["Content-Language"] = I18n.locale.to_s diff --combined app/models/user.rb index cca894a6b,4b471f60d..8b8f31676 --- a/app/models/user.rb +++ b/app/models/user.rb @@@ -68,7 -68,7 +68,7 @@@ class User < ApplicationRecor 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 @@@ -118,7 -118,6 +118,6 @@@ before_save :encrypt_password before_save :update_tile after_save :spam_check - after_save :reset_preferred_languages def to_param display_name @@@ -179,10 -178,6 +178,6 @@@ @preferred_languages ||= Locale.list(languages) end - def reset_preferred_languages - @preferred_languages = nil - end - def nearby(radius = Settings.nearby_radius, num = Settings.nearby_users) if home_lon && home_lat gc = OSM::GreatCircle.new(home_lat, home_lon) @@@ -288,23 -283,11 +283,23 @@@ end ## - # return an oauth access token for a specified application + # return an oauth 1 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) diff --combined app/views/users/show.html.erb index dac0ff5b5,3974a2f9c..ac6938af7 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@@ -4,7 -4,7 +4,7 @@@

<%= @user.display_name %> <%= role_icons(@user) %>

<% if current_user and @user.id == current_user.id %> - +
<% if current_user and current_user.administrator? -%> diff --combined config/locales/en.yml index fce1f8913,fcfb2bc89..83b697e8c --- a/config/locales/en.yml +++ b/config/locales/en.yml @@@ -152,7 -152,7 +152,7 @@@ en trace: tagstring: comma delimited user_block: - reason: The reason why the user is being blocked. Please be as calm and as reasonable as possible, giving as much detail as you can about the situation, remembering that the message will be publicly visible. Bear in mind that not all users understand the community jargon, so please try to use laymans terms. + reason: The reason why the user is being blocked. Please be as calm and as reasonable as possible, giving as much detail as you can about the situation, remembering that the message will be publicly visible. Bear in mind that not all users understand the community jargon, so please try to use layman's terms. needs_view: Does the user need to log in before this block will be cleared? user: email_confirmation: 'Your address is not displayed publicly, see our privacy policy for more information.' @@@ -697,7 -697,7 +697,7 @@@ houseboat: "Houseboat" hut: "Hut" industrial: "Industrial Building" - kindergarten: "Kindergarden Building" + kindergarten: "Kindergarten Building" manufacture: "Manufacturing Building" office: "Office Building" public: "Public Building" @@@ -722,7 -722,7 +722,7 @@@ sport: "Sportsclub" "yes": "Club" craft: - beekeper: "Beekeeper" + beekeeper: "Beekeeper" blacksmith: "Blacksmith" brewery: "Brewery" carpenter: "Carpenter" @@@ -752,7 -752,7 +752,7 @@@ ambulance_station: "Ambulance Station" assembly_point: "Assembly Point" defibrillator: "Defibrillator" - fire_xtinguisher: "Fire Extinguisher" + fire_extinguisher: "Fire Extinguisher" fire_water_pond: "Fire Water Pond" landing_site: "Emergency Landing Site" life_ring: "Emergency Life Ring" @@@ -837,7 -837,6 +837,7 @@@ railway: "Historic Railway" roman_road: "Roman Road" ruins: "Ruins" + rune_stone: "Rune Stone" stone: "Stone" tomb: "Tomb" tower: "Tower" @@@ -1645,6 -1644,43 +1645,43 @@@ reset: "Reset Password" flash changed: "Your password has been changed." flash token bad: "Did not find that token, check the URL maybe?" + preferences: + show: + title: My Preferences + preferred_editor: Preferred Editor + preferred_languages: Preferred Languages + edit_preferences: Edit Preferences + edit: + title: Edit Preferences + save: Update Preferences + cancel: Cancel + update: + failure: Couldn't update preferences. + update_success_flash: + message: Preferences updated. + profiles: + edit: + title: Edit Profile + save: Update Profile + cancel: Cancel + image: Image + gravatar: + gravatar: "Use Gravatar" + link: "https://wiki.openstreetmap.org/wiki/Gravatar" + what_is_gravatar: "What is Gravatar?" + disabled: "Gravatar has been disabled." + enabled: "Display of your Gravatar has been enabled." + new image: "Add an image" + keep image: "Keep the current image" + delete image: "Remove the current image" + replace image: "Replace the current image" + image size hint: "(square images at least 100x100 work best)" + home location: "Home Location" + no home location: "You have not entered your home location." + update home location on click: "Update home location when I click on the map?" + update: + success: Profile updated. + failure: Couldn't update profile. sessions: new: title: "Login" @@@ -2446,8 -2482,10 +2483,10 @@@ my profile: My Profile my settings: My Settings my comments: My Comments + my_preferences: My Preferences blocks on me: Blocks on Me blocks by me: Blocks by Me + edit_profile: Edit Profile send message: Send Message diary: Diary edits: Edits @@@ -2529,21 -2567,6 +2568,6 @@@ agreed_with_pd: "You have also declared that you consider your edits to be in the Public Domain." link: "https://www.osmfoundation.org/wiki/License/Contributor_Terms" link text: "what is this?" - image: Image - gravatar: - gravatar: "Use Gravatar" - link: "https://wiki.openstreetmap.org/wiki/Gravatar" - what_is_gravatar: "What is Gravatar?" - disabled: "Gravatar has been disabled." - enabled: "Display of your Gravatar has been enabled." - new image: "Add an image" - keep image: "Keep the current image" - delete image: "Remove the current image" - replace image: "Replace the current image" - image size hint: "(square images at least 100x100 work best)" - home location: "Home Location" - no home location: "You have not entered your home location." - update home location on click: "Update home location when I click on the map?" save changes button: Save Changes make edits public button: Make all my edits public return to profile: Return to profile