闭社主体 forked from https://github.com/tootsuite/mastodon
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.

53 lines
1.7 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'
  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. end
  30. end
  31. def log_target_from_history(type, attributes)
  32. case type
  33. when 'CustomEmoji'
  34. attributes['shortcode']
  35. when 'DomainBlock', 'DomainAllow', 'EmailDomainBlock'
  36. link_to attributes['domain'], "https://#{attributes['domain']}"
  37. when 'Status'
  38. tmp_status = Status.new(attributes.except('reblogs_count', 'favourites_count'))
  39. if tmp_status.account
  40. link_to tmp_status.account&.acct || "##{tmp_status.account_id}", admin_account_path(tmp_status.account_id)
  41. else
  42. I18n.t('admin.action_logs.deleted_status')
  43. end
  44. when 'Announcement'
  45. truncate(attributes['text'].is_a?(Array) ? attributes['text'].last : attributes['text'])
  46. end
  47. end
  48. end