FIX: Hide message button for current user if can't message (#27672)

Hide message button for current user if can't message
This commit is contained in:
Jan Cernik 2024-07-01 21:01:58 -03:00 committed by GitHub
parent 0acd6bea4c
commit 7b94cfcb1e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 3 deletions

View File

@ -147,7 +147,7 @@ class UserCardSerializer < BasicUserSerializer
end
def can_send_private_message_to_user
scope.can_send_private_message?(object) || scope.current_user == object
scope.can_send_private_message?(object)
end
def include_suspend_reason?

View File

@ -66,8 +66,20 @@ RSpec.describe UserCardSerializer do
expect(json[:pending_posts_count]).to eq 0
end
it "can_send_private_message_to_user is true" do
expect(json[:can_send_private_message_to_user]).to eq true
context "when the user is in a group with PMs enabled" do
before { SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:everyone] }
it "can_send_private_message_to_user is true" do
expect(json[:can_send_private_message_to_user]).to eq true
end
end
context "when the user is not in a group with PMs enabled" do
before { SiteSetting.personal_message_enabled_groups = Group::AUTO_GROUPS[:moderators] }
it "can_send_private_message_to_user is false" do
expect(json[:can_send_private_message_to_user]).to eq false
end
end
end
end