Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugins/chat/config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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."
Expand Down
6 changes: 4 additions & 2 deletions plugins/chat/config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions plugins/chat/lib/chat/guardian_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def can_moderate_chat?(chatable)

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?
Expand Down Expand Up @@ -140,8 +140,6 @@ def can_post_in_chatable?(chatable, post_allowed_category_ids: nil)

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

Expand Down
3 changes: 2 additions & 1 deletion plugins/chat/spec/lib/chat/guardian_extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -324,6 +324,7 @@

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
Expand Down