logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

action_logs_helper.rb (3294B)


  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. def linkable_log_target(record)
  11. case record.class.name
  12. when 'Account'
  13. link_to record.acct, admin_account_path(record.id)
  14. when 'User'
  15. link_to record.account.acct, admin_account_path(record.account_id)
  16. when 'CustomEmoji'
  17. record.shortcode
  18. when 'Report'
  19. link_to "##{record.id}", admin_report_path(record)
  20. when 'DomainBlock', 'EmailDomainBlock'
  21. link_to record.domain, "https://#{record.domain}"
  22. when 'Status'
  23. link_to record.account.acct, TagManager.instance.url_for(record)
  24. end
  25. end
  26. def log_target_from_history(type, attributes)
  27. case type
  28. when 'CustomEmoji'
  29. attributes['shortcode']
  30. when 'DomainBlock', 'EmailDomainBlock'
  31. link_to attributes['domain'], "https://#{attributes['domain']}"
  32. when 'Status'
  33. tmp_status = Status.new(attributes)
  34. link_to tmp_status.account&.acct || "##{tmp_status.account_id}", TagManager.instance.url_for(tmp_status)
  35. end
  36. end
  37. def relevant_log_changes(log)
  38. if log.target_type == 'CustomEmoji' && [:enable, :disable, :destroy].include?(log.action)
  39. log.recorded_changes.slice('domain')
  40. elsif log.target_type == 'CustomEmoji' && log.action == :update
  41. log.recorded_changes.slice('domain', 'visible_in_picker')
  42. elsif log.target_type == 'User' && [:promote, :demote].include?(log.action)
  43. log.recorded_changes.slice('moderator', 'admin')
  44. elsif log.target_type == 'User' && [:change_email].include?(log.action)
  45. log.recorded_changes.slice('email', 'unconfirmed_email')
  46. elsif log.target_type == 'DomainBlock'
  47. log.recorded_changes.slice('severity', 'reject_media')
  48. elsif log.target_type == 'Status' && log.action == :update
  49. log.recorded_changes.slice('sensitive')
  50. end
  51. end
  52. def log_extra_attributes(hash)
  53. safe_join(hash.to_a.map { |key, value| safe_join([content_tag(:span, key, class: 'diff-key'), '=', log_change(value)]) }, ' ')
  54. end
  55. def log_change(val)
  56. return content_tag(:span, val, class: 'diff-neutral') unless val.is_a?(Array)
  57. safe_join([content_tag(:span, val.first, class: 'diff-old'), content_tag(:span, val.last, class: 'diff-new')], '→')
  58. end
  59. def icon_for_log(log)
  60. case log.target_type
  61. when 'Account', 'User'
  62. 'user'
  63. when 'CustomEmoji'
  64. 'file'
  65. when 'Report'
  66. 'flag'
  67. when 'DomainBlock'
  68. 'lock'
  69. when 'EmailDomainBlock'
  70. 'envelope'
  71. when 'Status'
  72. 'pencil'
  73. end
  74. end
  75. def class_for_log_icon(log)
  76. case log.action
  77. when :enable, :unsuspend, :unsilence, :confirm, :promote, :resolve
  78. 'positive'
  79. when :create
  80. opposite_verbs?(log) ? 'negative' : 'positive'
  81. when :update, :reset_password, :disable_2fa, :memorialize, :change_email
  82. 'neutral'
  83. when :demote, :silence, :disable, :suspend, :remove_avatar, :reopen
  84. 'negative'
  85. when :destroy
  86. opposite_verbs?(log) ? 'positive' : 'negative'
  87. else
  88. ''
  89. end
  90. end
  91. private
  92. def opposite_verbs?(log)
  93. %w(DomainBlock EmailDomainBlock).include?(log.target_type)
  94. end
  95. end