mirror of
https://github.com/discourse/discourse.git
synced 2025-06-07 09:48:45 +08:00
FIX: dont allow channel non-members to write messages in threads (#31697)
Prevents channel non-members from seeing the composer in threads. Since they do not have the correct permissions to post within the channel, we should show the join channel CTA in place of the chat composer.
This commit is contained in:
@ -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") {
|
||||
@ -581,6 +587,9 @@ export default class ChatThread extends Component {
|
||||
@pane={{this.chatThreadPane}}
|
||||
@messagesManager={{this.messagesManager}}
|
||||
/>
|
||||
{{else}}
|
||||
{{#if this.showChannelPreview}}
|
||||
<ChatChannelPreviewCard @channel={{@thread.channel}} />
|
||||
{{else}}
|
||||
<ChatComposerThread
|
||||
@channel={{@channel}}
|
||||
@ -590,6 +599,7 @@ export default class ChatThread extends Component {
|
||||
@scroller={{this.scroller}}
|
||||
/>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
|
||||
<ChatUploadDropZone @model={{@thread}} />
|
||||
<ChatThreadTitlePrompt @thread={{@thread}} />
|
||||
|
@ -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;
|
||||
|
@ -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 }
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user