severed_relationships_controller.rb 1.7 KB

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