split federation & moderation logs into different subscopes + make scope tag prefix configurable

staging
multiple creatures 2019-07-26 13:25:24 -05:00
parent e0b257d512
commit 0151f14dbc
3 changed files with 46 additions and 39 deletions

View File

@ -1,4 +1,6 @@
module AutorejectHelper module AutorejectHelper
LOG_SCOPE_FEDERATION = ENV.fetch('LOG_SCOPE_FEDERATION', 'federation')
def should_reject?(uri = nil) def should_reject?(uri = nil)
if uri.nil? if uri.nil?
if @object if @object
@ -91,10 +93,10 @@ module AutorejectHelper
reason = reject_reason(reason) reason = reject_reason(reason)
if @json if @json
Rails.logger.info("Auto-rejected #{@json['id']} (#{@json['type']})") Rails.logger.info("Auto-rejected #{@json['id']} (#{@json['type']})")
LogWorker.perform_async("\xf0\x9f\x9a\xab Auto-rejected an incoming '#{@json['type']}#{@object && " #{@object['type']}".rstrip}' from #{@json['id']} because #{reason}.") LogWorker.perform_async("\xf0\x9f\x9a\xab Auto-rejected an incoming '#{@json['type']}#{@object && " #{@object['type']}".rstrip}' from #{@json['id']} because #{reason}.", LOG_SCOPE_FEDERATION)
elsif uri elsif uri
Rails.logger.info("Auto-rejected #{uri}") Rails.logger.info("Auto-rejected #{uri}")
LogWorker.perform_async("\xf0\x9f\x9a\xab Auto-rejected a request to #{uri} because #{reason}.") LogWorker.perform_async("\xf0\x9f\x9a\xab Auto-rejected a request to #{uri} because #{reason}.", LOG_SCOPE_FEDERATION)
end end
return true return true
end end

View File

@ -1,97 +1,99 @@
module LogHelper module LogHelper
LOG_SCOPE_MODERATION = ENV.fetch('LOG_SCOPE_MODERATION', 'moderation')
def user_friendly_action_log(source, action, target) def user_friendly_action_log(source, action, target)
source = source.username if source.is_a?(Account) source = source.username if source.is_a?(Account)
case action case action
when :create when :create
if target.is_a? DomainBlock if target.is_a? DomainBlock
LogWorker.perform_async("\xf0\x9f\x9a\xab <#{source}> applied a #{target.severity}#{target.force_sensitive? ? " and force sensitive media" : ''}#{target.reject_media? ? " and reject media" : ''} policy on https://#{target.domain}\u200b.") LogWorker.perform_async("\xf0\x9f\x9a\xab <#{source}> applied a #{target.severity}#{target.force_sensitive? ? " and force sensitive media" : ''}#{target.reject_media? ? " and reject media" : ''} policy on https://#{target.domain}\u200b.", LOG_SCOPE_MODERATION)
elsif target.is_a? EmailDomainBlock elsif target.is_a? EmailDomainBlock
LogWorker.perform_async("\u26d4 <#{source}> added a registration block on email domain '#{target.domain}'.") LogWorker.perform_async("\u26d4 <#{source}> added a registration block on email domain '#{target.domain}'.", LOG_SCOPE_MODERATION)
elsif target.is_a? CustomEmoji elsif target.is_a? CustomEmoji
LogWorker.perform_async("\xf0\x9f\x98\xba <#{source}> added the '#{target.shortcode}' emoji. :#{target.shortcode}:") LogWorker.perform_async("\xf0\x9f\x98\xba <#{source}> added the '#{target.shortcode}' emoji. :#{target.shortcode}:", LOG_SCOPE_MODERATION)
elsif target.is_a? AccountWarning elsif target.is_a? AccountWarning
LogWorker.perform_async("\xe2\x9a\xa0\xef\xb8\x8f <#{source}> sent someone an admin notice.") LogWorker.perform_async("\xe2\x9a\xa0\xef\xb8\x8f <#{source}> sent someone an admin notice.", LOG_SCOPE_MODERATION)
end end
when :destroy when :destroy
if target.is_a? DomainBlock if target.is_a? DomainBlock
LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> reset the policy on https://#{target.domain}\u200b.") LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> reset the policy on https://#{target.domain}\u200b.", LOG_SCOPE_MODERATION)
elsif target.is_a? EmailDomainBlock elsif target.is_a? EmailDomainBlock
LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> removed the registration block on email domain '#{target.domain}'.") LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> removed the registration block on email domain '#{target.domain}'.", LOG_SCOPE_MODERATION)
elsif target.is_a? CustomEmoji elsif target.is_a? CustomEmoji
LogWorker.perform_async("\xf0\x9f\x97\x91\xef\xb8\x8f <#{source}> removed the '#{target.shortcode}' emoji.") LogWorker.perform_async("\xf0\x9f\x97\x91\xef\xb8\x8f <#{source}> removed the '#{target.shortcode}' emoji.", LOG_SCOPE_MODERATION)
elsif target.is_a? Status elsif target.is_a? Status
LogWorker.perform_async("\xf0\x9f\x97\x91\xef\xb8\x8f <#{source}> removed post #{TagManager.instance.url_for(target)}\u200b.") LogWorker.perform_async("\xf0\x9f\x97\x91\xef\xb8\x8f <#{source}> removed post #{TagManager.instance.url_for(target, LOG_SCOPE_MODERATION)}\u200b.")
end end
when :update when :update
if target.is_a? Status if target.is_a? Status
LogWorker.perform_async("\xf0\x9f\x91\x81\xef\xb8\x8f <#{source}> changed visibility flags of post #{TagManager.instance.url_for(target)}\u200b.") LogWorker.perform_async("\xf0\x9f\x91\x81\xef\xb8\x8f <#{source}> changed visibility flags of post #{TagManager.instance.url_for(target, LOG_SCOPE_MODERATION)}\u200b.")
elsif target.is_a? CustomEmoji elsif target.is_a? CustomEmoji
LogWorker.perform_async("\xf0\x9f\x94\x81 <#{source}> replaced the '#{target.shortcode}' emoji. :#{target.shortcode}:") LogWorker.perform_async("\xf0\x9f\x94\x81 <#{source}> replaced the '#{target.shortcode}' emoji. :#{target.shortcode}:", LOG_SCOPE_MODERATION)
end end
when :enable when :enable
if target.is_a? User if target.is_a? User
LogWorker.perform_async("\xf0\x9f\x92\xa7 <#{source}> unfroze the account of <#{target.username}>.") LogWorker.perform_async("\xf0\x9f\x92\xa7 <#{source}> unfroze the account of <#{target.username}>.", LOG_SCOPE_MODERATION)
elsif target.is_a? CustomEmoji elsif target.is_a? CustomEmoji
LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> enabled the '#{target.shortcode}' emoji. :#{target.shortcode}:") LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> enabled the '#{target.shortcode}' emoji. :#{target.shortcode}:", LOG_SCOPE_MODERATION)
end end
when :disable when :disable
if target.is_a? User if target.is_a? User
LogWorker.perform_async("\xe2\x9d\x84\xef\xb8\x8f <#{source}> froze the account of <#{target.username}>.") LogWorker.perform_async("\xe2\x9d\x84\xef\xb8\x8f <#{source}> froze the account of <#{target.username}>.", LOG_SCOPE_MODERATION)
elsif target.is_a? CustomEmoji elsif target.is_a? CustomEmoji
LogWorker.perform_async("\u26d4 <#{source}> disabled the '#{target.shortcode}' emoji.") LogWorker.perform_async("\u26d4 <#{source}> disabled the '#{target.shortcode}' emoji.", LOG_SCOPE_MODERATION)
end end
when :force_sensitive when :force_sensitive
LogWorker.perform_async("\xf0\x9f\x94\x9e <#{source}> forced the media of <#{target.acct}> to be marked sensitive.") LogWorker.perform_async("\xf0\x9f\x94\x9e <#{source}> forced the media of <#{target.acct}> to be marked sensitive.", LOG_SCOPE_MODERATION)
when :force_unlisted when :force_unlisted
LogWorker.perform_async("\xf0\x9f\x94\x89 <#{source}> forced the posts of <#{target.acct}> to be unlisted.") LogWorker.perform_async("\xf0\x9f\x94\x89 <#{source}> forced the posts of <#{target.acct}> to be unlisted.", LOG_SCOPE_MODERATION)
when :silence when :silence
LogWorker.perform_async("\xf0\x9f\x94\x87 <#{source}> silenced <#{target.acct}>'.") LogWorker.perform_async("\xf0\x9f\x94\x87 <#{source}> silenced <#{target.acct}>'.", LOG_SCOPE_MODERATION)
when :suspend when :suspend
LogWorker.perform_async("\u26d4 <#{source}> suspended <#{target.acct}>.") LogWorker.perform_async("\u26d4 <#{source}> suspended <#{target.acct}>.", LOG_SCOPE_MODERATION)
when :allow_nonsensitive when :allow_nonsensitive
LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> allowed <#{target.acct}> to post media without a sensitive flag.") LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> allowed <#{target.acct}> to post media without a sensitive flag.", LOG_SCOPE_MODERATION)
when :allow_public when :allow_public
LogWorker.perform_async("\xf0\x9f\x86\x8a <#{source}> allowed <#{target.acct}> to post with public visibility.") LogWorker.perform_async("\xf0\x9f\x86\x8a <#{source}> allowed <#{target.acct}> to post with public visibility.", LOG_SCOPE_MODERATION)
when :unsilence when :unsilence
LogWorker.perform_async("\xf0\x9f\x94\x8a <#{source}> unsilenced <#{target.acct}>.") LogWorker.perform_async("\xf0\x9f\x94\x8a <#{source}> unsilenced <#{target.acct}>.", LOG_SCOPE_MODERATION)
when :unsuspend when :unsuspend
LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> unsuspended <#{target.acct}>.") LogWorker.perform_async("\xf0\x9f\x86\x97 <#{source}> unsuspended <#{target.acct}>.", LOG_SCOPE_MODERATION)
when :remove_avatar when :remove_avatar
LogWorker.perform_async("\xf0\x9f\x97\x91\xef\xb8\x8f <#{source}> removed the avatar of <#{target.acct}>.") LogWorker.perform_async("\xf0\x9f\x97\x91\xef\xb8\x8f <#{source}> removed the avatar of <#{target.acct}>.", LOG_SCOPE_MODERATION)
when :remove_header when :remove_header
LogWorker.perform_async("\xf0\x9f\x97\x91\xef\xb8\x8f <#{source}> removed the profile header of <#{target.acct}>.") LogWorker.perform_async("\xf0\x9f\x97\x91\xef\xb8\x8f <#{source}> removed the profile header of <#{target.acct}>.", LOG_SCOPE_MODERATION)
when :resolve when :resolve
LogWorker.perform_async("\u2705 <#{source}> resolved report ##{target.id}.") LogWorker.perform_async("\u2705 <#{source}> resolved report ##{target.id}.", LOG_SCOPE_MODERATION)
when :reopen when :reopen
LogWorker.perform_async("\u2757 <#{source}> reopened report ##{target.id}.") LogWorker.perform_async("\u2757 <#{source}> reopened report ##{target.id}.", LOG_SCOPE_MODERATION)
when :assigned_to_self when :assigned_to_self
LogWorker.perform_async("\xf0\x9f\x91\x80 <#{source}> is resolving report ##{target.id}.") LogWorker.perform_async("\xf0\x9f\x91\x80 <#{source}> is resolving report ##{target.id}.", LOG_SCOPE_MODERATION)
when :unassigned when :unassigned
LogWorker.perform_async("\u274c <#{source}> is no longer assigned to report ##{target.id}.") LogWorker.perform_async("\u274c <#{source}> is no longer assigned to report ##{target.id}.", LOG_SCOPE_MODERATION)
when :promote when :promote
LogWorker.perform_async("\xf0\x9f\x94\xba <#{source}> upgraded a local account from #{target.role}.") LogWorker.perform_async("\xf0\x9f\x94\xba <#{source}> upgraded a local account from #{target.role}.", LOG_SCOPE_MODERATION)
when :demote when :demote
LogWorker.perform_async("\xf0\x9f\x94\xbb <#{source}> downgraded a local account from #{target.role}.") LogWorker.perform_async("\xf0\x9f\x94\xbb <#{source}> downgraded a local account from #{target.role}.", LOG_SCOPE_MODERATION)
when :confirm when :confirm
LogWorker.perform_async("\u2705 <#{source}> manually confirmed a local account.") LogWorker.perform_async("\u2705 <#{source}> manually confirmed a local account.", LOG_SCOPE_MODERATION)
when :reset_password when :reset_password
LogWorker.perform_async("\xf0\x9f\x94\x81 <#{source}> manually reset a local account's password.") LogWorker.perform_async("\xf0\x9f\x94\x81 <#{source}> manually reset a local account's password.", LOG_SCOPE_MODERATION)
when :disable_2fa when :disable_2fa
LogWorker.perform_async("\xf0\x9f\x94\x81 <#{source}> manually reset a local account's 2-factor auth.") LogWorker.perform_async("\xf0\x9f\x94\x81 <#{source}> manually reset a local account's 2-factor auth.", LOG_SCOPE_MODERATION)
when :change_email when :change_email
LogWorker.perform_async("\xf0\x9f\x93\x9d <#{source}> manually changed a local account's email address.") LogWorker.perform_async("\xf0\x9f\x93\x9d <#{source}> manually changed a local account's email address.", LOG_SCOPE_MODERATION)
when :memorialize when :memorialize
LogWorker.perform_async("\xf0\x9f\x8f\x85 <#{source}> memorialized an account.") LogWorker.perform_async("\xf0\x9f\x8f\x85 <#{source}> memorialized an account.", LOG_SCOPE_MODERATION)
end end
end end
end end

View File

@ -5,18 +5,21 @@ class LogWorker
sidekiq_options unique: :until_executed sidekiq_options unique: :until_executed
def perform(log_text) def perform(log_text, scope = nil)
logger_id = ENV['LOG_USER'].to_i logger_id = ENV['LOG_USER'].to_i
return true if logger_id == 0 return true if logger_id == 0
logger = Account.find_by(id: logger_id) logger = Account.find_by(id: logger_id)
return true if logger.nil? return true if logger.nil?
scope_prefix = ENV.fetch('LOG_SCOPE_PREFIX', 'admin.log')
tag = scope.nil? ? scope_prefix : "#{scope_prefix}.#{scope}"
PostStatusService.new.call( PostStatusService.new.call(
logger, logger,
created_at: Time.now.utc, created_at: Time.now.utc,
text: log_text.strip, text: log_text.strip,
tags: ['monsterpit.admin.log'], tags: [tag],
visibility: :unlisted, visibility: :unlisted,
local_only: true, local_only: true,
content_type: 'text/plain', content_type: 'text/plain',