Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: allow staff and direct message enabled groups to create personal chats #26655

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -5,7 +5,7 @@ class ChatableUserSerializer < UserWithCustomFieldsSerializer
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
Expand Down
16 changes: 16 additions & 0 deletions plugins/chat/spec/serializer/chat/chatable_user_serializer_spec.rb
Expand Up @@ -54,4 +54,20 @@
expect(serializer.as_json[:can_chat]).to eq(false)
end
end

context "when staff creates direct messages" do
fab!(: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