mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 07:31:02 +08:00
FIX: current user serializer consistently returns {} for custom_fields
Resolves: #5210
This commit is contained in:
@ -135,7 +135,7 @@ class CurrentUserSerializer < BasicUserSerializer
|
|||||||
end
|
end
|
||||||
|
|
||||||
if fields.present?
|
if fields.present?
|
||||||
User.custom_fields_for_ids([object.id], fields)[object.id]
|
User.custom_fields_for_ids([object.id], fields)[object.id] || {}
|
||||||
else
|
else
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
|
@ -388,7 +388,7 @@ class UserSerializer < BasicUserSerializer
|
|||||||
end
|
end
|
||||||
|
|
||||||
if fields.present?
|
if fields.present?
|
||||||
User.custom_fields_for_ids([object.id], fields)[object.id]
|
User.custom_fields_for_ids([object.id], fields)[object.id] || {}
|
||||||
else
|
else
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
|
@ -149,6 +149,14 @@ describe Plugin::Instance do
|
|||||||
end
|
end
|
||||||
|
|
||||||
context "serialized_current_user_fields" do
|
context "serialized_current_user_fields" do
|
||||||
|
before do
|
||||||
|
DiscoursePluginRegistry.serialized_current_user_fields << "has_car"
|
||||||
|
end
|
||||||
|
|
||||||
|
after do
|
||||||
|
DiscoursePluginRegistry.serialized_current_user_fields.delete "has_car"
|
||||||
|
end
|
||||||
|
|
||||||
it "correctly serializes custom user fields" do
|
it "correctly serializes custom user fields" do
|
||||||
DiscoursePluginRegistry.serialized_current_user_fields << "has_car"
|
DiscoursePluginRegistry.serialized_current_user_fields << "has_car"
|
||||||
user = Fabricate(:user)
|
user = Fabricate(:user)
|
||||||
@ -157,6 +165,18 @@ describe Plugin::Instance do
|
|||||||
|
|
||||||
payload = JSON.parse(CurrentUserSerializer.new(user, scope: Guardian.new(user)).to_json)
|
payload = JSON.parse(CurrentUserSerializer.new(user, scope: Guardian.new(user)).to_json)
|
||||||
expect(payload["current_user"]["custom_fields"]["has_car"]).to eq("true")
|
expect(payload["current_user"]["custom_fields"]["has_car"]).to eq("true")
|
||||||
|
|
||||||
|
payload = JSON.parse(UserSerializer.new(user, scope: Guardian.new(user)).to_json)
|
||||||
|
expect(payload["user"]["custom_fields"]["has_car"]).to eq("true")
|
||||||
|
|
||||||
|
UserCustomField.destroy_all
|
||||||
|
user.reload
|
||||||
|
|
||||||
|
payload = JSON.parse(CurrentUserSerializer.new(user, scope: Guardian.new(user)).to_json)
|
||||||
|
expect(payload["current_user"]["custom_fields"]).to eq({})
|
||||||
|
|
||||||
|
payload = JSON.parse(UserSerializer.new(user, scope: Guardian.new(user)).to_json)
|
||||||
|
expect(payload["user"]["custom_fields"]).to eq({})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user