FIX: status was clearing after editing user preferences (#18887)

The problem was reported as a problem with changing theme in user preferences, after saving a new theme the previously set user status was disappearing (https://meta.discourse.org/t/user-status/240335/42). Turned out though that the problem was more wide, changing pretty much any setting in user preferences apart from user status itself led to clearing the status.
This commit is contained in:
Andrei Prigorshnev 2022-11-16 21:42:56 +04:00 committed by GitHub
parent cf51a4ea84
commit ce7172bc9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 1 deletions

View File

@ -1966,6 +1966,7 @@ class UsersController < ApplicationController
end end
if SiteSetting.enable_user_status if SiteSetting.enable_user_status
permitted << :status
permitted << { status: [:emoji, :description, :ends_at] } permitted << { status: [:emoji, :description, :ends_at] }
end end

View File

@ -216,7 +216,7 @@ class UserUpdater
end end
if SiteSetting.enable_user_status? if SiteSetting.enable_user_status?
update_user_status(attributes[:status]) update_user_status(attributes[:status]) if attributes.has_key?(:status)
end end
name_changed = user.name_changed? name_changed = user.name_changed?

View File

@ -2578,6 +2578,25 @@ RSpec.describe UsersController do
expect(user1.user_status).not_to be_nil expect(user1.user_status).not_to be_nil
end end
it "doesn't clear user status if it wasn't sent in the payload" do
new_status = {
emoji: "off to dentist",
description: "tooth",
}
user.set_status!(new_status[:description], new_status[:emoji])
user.reload
put "/u/#{user.username}.json", params: {
bio_raw: "new bio"
}
expect(response.status).to eq(200)
user.reload
expect(user.user_status).not_to be_nil
expect(user.user_status.emoji).to eq(new_status[:emoji])
expect(user.user_status.description).to eq(new_status[:description])
end
context 'when user status is disabled' do context 'when user status is disabled' do
before do before do
SiteSetting.enable_user_status = false SiteSetting.enable_user_status = false