A platform for community discussion. Free, open, simple.
FIX: CreateThread allows thread creation in closed/read-only/archived channels (#37661)
Joffrey JAFFEUX0c8f52f420ab
diff --git a/plugins/chat/app/services/chat/create_thread.rb b/plugins/chat/app/services/chat/create_thread.rbindex 889a9a71482..ca39ff8cbca 100644--- a/plugins/chat/app/services/chat/create_thread.rb+++ b/plugins/chat/app/services/chat/create_thread.rb@@ -28,6 +28,7 @@ module Chatmodel :channelpolicy :can_view_channel+ policy :can_create_thread_in_channelpolicy :threading_enabled_for_channelmodel :original_message@@ -49,6 +50,10 @@ module Chatguardian.can_preview_chat_channel?(channel)end+ def can_create_thread_in_channel(guardian:, channel:)+ guardian.can_create_channel_message?(channel)+ end+def threading_enabled_for_channel(channel:)channel.threading_enabled?enddiff --git a/plugins/chat/spec/services/chat/create_thread_spec.rb b/plugins/chat/spec/services/chat/create_thread_spec.rbindex dd7d1e58876..345006265fa 100644--- a/plugins/chat/spec/services/chat/create_thread_spec.rb+++ b/plugins/chat/spec/services/chat/create_thread_spec.rb@@ -106,6 +106,32 @@ RSpec.describe Chat::CreateThread doit { is_expected.to fail_a_policy(:can_view_channel) }end+ context "when channel is not open" do+ context "when channel is read_only" do+ before { channel_1.update!(status: :read_only) }++ it { is_expected.to fail_a_policy(:can_create_thread_in_channel) }+ end++ context "when channel is closed" do+ before { channel_1.update!(status: :closed) }++ it { is_expected.to fail_a_policy(:can_create_thread_in_channel) }++ context "when user is staff" do+ let(:guardian) { Guardian.new(Fabricate(:admin)) }++ it { is_expected.to run_successfully }+ end+ end++ context "when channel is archived" do+ before { channel_1.update!(status: :archived) }++ it { is_expected.to fail_a_policy(:can_create_thread_in_channel) }+ end+ end+context "when threading is not enabled for the channel" dobefore { channel_1.update!(threading_enabled: false) }