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: hide chat btn from user card when chat disabled #26237

Merged
merged 3 commits into from Mar 20, 2024
Merged
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
7 changes: 4 additions & 3 deletions plugins/chat/plugin.rb
Expand Up @@ -147,9 +147,10 @@ module ::Chat

add_to_serializer(:user_card, :can_chat_user) do
return false if !SiteSetting.chat_enabled
return false if scope.user.blank?
return false if scope.user.blank? || scope.user.id == object.id
return false if !scope.user.user_option.chat_enabled || !object.user_option.chat_enabled

scope.user.id != object.id && scope.can_chat? && Guardian.new(object).can_chat?
scope.can_direct_message? && Guardian.new(object).can_chat?
end

add_to_serializer(
Expand All @@ -166,7 +167,7 @@ module ::Chat
:can_direct_message,
include_condition: -> do
return @can_direct_message if defined?(@can_direct_message)
@can_direct_message = SiteSetting.chat_enabled && scope.can_direct_message?
@can_direct_message = include_has_chat_enabled? && scope.can_direct_message?
end,
) { true }

Expand Down
29 changes: 29 additions & 0 deletions plugins/chat/spec/plugin_spec.rb
Expand Up @@ -82,6 +82,7 @@

it "returns true if the target user and the guardian user is in the Chat.allowed_group_ids" do
SiteSetting.chat_allowed_groups = group.id
SiteSetting.direct_message_enabled_groups = group.id
GroupUser.create(user: target_user, group: group)
GroupUser.create(user: user, group: group)
expect(serializer.can_chat_user).to eq(true)
Expand Down Expand Up @@ -114,6 +115,34 @@
expect(serializer.can_chat_user).to eq(false)
end
end

context "when both users are in Chat.allowed_group_ids" do
before do
SiteSetting.chat_allowed_groups = group.id
SiteSetting.direct_message_enabled_groups = group.id
GroupUser.create(user: target_user, group: group)
GroupUser.create(user: user, group: group)
end

it "returns true when both users are valid" do
expect(serializer.can_chat_user).to eq(true)
end

it "returns false if current user has chat disabled" do
user.user_option.update!(chat_enabled: false)
expect(serializer.can_chat_user).to eq(false)
end

it "returns false if target user has chat disabled" do
target_user.user_option.update!(chat_enabled: false)
expect(serializer.can_chat_user).to eq(false)
end

it "returns false if user is not in dm allowed group" do
SiteSetting.direct_message_enabled_groups = 3
expect(serializer.can_chat_user).to eq(false)
end
end
end

context "when chat not enabled" do
Expand Down