A platform for community discussion. Free, open, simple.
DEV: adds a `chat_can_create_direct_message_channel` modifier (#25840)
Joffrey JAFFEUX77028e3675c4
diff --git a/plugins/chat/app/services/chat/create_direct_message_channel.rb b/plugins/chat/app/services/chat/create_direct_message_channel.rbindex d211904067b..d99fd0cb996 100644--- a/plugins/chat/app/services/chat/create_direct_message_channel.rb+++ b/plugins/chat/app/services/chat/create_direct_message_channel.rb@@ -22,9 +22,9 @@ module Chat# @option params_to_create [Array<String>] target_groups# @return [Service::Base::Context]- policy :can_create_direct_messagecontractmodel :target_users+ policy :can_create_direct_messagepolicy :satisfies_dms_max_users_limit,class_name: Chat::DirectMessageChannel::MaxUsersExcessPolicymodel :user_comm_screener@@ -53,8 +53,13 @@ module Chatprivate- def can_create_direct_message(guardian:, **)- guardian.can_create_direct_message?+ def can_create_direct_message(guardian:, target_users:, **)+ guardian.can_create_direct_message? &&+ DiscoursePluginRegistry.apply_modifier(+ :chat_can_create_direct_message_channel,+ guardian.user,+ target_users,+ )enddef fetch_target_users(guardian:, contract:, **)diff --git a/plugins/chat/spec/services/chat/create_direct_message_channel_spec.rb b/plugins/chat/spec/services/chat/create_direct_message_channel_spec.rbindex eb8f2d35c1a..f41a8bb25d1 100644--- a/plugins/chat/spec/services/chat/create_direct_message_channel_spec.rb+++ b/plugins/chat/spec/services/chat/create_direct_message_channel_spec.rb@@ -178,6 +178,22 @@ RSpec.describe Chat::CreateDirectMessageChannel doit { is_expected.to fail_a_policy(:can_create_direct_message) }end+ context "when the plugin modifier returns false" do+ it "fails a policy" do+ modifier_block = Proc.new { false }+ plugin_instance = Plugin::Instance.new+ plugin_instance.register_modifier(:chat_can_create_direct_message_channel, &modifier_block)++ expect(result).to fail_a_policy(:can_create_direct_message)+ ensure+ DiscoursePluginRegistry.unregister_modifier(+ plugin_instance,+ :chat_can_create_direct_message_channel,+ &modifier_block+ )+ end+ end+context "when the actor is not allowing anyone to message them" dobefore { current_user.user_option.update!(allow_private_messages: false) }