FIX: do not serialize status when profile is hidden (#23946)
Users can decide to hide their profile and presence. It seems more correct to also not return the status in this case. Co-authored-by: Penar Musaraj <pmusaraj@gmail.com>
This commit is contained in:
parent
1400d4a8fd
commit
d1ef6ab99f
|
@ -5,7 +5,13 @@ module Chat
|
|||
attributes :status
|
||||
|
||||
def include_status?
|
||||
SiteSetting.enable_user_status && user.has_status?
|
||||
predicate = SiteSetting.enable_user_status && user.has_status?
|
||||
|
||||
if user.association(:user_option).loaded?
|
||||
predicate = predicate && !user.user_option.hide_profile_and_presence
|
||||
end
|
||||
|
||||
predicate
|
||||
end
|
||||
|
||||
def status
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
describe Chat::ChatablesSerializer do
|
||||
context "with status" do
|
||||
fab!(:user_1) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
SiteSetting.enable_user_status = true
|
||||
user_1.set_status!("test", ":cat:")
|
||||
end
|
||||
|
||||
it "includes status" do
|
||||
serializer =
|
||||
described_class.new(
|
||||
OpenStruct.new({ users: [user_1] }),
|
||||
scope: Guardian.new(Fabricate(:user)),
|
||||
root: false,
|
||||
)
|
||||
|
||||
expect(serializer.users[0]["model"][:status]).to be_present
|
||||
end
|
||||
|
||||
context "with hidden profile" do
|
||||
before { user_1.user_option.update!(hide_profile_and_presence: true) }
|
||||
|
||||
it "doesn’t include status" do
|
||||
serializer =
|
||||
described_class.new(
|
||||
OpenStruct.new({ users: [user_1] }),
|
||||
scope: Guardian.new(Fabricate(:user)),
|
||||
root: false,
|
||||
)
|
||||
|
||||
expect(serializer.users[0]["model"][:status]).to be_blank
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue