FIX: Updating a user profile as admin shouldn't change the user's locale

This commit is contained in:
Gerhard Schlager 2019-06-07 17:51:58 +02:00
parent 2dce650b72
commit bae7b75e23
2 changed files with 15 additions and 6 deletions

@ -352,6 +352,8 @@ class UsersController < ApplicationController
return fail_with("login.reserved_username")
end
params[:locale] ||= I18n.locale unless current_user
new_user_params = user_params
user = User.unstage(new_user_params)
user = User.new(new_user_params) if user.nil?
@ -1259,8 +1261,7 @@ class UsersController < ApplicationController
.permit(permitted, theme_ids: [])
.reverse_merge(
ip_address: request.remote_ip,
registration_ip_address: request.remote_ip,
locale: user_locale
registration_ip_address: request.remote_ip
)
if !UsernameCheckerService.is_developer?(result['email']) &&
@ -1279,10 +1280,6 @@ class UsersController < ApplicationController
attrs
end
def user_locale
I18n.locale
end
def fail_with(key)
render json: { success: false, message: I18n.t(key) }
end

@ -738,6 +738,18 @@ describe UsersController do
expect(response.status).to eq(200)
expect(JSON.parse(response.body)['active']).to be_falsy
end
it "won't set the new user's locale to the admin's locale" do
SiteSetting.allow_user_locale = true
admin.update!(locale: :fr)
post "/u.json", params: post_user_params.merge(active: true, api_key: api_key.key)
expect(response.status).to eq(200)
json = JSON.parse(response.body)
new_user = User.find(json["user_id"])
expect(new_user.locale).not_to eq("fr")
end
end
end