fix: allow staff and `direct message enabled groups` to create personal chats

This commit is contained in:
pangbo13 2024-04-17 13:20:21 +08:00 committed by Régis Hanol
parent 8ff1efa100
commit 98f7430480
2 changed files with 16 additions and 1 deletions

View File

@ -5,7 +5,7 @@ module Chat
attributes :can_chat, :has_chat_enabled
def can_chat
SiteSetting.chat_enabled && object.guardian.can_chat? && object.guardian.can_direct_message?
SiteSetting.chat_enabled && object.guardian.can_chat? && scope.can_create_direct_message?
end
def has_chat_enabled

View File

@ -54,4 +54,19 @@ RSpec.describe Chat::ChatableUserSerializer do
expect(serializer.as_json[:can_chat]).to eq(false)
end
end
context "when staff creates direct messages" do
let(:admin) { Fabricate(:admin) }
subject(:serializer) { described_class.new(user, scope: Guardian.new(admin), root: false) }
before { SiteSetting.direct_message_enabled_groups = Group::AUTO_GROUPS[:trust_level_4] }
it "can chat" do
expect(serializer.as_json[:can_chat]).to eq(true)
end
it "can't chat if user has chat disabled" do
user.user_option.update!(chat_enabled: false)
expect(serializer.as_json[:has_chat_enabled]).to eq(false)
end
end
end