2018-01-20 00:34:54 +08:00
|
|
|
require_dependency 'staff_message_format'
|
|
|
|
|
2013-04-12 04:04:20 +08:00
|
|
|
# Responsible for logging the actions of admins and moderators.
|
2013-07-24 05:58:26 +08:00
|
|
|
class StaffActionLogger
|
2014-11-25 02:48:54 +08:00
|
|
|
|
2015-02-06 03:34:57 +08:00
|
|
|
def self.base_attrs
|
|
|
|
[:topic_id, :post_id, :context, :subject, :ip_address, :previous_value, :new_value]
|
|
|
|
end
|
|
|
|
|
2013-04-12 04:04:20 +08:00
|
|
|
def initialize(admin)
|
|
|
|
@admin = admin
|
2015-02-06 03:34:57 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:admin) unless @admin && @admin.is_a?(User)
|
2013-04-12 04:04:20 +08:00
|
|
|
end
|
|
|
|
|
2018-05-18 00:09:27 +08:00
|
|
|
USER_FIELDS ||= %i{id username name created_at trust_level last_seen_at last_emailed_at}
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_user_deletion(deleted_user, opts = {})
|
2015-02-06 03:34:57 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:deleted_user) unless deleted_user && deleted_user.is_a?(User)
|
2018-05-18 00:09:27 +08:00
|
|
|
details = USER_FIELDS.map { |x| "#{x}: #{deleted_user.send(x)}" }.join("\n")
|
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:delete_user],
|
|
|
|
ip_address: deleted_user.ip_address.to_s,
|
|
|
|
details: details
|
|
|
|
))
|
2014-10-01 23:40:13 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_custom(custom_type, details = nil)
|
2015-02-06 03:34:57 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:custom_type) unless custom_type
|
|
|
|
|
|
|
|
details ||= {}
|
|
|
|
|
|
|
|
attrs = {}
|
|
|
|
StaffActionLogger.base_attrs.each do |attr|
|
|
|
|
attrs[attr] = details.delete(attr) if details.has_key?(attr)
|
|
|
|
end
|
2017-07-28 09:20:09 +08:00
|
|
|
attrs[:details] = details.map { |r| "#{r[0]}: #{r[1]}" }.join("\n")
|
2015-02-06 03:34:57 +08:00
|
|
|
attrs[:acting_user_id] = @admin.id
|
|
|
|
attrs[:action] = UserHistory.actions[:custom_staff]
|
|
|
|
attrs[:custom_type] = custom_type
|
|
|
|
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(attrs)
|
2015-02-06 03:34:57 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_post_deletion(deleted_post, opts = {})
|
2015-02-06 03:34:57 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:deleted_post) unless deleted_post && deleted_post.is_a?(Post)
|
2014-10-01 23:40:13 +08:00
|
|
|
|
2016-04-11 11:50:08 +08:00
|
|
|
topic = deleted_post.topic || Topic.with_deleted.find_by(id: deleted_post.topic_id)
|
2014-10-01 23:40:13 +08:00
|
|
|
|
2018-06-02 11:55:41 +08:00
|
|
|
username = deleted_post.user.try(:username) || I18n.t('staff_action_logs.unknown')
|
|
|
|
name = deleted_post.user.try(:name) || I18n.t('staff_action_logs.unknown')
|
|
|
|
topic_title = topic.try(:title) || I18n.t('staff_action_logs.not_found')
|
2015-08-14 11:57:02 +08:00
|
|
|
|
2014-10-01 23:40:13 +08:00
|
|
|
details = [
|
|
|
|
"id: #{deleted_post.id}",
|
|
|
|
"created_at: #{deleted_post.created_at}",
|
2015-08-14 11:57:02 +08:00
|
|
|
"user: #{username} (#{name})",
|
2016-04-11 11:50:08 +08:00
|
|
|
"topic: #{topic_title}",
|
2014-10-01 23:40:13 +08:00
|
|
|
"post_number: #{deleted_post.post_number}",
|
|
|
|
"raw: #{deleted_post.raw}"
|
|
|
|
]
|
|
|
|
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:delete_post],
|
|
|
|
post_id: deleted_post.id,
|
|
|
|
details: details.join("\n")
|
|
|
|
))
|
2014-10-01 23:40:13 +08:00
|
|
|
end
|
|
|
|
|
2018-03-21 12:15:16 +08:00
|
|
|
def log_topic_delete_recover(topic, action = "delete_topic", opts = {})
|
|
|
|
raise Discourse::InvalidParameters.new(:topic) unless topic && topic.is_a?(Topic)
|
2014-10-01 23:40:13 +08:00
|
|
|
|
2018-03-21 12:15:16 +08:00
|
|
|
user = topic.user ? "#{topic.user.username} (#{topic.user.name})" : "(deleted user)"
|
2016-06-15 20:41:08 +08:00
|
|
|
|
2014-10-01 23:40:13 +08:00
|
|
|
details = [
|
2018-03-21 12:15:16 +08:00
|
|
|
"id: #{topic.id}",
|
|
|
|
"created_at: #{topic.created_at}",
|
2016-06-15 20:41:08 +08:00
|
|
|
"user: #{user}",
|
2018-03-21 12:15:16 +08:00
|
|
|
"title: #{topic.title}"
|
2014-10-01 23:40:13 +08:00
|
|
|
]
|
|
|
|
|
2018-03-21 12:15:16 +08:00
|
|
|
if first_post = topic.ordered_posts.with_deleted.first
|
2014-10-01 23:40:13 +08:00
|
|
|
details << "raw: #{first_post.raw}"
|
|
|
|
end
|
|
|
|
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[action.to_sym],
|
|
|
|
topic_id: topic.id,
|
|
|
|
details: details.join("\n")
|
|
|
|
))
|
2013-04-12 04:04:20 +08:00
|
|
|
end
|
2013-07-08 17:53:22 +08:00
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_trust_level_change(user, old_trust_level, new_trust_level, opts = {})
|
2015-02-06 03:34:57 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user && user.is_a?(User)
|
|
|
|
raise Discourse::InvalidParameters.new(:old_trust_level) unless TrustLevel.valid? old_trust_level
|
|
|
|
raise Discourse::InvalidParameters.new(:new_trust_level) unless TrustLevel.valid? new_trust_level
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:change_trust_level],
|
|
|
|
target_user_id: user.id,
|
|
|
|
details: "old trust level: #{old_trust_level}\nnew trust level: #{new_trust_level}"
|
|
|
|
))
|
2013-08-20 04:58:38 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_lock_trust_level(user, opts = {})
|
2017-01-11 05:45:36 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user && user.is_a?(User)
|
2018-05-18 00:09:27 +08:00
|
|
|
action = UserHistory.actions[user.manual_locked_trust_level.nil? ? :unlock_trust_level : :lock_trust_level]
|
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: action,
|
|
|
|
target_user_id: user.id
|
|
|
|
))
|
2017-01-11 05:45:36 +08:00
|
|
|
end
|
|
|
|
|
2018-03-14 03:59:12 +08:00
|
|
|
def log_topic_published(topic, opts = {})
|
|
|
|
raise Discourse::InvalidParameters.new(:topic) unless topic && topic.is_a?(Topic)
|
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:topic_published],
|
|
|
|
topic_id: topic.id)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-01-26 04:38:40 +08:00
|
|
|
def log_post_lock(post, opts = {})
|
|
|
|
raise Discourse::InvalidParameters.new(:post) unless post && post.is_a?(Post)
|
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[opts[:locked] ? :post_locked : :post_unlocked],
|
|
|
|
post_id: post.id)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2018-03-13 01:49:52 +08:00
|
|
|
def log_post_edit(post, opts = {})
|
|
|
|
raise Discourse::InvalidParameters.new(:post) unless post && post.is_a?(Post)
|
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:post_edit],
|
|
|
|
post_id: post.id,
|
2018-03-15 03:01:36 +08:00
|
|
|
details: "#{opts[:old_raw]}\n\n---\n\n#{post.raw}"
|
2018-03-13 01:49:52 +08:00
|
|
|
))
|
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_site_setting_change(setting_name, previous_value, new_value, opts = {})
|
2015-02-06 03:34:57 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:setting_name) unless setting_name.present? && SiteSetting.respond_to?(setting_name)
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:change_site_setting],
|
|
|
|
subject: setting_name,
|
|
|
|
previous_value: previous_value,
|
|
|
|
new_value: new_value
|
|
|
|
))
|
2013-08-20 04:58:38 +08:00
|
|
|
end
|
|
|
|
|
2017-04-12 22:52:52 +08:00
|
|
|
def theme_json(theme)
|
2017-07-28 09:20:09 +08:00
|
|
|
ThemeSerializer.new(theme, root: false).to_json
|
2017-04-12 22:52:52 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def strip_duplicates(old, cur)
|
|
|
|
return [old, cur] unless old && cur
|
2017-04-12 22:52:52 +08:00
|
|
|
|
|
|
|
old = JSON.parse(old)
|
|
|
|
cur = JSON.parse(cur)
|
|
|
|
|
|
|
|
old.each do |k, v|
|
|
|
|
next if k == "name"
|
|
|
|
next if k == "id"
|
|
|
|
if (v == cur[k])
|
|
|
|
cur.delete(k)
|
|
|
|
old.delete(k)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
[old.to_json, cur.to_json]
|
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_theme_change(old_json, new_theme, opts = {})
|
2017-04-12 22:52:52 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:new_theme) unless new_theme
|
|
|
|
|
|
|
|
new_json = theme_json(new_theme)
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
old_json, new_json = strip_duplicates(old_json, new_json)
|
2017-04-12 22:52:52 +08:00
|
|
|
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:change_theme],
|
|
|
|
subject: new_theme.name,
|
|
|
|
previous_value: old_json,
|
|
|
|
new_value: new_json
|
|
|
|
))
|
2013-08-22 00:03:21 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_theme_destroy(theme, opts = {})
|
2017-04-12 22:52:52 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:theme) unless theme
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:delete_theme],
|
|
|
|
subject: theme.name,
|
|
|
|
previous_value: theme_json(theme)
|
|
|
|
))
|
2013-08-21 22:49:35 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_site_text_change(subject, new_text = nil, old_text = nil, opts = {})
|
2015-12-18 21:31:04 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:subject) unless subject.present?
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:change_site_text],
|
|
|
|
subject: subject,
|
|
|
|
previous_value: old_text,
|
|
|
|
new_value: new_text
|
|
|
|
))
|
2015-12-18 21:31:04 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_username_change(user, old_username, new_username, opts = {})
|
2015-02-06 03:34:57 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:change_username],
|
|
|
|
target_user_id: user.id,
|
|
|
|
previous_value: old_username,
|
|
|
|
new_value: new_username
|
|
|
|
))
|
2015-01-17 06:30:46 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_name_change(user_id, old_name, new_name, opts = {})
|
2017-02-23 13:48:57 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user_id
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:change_name],
|
|
|
|
target_user_id: user_id,
|
|
|
|
previous_value: old_name,
|
|
|
|
new_value: new_name
|
|
|
|
))
|
2017-02-23 13:48:57 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_user_suspend(user, reason, opts = {})
|
2015-02-06 03:34:57 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
2017-11-21 01:33:02 +08:00
|
|
|
|
2018-01-20 00:34:54 +08:00
|
|
|
details = StaffMessageFormat.new(:suspend, reason, opts[:message]).format
|
2017-11-21 01:33:02 +08:00
|
|
|
|
2017-09-15 02:10:39 +08:00
|
|
|
args = params(opts).merge(
|
|
|
|
action: UserHistory.actions[:suspend_user],
|
|
|
|
target_user_id: user.id,
|
2017-11-21 01:33:02 +08:00
|
|
|
details: details
|
2017-09-15 02:10:39 +08:00
|
|
|
)
|
|
|
|
args[:post_id] = opts[:post_id] if opts[:post_id]
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(args)
|
2013-11-01 22:47:03 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_user_unsuspend(user, opts = {})
|
2015-02-06 03:34:57 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:unsuspend_user],
|
|
|
|
target_user_id: user.id
|
|
|
|
))
|
|
|
|
end
|
|
|
|
|
2018-06-08 22:48:26 +08:00
|
|
|
def log_user_merge(user, source_username, source_email, opts = {})
|
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:merge_user],
|
|
|
|
target_user_id: user.id,
|
|
|
|
context: I18n.t("staff_action_logs.user_merged", username: source_username),
|
|
|
|
email: source_email
|
|
|
|
))
|
|
|
|
end
|
|
|
|
|
2018-05-18 00:09:27 +08:00
|
|
|
BADGE_FIELDS ||= %i{id name description long_description icon image badge_type_id
|
|
|
|
badge_grouping_id query allow_title multiple_grant listable target_posts
|
|
|
|
enabled auto_revoke show_posts system}
|
|
|
|
|
|
|
|
def log_badge_creation(badge)
|
|
|
|
raise Discourse::InvalidParameters.new(:badge) unless badge
|
|
|
|
details = BADGE_FIELDS.map { |f| [f, badge.send(f)] }.select { |f, v| v.present? }.map { |f, v| "#{f}: #{v}" }
|
|
|
|
UserHistory.create!(params.merge(
|
|
|
|
action: UserHistory.actions[:create_badge],
|
|
|
|
details: details.join("\n")
|
|
|
|
))
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_badge_change(badge)
|
|
|
|
raise Discourse::InvalidParameters.new(:badge) unless badge
|
|
|
|
details = ["id: #{badge.id}"]
|
|
|
|
badge.previous_changes.each { |f, values| details << "#{f}: #{values[1]}" if BADGE_FIELDS.include?(f.to_sym) }
|
|
|
|
UserHistory.create!(params.merge(
|
|
|
|
action: UserHistory.actions[:change_badge],
|
|
|
|
details: details.join("\n")
|
|
|
|
))
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_badge_deletion(badge)
|
|
|
|
raise Discourse::InvalidParameters.new(:badge) unless badge
|
|
|
|
details = BADGE_FIELDS.map { |f| [f, badge.send(f)] }.select { |f, v| v.present? }.map { |f, v| "#{f}: #{v}" }
|
|
|
|
UserHistory.create!(params.merge(
|
|
|
|
action: UserHistory.actions[:delete_badge],
|
|
|
|
details: details.join("\n")
|
|
|
|
))
|
2013-11-01 22:47:03 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_badge_grant(user_badge, opts = {})
|
2015-02-06 03:34:57 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user_badge) unless user_badge
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:grant_badge],
|
|
|
|
target_user_id: user_badge.user_id,
|
|
|
|
details: user_badge.badge.name
|
|
|
|
))
|
2014-03-20 03:30:12 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_badge_revoke(user_badge, opts = {})
|
2015-02-06 03:34:57 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user_badge) unless user_badge
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:revoke_badge],
|
|
|
|
target_user_id: user_badge.user_id,
|
|
|
|
details: user_badge.badge.name
|
|
|
|
))
|
2014-03-20 03:30:12 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_check_email(user, opts = {})
|
2015-02-06 03:34:57 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:check_email],
|
|
|
|
target_user_id: user.id
|
|
|
|
))
|
2014-09-30 04:31:05 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_show_emails(users, opts = {})
|
2014-12-16 03:14:12 +08:00
|
|
|
return if users.blank?
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:check_email],
|
|
|
|
details: users.map { |u| "[#{u.id}] #{u.username}" }.join("\n")
|
|
|
|
))
|
2014-11-03 19:46:08 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_impersonate(user, opts = {})
|
2015-02-06 03:34:57 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:impersonate],
|
|
|
|
target_user_id: user.id
|
|
|
|
))
|
2014-11-06 17:58:47 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_roll_up(subnets, opts = {})
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:roll_up],
|
|
|
|
details: subnets.join(", ")
|
|
|
|
))
|
2014-11-25 02:48:54 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_category_settings_change(category, category_params, old_permissions = nil)
|
2015-09-17 15:51:32 +08:00
|
|
|
validate_category(category)
|
|
|
|
|
|
|
|
changed_attributes = category.previous_changes.slice(*category_params.keys)
|
|
|
|
|
2015-12-06 15:29:13 +08:00
|
|
|
if !old_permissions.empty? && (old_permissions != category_params[:permissions])
|
2017-07-28 09:20:09 +08:00
|
|
|
changed_attributes.merge!(permissions: [old_permissions.to_json, category_params[:permissions].to_json])
|
2015-09-17 15:51:32 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
changed_attributes.each do |key, value|
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params.merge(
|
|
|
|
action: UserHistory.actions[:change_category_settings],
|
|
|
|
category_id: category.id,
|
|
|
|
context: category.url,
|
|
|
|
subject: key,
|
|
|
|
previous_value: value[0],
|
|
|
|
new_value: value[1]
|
|
|
|
))
|
2015-09-17 15:51:32 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_category_deletion(category)
|
|
|
|
validate_category(category)
|
|
|
|
|
|
|
|
details = [
|
|
|
|
"created_at: #{category.created_at}",
|
|
|
|
"name: #{category.name}",
|
|
|
|
"permissions: #{category.permissions_params}"
|
|
|
|
]
|
|
|
|
|
|
|
|
if parent_category = category.parent_category
|
|
|
|
details << "parent_category: #{parent_category.name}"
|
|
|
|
end
|
|
|
|
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params.merge(
|
|
|
|
action: UserHistory.actions[:delete_category],
|
|
|
|
category_id: category.id,
|
|
|
|
details: details.join("\n"),
|
|
|
|
context: category.url
|
|
|
|
))
|
2015-09-17 15:51:32 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def log_category_creation(category)
|
|
|
|
validate_category(category)
|
|
|
|
|
|
|
|
details = [
|
|
|
|
"created_at: #{category.created_at}",
|
|
|
|
"name: #{category.name}"
|
|
|
|
]
|
|
|
|
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params.merge(
|
|
|
|
action: UserHistory.actions[:create_category],
|
|
|
|
details: details.join("\n"),
|
|
|
|
category_id: category.id,
|
|
|
|
context: category.url
|
|
|
|
))
|
2015-09-17 15:51:32 +08:00
|
|
|
end
|
|
|
|
|
2017-11-11 01:18:08 +08:00
|
|
|
def log_silence_user(user, opts = {})
|
2016-01-15 04:05:11 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
2017-11-21 01:33:02 +08:00
|
|
|
|
2018-02-14 04:33:15 +08:00
|
|
|
create_args = params(opts).merge(
|
|
|
|
action: UserHistory.actions[:silence_user],
|
|
|
|
target_user_id: user.id,
|
|
|
|
details: opts[:details]
|
2017-11-14 02:41:36 +08:00
|
|
|
)
|
2018-02-14 04:33:15 +08:00
|
|
|
create_args[:post_id] = opts[:post_id] if opts[:post_id]
|
|
|
|
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(create_args)
|
2016-01-15 04:05:11 +08:00
|
|
|
end
|
|
|
|
|
2017-11-11 01:18:08 +08:00
|
|
|
def log_unsilence_user(user, opts = {})
|
2016-01-15 04:05:11 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:unsilence_user],
|
|
|
|
target_user_id: user.id
|
|
|
|
))
|
2017-12-22 09:18:12 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def log_disable_second_factor_auth(user, opts = {})
|
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:disabled_second_factor],
|
|
|
|
target_user_id: user.id
|
|
|
|
))
|
2016-01-15 04:05:11 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_grant_admin(user, opts = {})
|
2016-01-27 17:38:16 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:grant_admin],
|
|
|
|
target_user_id: user.id
|
|
|
|
))
|
2016-01-27 17:38:16 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_revoke_admin(user, opts = {})
|
2016-01-27 17:38:16 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:revoke_admin],
|
|
|
|
target_user_id: user.id
|
|
|
|
))
|
2016-01-27 17:38:16 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_grant_moderation(user, opts = {})
|
2016-01-27 17:38:16 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:grant_moderation],
|
|
|
|
target_user_id: user.id
|
|
|
|
))
|
2016-01-27 17:38:16 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_revoke_moderation(user, opts = {})
|
2016-01-27 17:38:16 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:revoke_moderation],
|
|
|
|
target_user_id: user.id
|
|
|
|
))
|
2016-01-27 17:38:16 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_backup_create(opts = {})
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:backup_create],
|
|
|
|
ip_address: @admin.ip_address.to_s
|
|
|
|
))
|
2016-02-28 01:38:24 +08:00
|
|
|
end
|
|
|
|
|
2018-09-19 05:46:45 +08:00
|
|
|
def log_entity_export(entity, opts = {})
|
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:entity_export],
|
|
|
|
ip_address: @admin.ip_address.to_s,
|
|
|
|
subject: entity
|
|
|
|
))
|
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_backup_download(backup, opts = {})
|
2017-01-17 02:53:31 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:backup) unless backup
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:backup_download],
|
|
|
|
ip_address: @admin.ip_address.to_s,
|
|
|
|
details: backup.filename
|
|
|
|
))
|
2017-01-17 02:53:31 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_backup_destroy(backup, opts = {})
|
2017-01-17 02:53:31 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:backup) unless backup
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:backup_destroy],
|
|
|
|
ip_address: @admin.ip_address.to_s,
|
|
|
|
details: backup.filename
|
|
|
|
))
|
2017-01-17 02:53:31 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_revoke_email(user, reason, opts = {})
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:revoke_email],
|
|
|
|
target_user_id: user.id,
|
|
|
|
details: reason
|
|
|
|
))
|
2016-07-26 00:57:06 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_user_deactivate(user, reason, opts = {})
|
2016-07-26 00:57:06 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:deactivate_user],
|
|
|
|
target_user_id: user.id,
|
|
|
|
details: reason
|
|
|
|
))
|
2016-05-03 05:15:32 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_user_activate(user, reason, opts = {})
|
2017-01-11 05:45:36 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:user) unless user
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:activate_user],
|
|
|
|
target_user_id: user.id,
|
|
|
|
details: reason
|
|
|
|
))
|
2017-01-11 05:45:36 +08:00
|
|
|
end
|
|
|
|
|
2017-07-28 09:20:09 +08:00
|
|
|
def log_wizard_step(step, opts = {})
|
2016-09-15 04:36:08 +08:00
|
|
|
raise Discourse::InvalidParameters.new(:step) unless step
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:wizard_step],
|
|
|
|
context: step.id
|
|
|
|
))
|
2016-09-15 04:36:08 +08:00
|
|
|
end
|
|
|
|
|
2017-01-11 14:46:48 +08:00
|
|
|
def log_change_readonly_mode(state)
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params.merge(
|
|
|
|
action: UserHistory.actions[:change_readonly_mode],
|
|
|
|
previous_value: !state,
|
|
|
|
new_value: state
|
|
|
|
))
|
2017-01-11 14:46:48 +08:00
|
|
|
end
|
|
|
|
|
2018-01-27 20:51:22 +08:00
|
|
|
def log_check_personal_message(topic, opts = {})
|
|
|
|
raise Discourse::InvalidParameters.new(:topic) unless topic && topic.is_a?(Topic)
|
2018-05-18 00:09:27 +08:00
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:check_personal_message],
|
|
|
|
topic_id: topic.id,
|
|
|
|
context: topic.relative_url
|
|
|
|
))
|
2018-01-27 20:51:22 +08:00
|
|
|
end
|
|
|
|
|
2018-04-23 13:48:53 +08:00
|
|
|
def log_post_approved(post, opts = {})
|
|
|
|
raise Discourse::InvalidParameters.new(:post) unless post && post.is_a?(Post)
|
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:post_approved],
|
2018-05-18 00:09:27 +08:00
|
|
|
post_id: post.id
|
|
|
|
))
|
2018-04-23 13:48:53 +08:00
|
|
|
end
|
|
|
|
|
2018-06-01 22:12:31 +08:00
|
|
|
def log_post_rejected(rejected_post, opts = {})
|
|
|
|
raise Discourse::InvalidParameters.new(:rejected_post) unless rejected_post && rejected_post.is_a?(QueuedPost)
|
|
|
|
|
|
|
|
topic = rejected_post.topic || Topic.with_deleted.find_by(id: rejected_post.topic_id)
|
2018-06-02 11:55:41 +08:00
|
|
|
topic_title = topic&.title || I18n.t('staff_action_logs.not_found')
|
|
|
|
username = rejected_post.user&.username || I18n.t('staff_action_logs.unknown')
|
|
|
|
name = rejected_post.user&.name || I18n.t('staff_action_logs.unknown')
|
2018-06-01 22:12:31 +08:00
|
|
|
|
|
|
|
details = [
|
|
|
|
"created_at: #{rejected_post.created_at}",
|
|
|
|
"rejected_at: #{rejected_post.rejected_at}",
|
|
|
|
"user: #{username} (#{name})",
|
|
|
|
"topic: #{topic_title}",
|
|
|
|
"raw: #{rejected_post.raw}",
|
|
|
|
]
|
|
|
|
|
|
|
|
UserHistory.create!(params(opts).merge(
|
|
|
|
action: UserHistory.actions[:post_rejected],
|
|
|
|
details: details.join("\n")
|
|
|
|
))
|
|
|
|
end
|
|
|
|
|
2013-08-20 04:58:38 +08:00
|
|
|
private
|
|
|
|
|
2018-06-07 13:28:18 +08:00
|
|
|
def params(opts = nil)
|
|
|
|
opts ||= {}
|
|
|
|
{ acting_user_id: @admin.id, context: opts[:context] }
|
|
|
|
end
|
2013-08-22 00:03:21 +08:00
|
|
|
|
2018-06-07 13:28:18 +08:00
|
|
|
def validate_category(category)
|
|
|
|
raise Discourse::InvalidParameters.new(:category) unless category && category.is_a?(Category)
|
|
|
|
end
|
2015-09-17 15:51:32 +08:00
|
|
|
|
2013-07-08 17:53:22 +08:00
|
|
|
end
|