action_logs_helper.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. when 'Instance'
  32. record.domain
  33. when 'Appeal'
  34. link_to record.account.acct, disputes_strike_path(record.strike)
  35. end
  36. end
  37. def log_target_from_history(type, attributes)
  38. case type
  39. when 'User'
  40. attributes['username']
  41. when 'CustomEmoji'
  42. attributes['shortcode']
  43. when 'DomainBlock', 'DomainAllow', 'EmailDomainBlock', 'UnavailableDomain'
  44. link_to attributes['domain'], "https://#{attributes['domain']}"
  45. when 'Status'
  46. tmp_status = Status.new(attributes.except('reblogs_count', 'favourites_count'))
  47. if tmp_status.account
  48. link_to tmp_status.account&.acct || "##{tmp_status.account_id}", admin_account_path(tmp_status.account_id)
  49. else
  50. I18n.t('admin.action_logs.deleted_status')
  51. end
  52. when 'Announcement'
  53. truncate(attributes['text'].is_a?(Array) ? attributes['text'].last : attributes['text'])
  54. when 'IpBlock'
  55. "#{attributes['ip']}/#{attributes['ip'].prefix} (#{I18n.t("simple_form.labels.ip_block.severities.#{attributes['severity']}")})"
  56. when 'Instance'
  57. attributes['domain']
  58. end
  59. end
  60. end