Skip to content

A platform for community discussion. Free, open, simple.

FIX: dont allow channel non-members to write messages in threads (#31697)

David Battersby914543dbb9e8
diff --git a/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs b/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs
index 908230fa8bb..90706945c0e 100644
--- a/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs
+++ b/plugins/chat/assets/javascripts/discourse/components/chat-thread.gjs
@@ -34,6 +34,7 @@ import UserChatThreadMembership from "discourse/plugins/chat/discourse/models/us
import ChatComposerThread from "./chat/composer/thread";
import ChatScrollToBottomArrow from "./chat/scroll-to-bottom-arrow";
import ChatSelectionManager from "./chat/selection-manager";
+import ChatChannelPreviewCard from "./chat-channel-preview-card";
import Message from "./chat-message";
import ChatMessagesContainer from "./chat-messages-container";
import ChatMessagesScroller from "./chat-messages-scroller";
@@ -71,6 +72,11 @@ export default class ChatThread extends Component {
return this.args.thread.messagesManager;
}
+ get showChannelPreview() {
+ const channel = this.args.thread.channel;
+ return channel?.isCategoryChannel && !channel?.isFollowing;
+ }
+
@action
handleKeydown(event) {
if (event.key === "Escape") {
@@ -582,13 +588,17 @@ export default class ChatThread extends Component {
@messagesManager={{this.messagesManager}}
/>
{{else}}
- <ChatComposerThread
- @channel={{@channel}}
- @thread={{@thread}}
- @onSendMessage={{this.onSendMessage}}
- @uploadDropZone={{this.uploadDropZone}}
- @scroller={{this.scroller}}
- />
+ {{#if this.showChannelPreview}}
+ <ChatChannelPreviewCard @channel={{@thread.channel}} />
+ {{else}}
+ <ChatComposerThread
+ @channel={{@channel}}
+ @thread={{@thread}}
+ @onSendMessage={{this.onSendMessage}}
+ @uploadDropZone={{this.uploadDropZone}}
+ @scroller={{this.scroller}}
+ />
+ {{/if}}
{{/if}}
<ChatUploadDropZone @model={{@thread}} />
diff --git a/plugins/chat/assets/stylesheets/common/chat-channel-preview-card.scss b/plugins/chat/assets/stylesheets/common/chat-channel-preview-card.scss
index 86df4a8a8be..1b57a40e23f 100644
--- a/plugins/chat/assets/stylesheets/common/chat-channel-preview-card.scss
+++ b/plugins/chat/assets/stylesheets/common/chat-channel-preview-card.scss
@@ -1,5 +1,5 @@
.chat-channel-preview-card {
- margin: 1rem 0 2rem 0;
+ margin: 1rem 0 0 0;
padding: 1.5rem 1rem;
background-color: var(--secondary-very-high);
display: flex;
diff --git a/plugins/chat/spec/system/message_errors_spec.rb b/plugins/chat/spec/system/message_errors_spec.rb
index 5d751cbc52e..65536ad0f4f 100644
--- a/plugins/chat/spec/system/message_errors_spec.rb
+++ b/plugins/chat/spec/system/message_errors_spec.rb
@@ -8,19 +8,17 @@ RSpec.describe "Message errors", type: :system do
let(:message) { "atoolongmessage" + "a" * max_length }
fab!(:current_user) { Fabricate(:admin) }
+ fab!(:channel) { Fabricate(:chat_channel, threading_enabled: true) }
before do
chat_system_bootstrap
sign_in(current_user)
+ channel.add(current_user)
end
context "when in channel" do
- fab!(:channel) { Fabricate(:chat_channel) }
-
let(:channel_page) { PageObjects::Pages::ChatChannel.new }
- before { channel.add(current_user) }
-
it "shows a dialog with the error and keeps the message in the input" do
chat_page.visit_channel(channel)
@@ -34,7 +32,7 @@ RSpec.describe "Message errors", type: :system do
end
context "when in thread" do
- fab!(:thread) { Fabricate(:chat_thread) }
+ fab!(:thread) { Fabricate(:chat_thread, channel: channel) }
let(:thread_page) { PageObjects::Pages::ChatThread.new }
diff --git a/plugins/chat/spec/system/visit_channel_spec.rb b/plugins/chat/spec/system/visit_channel_spec.rb
index 91985b1e7eb..60473df03ac 100644
--- a/plugins/chat/spec/system/visit_channel_spec.rb
+++ b/plugins/chat/spec/system/visit_channel_spec.rb
@@ -136,6 +136,28 @@ RSpec.describe "Visit channel", type: :system do
expect(page).to have_content(category_channel_1.name)
expect(channel_page.messages).to have_message(id: message_1.id)
end
+
+ context "with a thread" do
+ fab!(:thread) do
+ Fabricate(
+ :chat_thread,
+ channel: category_channel_1,
+ original_message: message_1,
+ with_replies: 1,
+ )
+ end
+
+ before { category_channel_1.update(threading_enabled: true) }
+
+ it "allows to join it" do
+ chat.visit_thread(thread)
+
+ expect(page).to have_content(
+ I18n.t("js.chat.channel_settings.join_channel"),
+ count: 2,
+ )
+ end
+ end
end
context "when direct message channel" do