From 0a5eba734e6aa6a6e7e8f64b022af8ea129c9f5d Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Mon, 15 Jul 2019 13:10:50 -0500 Subject: [PATCH] add ability to export followers --- .../exports/followers_accounts_controller.rb | 19 +++++++++++++++++++ app/models/export.rb | 8 ++++++++ app/views/settings/exports/show.html.haml | 2 +- config/routes.rb | 1 + 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 app/controllers/settings/exports/followers_accounts_controller.rb diff --git a/app/controllers/settings/exports/followers_accounts_controller.rb b/app/controllers/settings/exports/followers_accounts_controller.rb new file mode 100644 index 000000000..5ed5d6160 --- /dev/null +++ b/app/controllers/settings/exports/followers_accounts_controller.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Settings + module Exports + class FollowersAccountsController < ApplicationController + include ExportControllerConcern + + def index + send_export_file + end + + private + + def export_data + @export.to_followers_accounts_csv + end + end + end +end diff --git a/app/models/export.rb b/app/models/export.rb index cab01f11a..fed41310d 100644 --- a/app/models/export.rb +++ b/app/models/export.rb @@ -29,6 +29,14 @@ class Export end end + def to_followers_accounts_csv + CSV.generate(headers: ['Account address'], write_headers: true) do |csv| + account.followers.find_each do |follow| + csv << [acct(follow)] + end + end + end + def to_lists_csv CSV.generate do |csv| account.owned_lists.select(:title, :id).each do |list| diff --git a/app/views/settings/exports/show.html.haml b/app/views/settings/exports/show.html.haml index b13cea976..455df1c2d 100644 --- a/app/views/settings/exports/show.html.haml +++ b/app/views/settings/exports/show.html.haml @@ -23,7 +23,7 @@ %tr %th= t('accounts.followers', count: @export.total_followers) %td= number_with_delimiter @export.total_followers - %td + %td= table_link_to 'download', t('exports.csv'), settings_exports_followers_path(format: :csv) %tr %th= t('exports.blocks') %td= number_with_delimiter @export.total_blocks diff --git a/config/routes.rb b/config/routes.rb index c86194109..08236a5a6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -98,6 +98,7 @@ Rails.application.routes.draw do resource :export, only: [:show, :create] namespace :exports, constraints: { format: :csv } do resources :follows, only: :index, controller: :following_accounts + resources :followers, only: :index, controller: :followers_accounts resources :blocks, only: :index, controller: :blocked_accounts resources :mutes, only: :index, controller: :muted_accounts resources :lists, only: :index, controller: :lists