2017-11-24 02:05:53 +01: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
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-03-15 16:57:23 +01: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)
|
2021-05-05 23:39:02 +02:00
|
|
|
when 'DomainBlock', 'DomainAllow', 'EmailDomainBlock', 'UnavailableDomain'
|
2019-03-15 16:57:23 +01:00
|
|
|
link_to record.domain, "https://#{record.domain}"
|
|
|
|
when 'Status'
|
2019-07-07 16:16:51 +02:00
|
|
|
link_to record.account.acct, ActivityPub::TagManager.instance.url_for(record)
|
2019-03-15 16:57:23 +01:00
|
|
|
when 'AccountWarning'
|
|
|
|
link_to record.target_account.acct, admin_account_path(record.target_account_id)
|
2020-01-23 22:00:13 +01:00
|
|
|
when 'Announcement'
|
2020-04-03 13:06:34 +02:00
|
|
|
link_to truncate(record.text), edit_admin_announcement_path(record.id)
|
2020-10-12 16:33:49 +02:00
|
|
|
when 'IpBlock'
|
|
|
|
"#{record.ip}/#{record.ip.prefix} (#{I18n.t("simple_form.labels.ip_block.severities.#{record.severity}")})"
|
2021-12-17 23:01:21 +01:00
|
|
|
when 'Instance'
|
|
|
|
record.domain
|
2022-02-14 21:27:53 +01:00
|
|
|
when 'Appeal'
|
|
|
|
link_to record.account.acct, disputes_strike_path(record.strike)
|
2019-03-15 16:57:23 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_target_from_history(type, attributes)
|
|
|
|
case type
|
2021-12-05 21:48:39 +01:00
|
|
|
when 'User'
|
|
|
|
attributes['username']
|
2019-03-15 16:57:23 +01:00
|
|
|
when 'CustomEmoji'
|
|
|
|
attributes['shortcode']
|
2021-05-05 23:39:02 +02:00
|
|
|
when 'DomainBlock', 'DomainAllow', 'EmailDomainBlock', 'UnavailableDomain'
|
2019-03-15 16:57:23 +01:00
|
|
|
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
|
2020-01-23 22:00:13 +01:00
|
|
|
when 'Announcement'
|
2020-04-17 19:54:58 +02:00
|
|
|
truncate(attributes['text'].is_a?(Array) ? attributes['text'].last : attributes['text'])
|
2020-10-12 16:33:49 +02:00
|
|
|
when 'IpBlock'
|
|
|
|
"#{attributes['ip']}/#{attributes['ip'].prefix} (#{I18n.t("simple_form.labels.ip_block.severities.#{attributes['severity']}")})"
|
2021-12-17 23:01:21 +01:00
|
|
|
when 'Instance'
|
|
|
|
attributes['domain']
|
2019-03-15 16:57:23 +01:00
|
|
|
end
|
|
|
|
end
|
2017-11-24 02:05:53 +01:00
|
|
|
end
|