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:
Joffrey JAFFEUX 2023-10-16 17:43:39 +02:00 committed by GitHub
parent 1400d4a8fd
commit d1ef6ab99f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 1 deletions

View File

@ -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

View File

@ -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 "doesnt 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