Skip to content

Commit

Permalink
[WiP] Add page to list relationship severance events
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire committed Oct 26, 2023
1 parent 584a167 commit 0d5c6c1
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 1 deletion.
61 changes: 61 additions & 0 deletions app/controllers/severed_relationships_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# frozen_string_literal: true

class SeveredRelationshipsController < ApplicationController
layout 'admin'

before_action :authenticate_user!
before_action :set_body_classes
before_action :set_cache_headers

before_action :set_event, only: [:following, :followers]

def index
@events = RelationshipSeveranceEvent.about_account(current_account)
end

def following
respond_to do |format|
format.csv { send_data following_data, filename: 'following-TODO.csv' }
end
end

def followers
respond_to do |format|
format.csv { send_data followers_data, filename: 'followers-TODO.csv' }
end
end

private

def set_event
@event = RelationshipSeveranceEvent.find(params[:id])
end

def following_data
CSV.generate(headers: ['Account address', 'Show boosts', 'Notify on new posts', 'Languages'], write_headers: true) do |csv|
@event.severed_relationships.where(account: current_account).includes(:target_account).reorder(id: :desc).each do |follow|
csv << [acct(follow.target_account), follow.show_reblogs, follow.notify, follow.languages&.join(', ')]
end
end
end

def followers_data
CSV.generate(headers: ['Account address'], write_headers: true) do |csv|
@event.severed_relationships.where(target_account: current_account).includes(:account).reorder(id: :desc).each do |follow|
csv << [acct(follow.account)]
end
end
end

def acct(account)
account.local? ? account.local_username_and_domain : account.acct
end

def set_body_classes
@body_classes = 'admin'
end

def set_cache_headers
response.cache_control.replace(private: true, no_store: true)
end
end
31 changes: 31 additions & 0 deletions app/views/severed_relationships/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
- content_for :page_title do
= t('settings.severed_relationships')

%p.muted-hint= t('severed_relationships.preamble')

- unless @events.empty?
.table-wrapper
%table.table
%thead
%tr
%th= t('exports.archive_takeout.date')
%th= t('severed_relationships.type')
%th= t('severed_relationships.lost_follows')
%th= t('severed_relationships.lost_followers')
%tbody
- @events.each do |event|
%tr
%td= l event.created_at
%td= t("severed_relationships.event_type.#{event.type}")
%td
- count = event.severed_relationships.where(account: current_account).count
- if count.zero?
= t('generic.none')
- else
= table_link_to 'download', t('severed_relationships.download', count: count), following_severed_relationship_path(event, format: :csv)
%td
- count = event.severed_relationships.where(target_account: current_account).count
- if count.zero?
= t('generic.none')
- else
= table_link_to 'download', t('severed_relationships.download', count: count), followers_severed_relationship_path(event, format: :csv)
9 changes: 9 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1640,10 +1640,19 @@ en:
preferences: Preferences
profile: Public profile
relationships: Follows and followers
severed_relationships: Severed relationships
statuses_cleanup: Automated post deletion
strikes: Moderation strikes
two_factor_authentication: Two-factor Auth
webauthn_authentication: Security keys
severed_relationships:
download: Download (%{count})
event_type:
domain_block: Server suspension
lost_followers: Lost followers
lost_follows: Lost follows
preamble: You may lose follows and followers when you block a domain or when your moderators decide to suspend a remote server. When that happens, you will be able to download lists of severed relationships, to be inspected and possibly imported on another server.
type: Event
statuses:
attached:
audio:
Expand Down
6 changes: 5 additions & 1 deletion config/navigation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
s.item :other, safe_join([fa_icon('cog fw'), t('preferences.other')]), settings_preferences_other_path
end

n.item :relationships, safe_join([fa_icon('users fw'), t('settings.relationships')]), relationships_path, if: -> { current_user.functional? && !self_destruct }
n.item :relationships, safe_join([fa_icon('users fw'), t('settings.relationships')]), relationships_path, if: -> { current_user.functional? && !self_destruct } do |s|
s.item :current, safe_join([fa_icon('users fw'), t('settings.relationships')]), relationships_path
s.item :severed_relationships, safe_join([fa_icon('unlink fw'), t('settings.severed_relationships')]), severed_relationships_path
end

n.item :filters, safe_join([fa_icon('filter fw'), t('filters.index.title')]), filters_path, highlights_on: %r{/filters}, if: -> { current_user.functional? && !self_destruct }
n.item :statuses_cleanup, safe_join([fa_icon('history fw'), t('settings.statuses_cleanup')]), statuses_cleanup_path, if: -> { current_user.functional_or_moved? && !self_destruct }

Expand Down
8 changes: 8 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@
end

resource :relationships, only: [:show, :update]
resources :severed_relationships, only: [:index] do
member do
constraints(format: :csv) do
get :followers
get :following
end
end
end
resource :statuses_cleanup, controller: :statuses_cleanup, only: [:show, :update]

get '/media_proxy/:id/(*any)', to: 'media_proxy#show', as: :media_proxy, format: false
Expand Down

0 comments on commit 0d5c6c1

Please sign in to comment.