Skip to content

Commit a7c48f2

Browse files
Gargronhiyuki2578
authored andcommitted
Add CSV export for lists and domain blocks (mastodon#9677)
Fix mastodon#6893 Fix mastodon#9268
1 parent 6e8a339 commit a7c48f2

5 files changed

Lines changed: 82 additions & 4 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module Settings
4+
module Exports
5+
class BlockedDomainsController < ApplicationController
6+
include ExportControllerConcern
7+
8+
def index
9+
send_export_file
10+
end
11+
12+
private
13+
14+
def export_data
15+
@export.to_blocked_domains_csv
16+
end
17+
end
18+
end
19+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
module Settings
4+
module Exports
5+
class ListsController < ApplicationController
6+
include ExportControllerConcern
7+
8+
def index
9+
send_export_file
10+
end
11+
12+
private
13+
14+
def export_data
15+
@export.to_lists_csv
16+
end
17+
end
18+
end
19+
end

app/models/export.rb

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,33 @@ def initialize(account)
99
end
1010

1111
def to_blocked_accounts_csv
12-
to_csv account.blocking
12+
to_csv account.blocking.select(:username, :domain)
1313
end
1414

1515
def to_muted_accounts_csv
16-
to_csv account.muting
16+
to_csv account.muting.select(:username, :domain)
1717
end
1818

1919
def to_following_accounts_csv
20-
to_csv account.following
20+
to_csv account.following.select(:username, :domain)
21+
end
22+
23+
def to_lists_csv
24+
CSV.generate do |csv|
25+
account.owned_lists.select(:title).each do |list|
26+
list.accounts.select(:username, :domain).each do |account|
27+
csv << [list.title, acct(account)]
28+
end
29+
end
30+
end
31+
end
32+
33+
def to_blocked_domains_csv
34+
CSV.generate do |csv|
35+
account.domain_blocks.pluck(:domain).each do |domain|
36+
csv << [domain]
37+
end
38+
end
2139
end
2240

2341
def total_storage
@@ -32,6 +50,10 @@ def total_follows
3250
account.following_count
3351
end
3452

53+
def total_lists
54+
account.owned_lists.count
55+
end
56+
3557
def total_followers
3658
account.followers_count
3759
end
@@ -44,13 +66,21 @@ def total_mutes
4466
account.muting.count
4567
end
4668

69+
def total_domain_blocks
70+
account.domain_blocks.count
71+
end
72+
4773
private
4874

4975
def to_csv(accounts)
5076
CSV.generate do |csv|
5177
accounts.each do |account|
52-
csv << [(account.local? ? account.local_username_and_domain : account.acct)]
78+
csv << [acct(account)]
5379
end
5480
end
5581
end
82+
83+
def acct(account)
84+
account.local? ? account.local_username_and_domain : account.acct
85+
end
5686
end

app/views/settings/exports/show.html.haml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
%th= t('exports.follows')
1717
%td= number_with_delimiter @export.total_follows
1818
%td= table_link_to 'download', t('exports.csv'), settings_exports_follows_path(format: :csv)
19+
%tr
20+
%th= t('exports.lists')
21+
%td= number_with_delimiter @export.total_lists
22+
%td= table_link_to 'download', t('exports.csv'), settings_exports_lists_path(format: :csv)
1923
%tr
2024
%th= t('accounts.followers', count: @export.total_followers)
2125
%td= number_with_delimiter @export.total_followers
@@ -28,6 +32,10 @@
2832
%th= t('exports.mutes')
2933
%td= number_with_delimiter @export.total_mutes
3034
%td= table_link_to 'download', t('exports.csv'), settings_exports_mutes_path(format: :csv)
35+
%tr
36+
%th= t('exports.domain_blocks')
37+
%td= number_with_delimiter @export.total_domain_blocks
38+
%td= table_link_to 'download', t('exports.csv'), settings_exports_domain_blocks_path(format: :csv)
3139

3240
%p.muted-hint= t('exports.archive_takeout.hint_html')
3341

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494
resources :follows, only: :index, controller: :following_accounts
9595
resources :blocks, only: :index, controller: :blocked_accounts
9696
resources :mutes, only: :index, controller: :muted_accounts
97+
resources :lists, only: :index, controller: :lists
98+
resources :domain_blocks, only: :index, controller: :blocked_domains
9799
end
98100

99101
resource :two_factor_authentication, only: [:show, :create, :destroy]

0 commit comments

Comments
 (0)