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

For both `chat_allowed_groups` and `chat_message_flag_allowed_groups`,
this commit removes the `is_staff?` guardian check, and instead
adds both `moderators` and `admins` auto groups as `mandatory_values`
to those settings, as part of an ongoing effort to do this for
group-based setting values.
This commit is contained in:
Martin Brennan
2024-05-13 14:38:26 +10:00
committed by GitHub
parent df75923f2b
commit 10b2715cb3
4 changed files with 9 additions and 8 deletions

View File

@ -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."

View File

@ -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

View File

@ -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

View File

@ -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