FEATURE: Log topic slow mode changes (#27934)

Previously, we did not log any topic slow mode changes. This allowed
some malicious (or just careless) TL4 users to delete slow modes created
by moderators at will. Administrators could not see who changed the slow
mode unless they had SQL knowledge and used Data Explorer.

This commit enables logging who turns slow mode on, off, or changes it.

Related meta topic: https://meta.discourse.org/t/why-is-there-no-record-of-who-added-or-removed-slow-mode/316354
This commit is contained in:
锦心
2024-07-16 17:08:09 +08:00
committed by GitHub
parent 3bc459e178
commit 600f2854c7
5 changed files with 48 additions and 0 deletions

View File

@@ -1186,6 +1186,13 @@ class TopicsController < ApplicationController
topic.set_or_create_timer(slow_mode_type, time, by_user: timer&.user)
StaffActionLogger.new(current_user).log_topic_slow_mode(
topic,
enabled:,
seconds: params[:seconds],
until: time,
)
head :ok
end

View File

@@ -146,6 +146,8 @@ class UserHistory < ActiveRecord::Base
delete_watched_word_group: 107,
redirected_to_required_fields: 108,
filled_in_required_fields: 109,
topic_slow_mode_set: 110,
topic_slow_mode_removed: 111,
)
end
@@ -254,6 +256,8 @@ class UserHistory < ActiveRecord::Base
create_watched_word_group
update_watched_word_group
delete_watched_word_group
topic_slow_mode_set
topic_slow_mode_removed
]
end

View File

@@ -204,6 +204,21 @@ class StaffActionLogger
)
end
def log_topic_slow_mode(topic, opts = {})
raise Discourse::InvalidParameters.new(:topic) unless topic && topic.is_a?(Topic)
details = opts[:enabled] ? ["interval: #{opts[:seconds]}", "until: #{opts[:until]}"] : []
UserHistory.create!(
params(opts).merge(
action:
UserHistory.actions[opts[:enabled] ? :topic_slow_mode_set : :topic_slow_mode_removed],
topic_id: topic.id,
details: details.join("\n"),
),
)
end
def log_post_staff_note(post, opts = {})
raise Discourse::InvalidParameters.new(:post) unless post && post.is_a?(Post)