severed_relationships_controller.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # frozen_string_literal: true
  2. class SeveredRelationshipsController < ApplicationController
  3. layout 'admin'
  4. before_action :authenticate_user!
  5. before_action :set_body_classes
  6. before_action :set_cache_headers
  7. before_action :set_event, only: [:following, :followers]
  8. def index
  9. @events = AccountRelationshipSeveranceEvent.where(account: current_account)
  10. end
  11. def following
  12. respond_to do |format|
  13. format.csv { send_data following_data, filename: "following-#{@event.target_name}-#{@event.created_at.to_date.iso8601}.csv" }
  14. end
  15. end
  16. def followers
  17. respond_to do |format|
  18. format.csv { send_data followers_data, filename: "followers-#{@event.target_name}-#{@event.created_at.to_date.iso8601}.csv" }
  19. end
  20. end
  21. private
  22. def set_event
  23. @event = AccountRelationshipSeveranceEvent.find(params[:id])
  24. end
  25. def following_data
  26. CSV.generate(headers: ['Account address', 'Show boosts', 'Notify on new posts', 'Languages'], write_headers: true) do |csv|
  27. @event.severed_relationships.active.about_local_account(current_account).includes(:remote_account).reorder(id: :desc).each do |follow|
  28. csv << [acct(follow.target_account), follow.show_reblogs, follow.notify, follow.languages&.join(', ')]
  29. end
  30. end
  31. end
  32. def followers_data
  33. CSV.generate(headers: ['Account address'], write_headers: true) do |csv|
  34. @event.severed_relationships.passive.about_local_account(current_account).includes(:remote_account).reorder(id: :desc).each do |follow|
  35. csv << [acct(follow.account)]
  36. end
  37. end
  38. end
  39. def acct(account)
  40. account.local? ? account.local_username_and_domain : account.acct
  41. end
  42. def set_body_classes
  43. @body_classes = 'admin'
  44. end
  45. def set_cache_headers
  46. response.cache_control.replace(private: true, no_store: true)
  47. end
  48. end