You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.0 KiB

  1. # frozen_string_literal: true
  2. module Admin::ActionLogsHelper
  3. def log_target(log)
  4. if log.target
  5. linkable_log_target(log.target)
  6. else
  7. log_target_from_history(log.target_type, log.recorded_changes)
  8. end
  9. end
  10. private
  11. def linkable_log_target(record)
  12. case record.class.name
  13. when 'Account'
  14. link_to record.acct, admin_account_path(record.id)
  15. when 'User'
  16. link_to record.account.acct, admin_account_path(record.account_id)
  17. when 'CustomEmoji'
  18. record.shortcode
  19. when 'Report'
  20. link_to "##{record.id}", admin_report_path(record)
  21. when 'DomainBlock', 'DomainAllow', 'EmailDomainBlock', 'UnavailableDomain'
  22. link_to record.domain, "https://#{record.domain}"
  23. when 'Status'
  24. link_to record.account.acct, ActivityPub::TagManager.instance.url_for(record)
  25. when 'AccountWarning'
  26. link_to record.target_account.acct, admin_account_path(record.target_account_id)
  27. when 'Announcement'
  28. link_to truncate(record.text), edit_admin_announcement_path(record.id)
  29. when 'IpBlock'
  30. "#{record.ip}/#{record.ip.prefix} (#{I18n.t("simple_form.labels.ip_block.severities.#{record.severity}")})"
  31. end
  32. end
  33. def log_target_from_history(type, attributes)
  34. case type
  35. when 'CustomEmoji'
  36. attributes['shortcode']
  37. when 'DomainBlock', 'DomainAllow', 'EmailDomainBlock', 'UnavailableDomain'
  38. link_to attributes['domain'], "https://#{attributes['domain']}"
  39. when 'Status'
  40. tmp_status = Status.new(attributes.except('reblogs_count', 'favourites_count'))
  41. if tmp_status.account
  42. link_to tmp_status.account&.acct || "##{tmp_status.account_id}", admin_account_path(tmp_status.account_id)
  43. else
  44. I18n.t('admin.action_logs.deleted_status')
  45. end
  46. when 'Announcement'
  47. truncate(attributes['text'].is_a?(Array) ? attributes['text'].last : attributes['text'])
  48. when 'IpBlock'
  49. "#{attributes['ip']}/#{attributes['ip'].prefix} (#{I18n.t("simple_form.labels.ip_block.severities.#{attributes['severity']}")})"
  50. end
  51. end
  52. end