about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-01-01 13:44:04 +0100
committerGitHub <noreply@github.com>2019-01-01 13:44:04 +0100
commit7fc7437d05bf1441bb694b847f7e65ce37cd74fa (patch)
tree2ecefba5f58a812ab429151841b30e25a331097e
parent1d4215be777afde86208059e3eacf615533bc734 (diff)
Add CSV export for lists and domain blocks (#9677)
Fix #6893
Fix #9268
-rw-r--r--app/controllers/settings/exports/blocked_domains_controller.rb19
-rw-r--r--app/controllers/settings/exports/lists_controller.rb19
-rw-r--r--app/models/export.rb38
-rw-r--r--app/views/settings/exports/show.html.haml8
-rw-r--r--config/routes.rb2
5 files changed, 82 insertions, 4 deletions
diff --git a/app/controllers/settings/exports/blocked_domains_controller.rb b/app/controllers/settings/exports/blocked_domains_controller.rb
new file mode 100644
index 000000000..6676ce340
--- /dev/null
+++ b/app/controllers/settings/exports/blocked_domains_controller.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module Settings
+  module Exports
+    class BlockedDomainsController < ApplicationController
+      include ExportControllerConcern
+
+      def index
+        send_export_file
+      end
+
+      private
+
+      def export_data
+        @export.to_blocked_domains_csv
+      end
+    end
+  end
+end
diff --git a/app/controllers/settings/exports/lists_controller.rb b/app/controllers/settings/exports/lists_controller.rb
new file mode 100644
index 000000000..cf5a9de44
--- /dev/null
+++ b/app/controllers/settings/exports/lists_controller.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module Settings
+  module Exports
+    class ListsController < ApplicationController
+      include ExportControllerConcern
+
+      def index
+        send_export_file
+      end
+
+      private
+
+      def export_data
+        @export.to_lists_csv
+      end
+    end
+  end
+end
diff --git a/app/models/export.rb b/app/models/export.rb
index 0eeac0dc0..a2520e9c2 100644
--- a/app/models/export.rb
+++ b/app/models/export.rb
@@ -9,15 +9,33 @@ class Export
   end
 
   def to_blocked_accounts_csv
-    to_csv account.blocking
+    to_csv account.blocking.select(:username, :domain)
   end
 
   def to_muted_accounts_csv
-    to_csv account.muting
+    to_csv account.muting.select(:username, :domain)
   end
 
   def to_following_accounts_csv
-    to_csv account.following
+    to_csv account.following.select(:username, :domain)
+  end
+
+  def to_lists_csv
+    CSV.generate do |csv|
+      account.owned_lists.select(:title).each do |list|
+        list.accounts.select(:username, :domain).each do |account|
+          csv << [list.title, acct(account)]
+        end
+      end
+    end
+  end
+
+  def to_blocked_domains_csv
+    CSV.generate do |csv|
+      account.domain_blocks.pluck(:domain).each do |domain|
+        csv << [domain]
+      end
+    end
   end
 
   def total_storage
@@ -32,6 +50,10 @@ class Export
     account.following_count
   end
 
+  def total_lists
+    account.owned_lists.count
+  end
+
   def total_followers
     account.followers_count
   end
@@ -44,13 +66,21 @@ class Export
     account.muting.count
   end
 
+  def total_domain_blocks
+    account.domain_blocks.count
+  end
+
   private
 
   def to_csv(accounts)
     CSV.generate do |csv|
       accounts.each do |account|
-        csv << [(account.local? ? account.local_username_and_domain : account.acct)]
+        csv << [acct(account)]
       end
     end
   end
+
+  def acct(account)
+    account.local? ? account.local_username_and_domain : account.acct
+  end
 end
diff --git a/app/views/settings/exports/show.html.haml b/app/views/settings/exports/show.html.haml
index 6c030b1ab..b13cea976 100644
--- a/app/views/settings/exports/show.html.haml
+++ b/app/views/settings/exports/show.html.haml
@@ -17,6 +17,10 @@
         %td= number_with_delimiter @export.total_follows
         %td= table_link_to 'download', t('exports.csv'), settings_exports_follows_path(format: :csv)
       %tr
+        %th= t('exports.lists')
+        %td= number_with_delimiter @export.total_lists
+        %td= table_link_to 'download', t('exports.csv'), settings_exports_lists_path(format: :csv)
+      %tr
         %th= t('accounts.followers', count: @export.total_followers)
         %td= number_with_delimiter @export.total_followers
         %td
@@ -28,6 +32,10 @@
         %th= t('exports.mutes')
         %td= number_with_delimiter @export.total_mutes
         %td= table_link_to 'download', t('exports.csv'), settings_exports_mutes_path(format: :csv)
+      %tr
+        %th= t('exports.domain_blocks')
+        %td= number_with_delimiter @export.total_domain_blocks
+        %td= table_link_to 'download', t('exports.csv'), settings_exports_domain_blocks_path(format: :csv)
 
 %p.muted-hint= t('exports.archive_takeout.hint_html')
 
diff --git a/config/routes.rb b/config/routes.rb
index 1556aa577..6e4da48a0 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -94,6 +94,8 @@ Rails.application.routes.draw do
       resources :follows, only: :index, controller: :following_accounts
       resources :blocks, only: :index, controller: :blocked_accounts
       resources :mutes, only: :index, controller: :muted_accounts
+      resources :lists, only: :index, controller: :lists
+      resources :domain_blocks, only: :index, controller: :blocked_domains
     end
 
     resource :two_factor_authentication, only: [:show, :create, :destroy]