2017-11-23 17:05:53 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin::ActionLogsHelper
|
|
|
|
def log_target(log)
|
|
|
|
if log.target
|
|
|
|
linkable_log_target(log.target)
|
|
|
|
else
|
|
|
|
log_target_from_history(log.target_type, log.recorded_changes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def relevant_log_changes(log)
|
|
|
|
if log.target_type == 'CustomEmoji' && [:enable, :disable, :destroy].include?(log.action)
|
|
|
|
log.recorded_changes.slice('domain')
|
|
|
|
elsif log.target_type == 'CustomEmoji' && log.action == :update
|
|
|
|
log.recorded_changes.slice('domain', 'visible_in_picker')
|
|
|
|
elsif log.target_type == 'User' && [:promote, :demote].include?(log.action)
|
|
|
|
log.recorded_changes.slice('moderator', 'admin')
|
2018-04-10 00:16:06 -07:00
|
|
|
elsif log.target_type == 'User' && [:change_email].include?(log.action)
|
|
|
|
log.recorded_changes.slice('email', 'unconfirmed_email')
|
2017-11-23 17:05:53 -08:00
|
|
|
elsif log.target_type == 'DomainBlock'
|
|
|
|
log.recorded_changes.slice('severity', 'reject_media')
|
|
|
|
elsif log.target_type == 'Status' && log.action == :update
|
|
|
|
log.recorded_changes.slice('sensitive')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_extra_attributes(hash)
|
|
|
|
safe_join(hash.to_a.map { |key, value| safe_join([content_tag(:span, key, class: 'diff-key'), '=', log_change(value)]) }, ' ')
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_change(val)
|
|
|
|
return content_tag(:span, val, class: 'diff-neutral') unless val.is_a?(Array)
|
|
|
|
safe_join([content_tag(:span, val.first, class: 'diff-old'), content_tag(:span, val.last, class: 'diff-new')], '→')
|
|
|
|
end
|
|
|
|
|
|
|
|
def icon_for_log(log)
|
|
|
|
case log.target_type
|
|
|
|
when 'Account', 'User'
|
|
|
|
'user'
|
|
|
|
when 'CustomEmoji'
|
|
|
|
'file'
|
|
|
|
when 'Report'
|
|
|
|
'flag'
|
|
|
|
when 'DomainBlock'
|
|
|
|
'lock'
|
|
|
|
when 'EmailDomainBlock'
|
|
|
|
'envelope'
|
|
|
|
when 'Status'
|
|
|
|
'pencil'
|
Add moderation warnings (#9519)
* Add moderation warnings
Replace individual routes for disabling, silencing, and suspending
a user, as well as the report update route, with a unified account
action controller that allows you to select an action (none,
disable, silence, suspend) as well as whether it should generate an
e-mail notification with optional custom text. That notification,
with the optional custom text, is saved as a warning.
Additionally, there are warning presets you can configure to save
time when performing the above.
* Use Account#local_username_and_domain
2018-12-22 11:02:09 -08:00
|
|
|
when 'AccountWarning'
|
|
|
|
'warning'
|
2017-11-23 17:05:53 -08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def class_for_log_icon(log)
|
|
|
|
case log.action
|
|
|
|
when :enable, :unsuspend, :unsilence, :confirm, :promote, :resolve
|
|
|
|
'positive'
|
|
|
|
when :create
|
|
|
|
opposite_verbs?(log) ? 'negative' : 'positive'
|
2018-04-10 00:16:06 -07:00
|
|
|
when :update, :reset_password, :disable_2fa, :memorialize, :change_email
|
2017-11-23 17:05:53 -08:00
|
|
|
'neutral'
|
2018-12-11 10:28:03 -08:00
|
|
|
when :demote, :silence, :disable, :suspend, :remove_avatar, :remove_header, :reopen
|
2017-11-23 17:05:53 -08:00
|
|
|
'negative'
|
|
|
|
when :destroy
|
|
|
|
opposite_verbs?(log) ? 'positive' : 'negative'
|
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def opposite_verbs?(log)
|
Add moderation warnings (#9519)
* Add moderation warnings
Replace individual routes for disabling, silencing, and suspending
a user, as well as the report update route, with a unified account
action controller that allows you to select an action (none,
disable, silence, suspend) as well as whether it should generate an
e-mail notification with optional custom text. That notification,
with the optional custom text, is saved as a warning.
Additionally, there are warning presets you can configure to save
time when performing the above.
* Use Account#local_username_and_domain
2018-12-22 11:02:09 -08:00
|
|
|
%w(DomainBlock EmailDomainBlock AccountWarning).include?(log.target_type)
|
2017-11-23 17:05:53 -08:00
|
|
|
end
|
2019-03-15 08:57:23 -07:00
|
|
|
|
|
|
|
def linkable_log_target(record)
|
|
|
|
case record.class.name
|
|
|
|
when 'Account'
|
|
|
|
link_to record.acct, admin_account_path(record.id)
|
|
|
|
when 'User'
|
|
|
|
link_to record.account.acct, admin_account_path(record.account_id)
|
|
|
|
when 'CustomEmoji'
|
|
|
|
record.shortcode
|
|
|
|
when 'Report'
|
|
|
|
link_to "##{record.id}", admin_report_path(record)
|
|
|
|
when 'DomainBlock', 'EmailDomainBlock'
|
|
|
|
link_to record.domain, "https://#{record.domain}"
|
|
|
|
when 'Status'
|
2019-07-07 07:16:51 -07:00
|
|
|
link_to record.account.acct, ActivityPub::TagManager.instance.url_for(record)
|
2019-03-15 08:57:23 -07:00
|
|
|
when 'AccountWarning'
|
|
|
|
link_to record.target_account.acct, admin_account_path(record.target_account_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_target_from_history(type, attributes)
|
|
|
|
case type
|
|
|
|
when 'CustomEmoji'
|
|
|
|
attributes['shortcode']
|
|
|
|
when 'DomainBlock', 'EmailDomainBlock'
|
|
|
|
link_to attributes['domain'], "https://#{attributes['domain']}"
|
|
|
|
when 'Status'
|
|
|
|
tmp_status = Status.new(attributes.except('reblogs_count', 'favourites_count'))
|
|
|
|
|
|
|
|
if tmp_status.account
|
|
|
|
link_to tmp_status.account&.acct || "##{tmp_status.account_id}", admin_account_path(tmp_status.account_id)
|
|
|
|
else
|
|
|
|
I18n.t('admin.action_logs.deleted_status')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-11-23 17:05:53 -08:00
|
|
|
end
|