Skip to content

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

DEV: Use site setting mandatory_values for chat allowed groups (#26994)

Martin Brennan10b2715cb34e
diff --git a/plugins/chat/config/locales/server.en.yml b/plugins/chat/config/locales/server.en.yml
index cdf0eeed475..e828b29bc9f 100644
--- a/plugins/chat/config/locales/server.en.yml
+++ b/plugins/chat/config/locales/server.en.yml
@@ -3,7 +3,7 @@ en:
chat_separate_sidebar_mode: "Show separate sidebar modes for forum and chat."
chat_enabled: "Enable chat."
enable_public_channels: "Enable public channels based on categories."
- chat_allowed_groups: "Users in these groups can chat. Note that staff can always access chat."
+ chat_allowed_groups: "Users in these groups can chat. Note that admins and moderators can always access chat."
chat_channel_retention_days: "Chat messages in regular channels will be retained for this many days. Set to '0' to retain messages forever."
chat_dm_retention_days: "Chat messages in personal chat channels will be retained for this many days. Set to '0' to retain messages forever."
chat_auto_silence_duration: "Number of minutes that users will be silenced for when they exceed the chat message creation rate limit. Set to '0' to disable auto-silencing."
@@ -18,7 +18,7 @@ en:
chat_archive_destination_topic_status: "The status that the destination topic should be once a channel archive is completed. This only applies when the destination topic is a new topic, not an existing one."
default_emoji_reactions: "Default emoji reactions for chat messages. Add up to 5 emojis for quick reaction."
direct_message_enabled_groups: "Allow users within these groups to create user-to-user Personal Chats. Note: staff can always create Personal Chats, and users will be able to reply to Personal Chats initiated by users who have permission to create them."
- chat_message_flag_allowed_groups: "Users in these groups are allowed to flag chat messages."
+ chat_message_flag_allowed_groups: "Users in these groups are allowed to flag chat messages. Note that admins and moderators can always flag chat messages."
max_mentions_per_chat_message: "Maximum number of @name notifications a user can use in a chat message."
chat_max_direct_message_users: "Users cannot add more than this number of other users when creating a new direct message. Set to 0 to only allow messages to oneself. Staff are exempt from this setting."
chat_allow_archiving_channels: "Allow staff to archive messages to a topic when closing a channel."
diff --git a/plugins/chat/config/settings.yml b/plugins/chat/config/settings.yml
index 24aef9ebcc9..ee9f99a5311 100644
--- a/plugins/chat/config/settings.yml
+++ b/plugins/chat/config/settings.yml
@@ -8,7 +8,8 @@ chat:
chat_allowed_groups:
type: group_list
list_type: compact
- default: "3|11" # 3: @staff, 11: @trust_level_1
+ default: "1|2|11" # @admins, @moderators, @trust_level_1
+ mandatory_values: "1|2" # @admins, @moderators
allow_any: false
refresh: true
chat_threads_enabled:
@@ -104,7 +105,8 @@ chat:
refresh: true
validator: "Chat::DirectMessageEnabledGroupsValidator"
chat_message_flag_allowed_groups:
- default: "11" # @trust_level_1
+ default: "1|2|11" # @admins, @moderators, @trust_level_1
+ mandatory_values: "1|2" # @admins, @moderators
type: group_list
allow_any: false
refresh: true
diff --git a/plugins/chat/lib/chat/guardian_extensions.rb b/plugins/chat/lib/chat/guardian_extensions.rb
index d31ed8d6a1b..4fc03f8ef67 100644
--- a/plugins/chat/lib/chat/guardian_extensions.rb
+++ b/plugins/chat/lib/chat/guardian_extensions.rb
@@ -13,7 +13,7 @@ module Chat
def can_chat?
return false if anonymous?
- is_staff? || @user.bot? || @user.in_any_groups?(Chat.allowed_group_ids)
+ @user.bot? || @user.in_any_groups?(Chat.allowed_group_ids)
end
def can_direct_message?
@@ -140,8 +140,6 @@ module Chat
def can_flag_chat_messages?
return false if @user.silenced?
- return true if is_staff?
-
@user.in_any_groups?(SiteSetting.chat_message_flag_allowed_groups_map)
end
diff --git a/plugins/chat/spec/lib/chat/guardian_extensions_spec.rb b/plugins/chat/spec/lib/chat/guardian_extensions_spec.rb
index 8af2bd9ecd0..3bd12d2ae04 100644
--- a/plugins/chat/spec/lib/chat/guardian_extensions_spec.rb
+++ b/plugins/chat/spec/lib/chat/guardian_extensions_spec.rb
@@ -3,7 +3,7 @@
RSpec.describe Chat::GuardianExtensions do
fab!(:chatters) { Fabricate(:group) }
fab!(:user) { Fabricate(:user, group_ids: [chatters.id], refresh_auto_groups: true) }
- fab!(:staff) { Fabricate(:user, admin: true) }
+ fab!(:staff) { Fabricate(:admin, refresh_auto_groups: true) }
fab!(:chat_group) { Fabricate(:group) }
fab!(:channel) { Fabricate(:category_channel) }
fab!(:dm_channel) { Fabricate(:direct_message_channel) }
@@ -324,6 +324,7 @@ RSpec.describe Chat::GuardianExtensions do
describe "#can_flag_chat_message?" do
let!(:message) { Fabricate(:chat_message, chat_channel: channel) }
+
before { SiteSetting.chat_message_flag_allowed_groups = "" }
context "when user isn't staff" do