]> git.openstreetmap.org Git - rails.git/commitdiff
Remove code complexity around resetting language preferences
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 14 Jul 2021 11:43:54 +0000 (12:43 +0100)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 14 Jul 2021 16:40:20 +0000 (17:40 +0100)
This was originally introduced since we saved the user and showed
the result on the same action. Now that the preferences controller
saves and redirects, the user model and associated language preferences
are reloaded between requests, and this code is no longer required.

app/controllers/application_controller.rb
app/models/user.rb

index fc8b75b60144ec40e2bf2a851ae7fcdce8c171da..2083627f56da30349b6b85eb679dca4d543e45d0 100644 (file)
@@ -173,8 +173,7 @@ class ApplicationController < ActionController::Base
     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
@@ -186,13 +185,13 @@ class ApplicationController < ActionController::Base
 
   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
index 964359e9cd4cec972f596f08eec1b45c71de3fe2..4b471f60d8ce8155544617c76478a43218ee2840 100644 (file)
@@ -118,7 +118,6 @@ class User < ApplicationRecord
   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 @@ class User < ApplicationRecord
     @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)