From 7a53fefe8cd42e0ad41fd792a8ca1fd61cbcae1c Mon Sep 17 00:00:00 2001 From: noellabo Date: Fri, 20 Jan 2023 14:08:02 +0900 Subject: [PATCH] Add export of account subscribe --- .../account_subscribings_controller.rb | 19 +++++++++++++++++++ app/models/export.rb | 14 +++++++++++--- app/models/follow.rb | 4 ++++ app/views/settings/exports/show.html.haml | 4 ++++ config/locales/en.yml | 1 + config/locales/ja.yml | 1 + config/routes.rb | 1 + 7 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 app/controllers/settings/exports/account_subscribings_controller.rb diff --git a/app/controllers/settings/exports/account_subscribings_controller.rb b/app/controllers/settings/exports/account_subscribings_controller.rb new file mode 100644 index 000000000..c727fcd83 --- /dev/null +++ b/app/controllers/settings/exports/account_subscribings_controller.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Settings + module Exports + class AccountSubscribingsController < BaseController + include ExportControllerConcern + + def index + send_export_file + end + + private + + def export_data + @export.to_subscribing_accounts_csv + end + end + end +end diff --git a/app/models/export.rb b/app/models/export.rb index 1abcfa144..e739dd2a7 100644 --- a/app/models/export.rb +++ b/app/models/export.rb @@ -30,9 +30,17 @@ class Export end def to_following_accounts_csv - CSV.generate(headers: ['Account address', 'Show boosts'], write_headers: true) do |csv| + CSV.generate(headers: ['Account address', 'Show boosts', 'Notify on new posts', 'Languages', 'Delivery to home'], write_headers: true) do |csv| account.active_relationships.includes(:target_account).reorder(id: :desc).each do |follow| - csv << [acct(follow.target_account), follow.show_reblogs] + csv << [acct(follow.target_account), follow.show_reblogs, follow.notify, follow.languages&.join(', '), follow.delivery] + end + end + end + + def to_subscribing_accounts_csv + CSV.generate(headers: ['Account address', 'List', 'Show boosts', 'Media only'], write_headers: true) do |csv| + account.active_subscribes.includes(:target_account, :list).references(:list).reorder(id: :desc).each do |subscribe| + csv << [acct(subscribe.target_account), subscribe.list&.title, subscribe.show_reblogs, subscribe.media_only] end end end @@ -71,7 +79,7 @@ class Export account.following_count end - def total_subscribes + def total_subscribings account.subscribing_count end diff --git a/app/models/follow.rb b/app/models/follow.rb index 32d7a325f..6a6fa92cf 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -40,6 +40,10 @@ class Follow < ApplicationRecord destroy! end + def languages + nil + end + before_validation :set_uri, only: :create after_create :increment_cache_counters after_create :invalidate_hash_cache diff --git a/app/views/settings/exports/show.html.haml b/app/views/settings/exports/show.html.haml index c49613fdc..8a7229bf0 100644 --- a/app/views/settings/exports/show.html.haml +++ b/app/views/settings/exports/show.html.haml @@ -16,6 +16,10 @@ %th= t('admin.accounts.follows') %td= number_with_delimiter @export.total_follows %td= table_link_to 'download', t('exports.csv'), settings_exports_follows_path(format: :csv) + %tr + %th= t('admin.accounts.subscribes') + %td= number_with_delimiter @export.total_subscribings + %td= table_link_to 'download', t('exports.csv'), settings_exports_account_subscribings_path(format: :csv) %tr %th= t('exports.lists') %td= number_with_delimiter @export.total_lists diff --git a/config/locales/en.yml b/config/locales/en.yml index 189ef16a6..d2ebae9d4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -218,6 +218,7 @@ en: silenced: Limited statuses: Posts subscribe: Subscribe + subscribes: Subscribes suspended: Suspended suspension_irreversible: The data of this account has been irreversibly deleted. You can unsuspend the account to make it usable but it will not recover any data it previously had. suspension_reversible_hint_html: The account has been suspended, and the data will be fully removed on %{date}. Until then, the account can be restored without any ill effects. If you wish to remove all of the account's data immediately, you can do so below. diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 20b49faba..c9476416d 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -207,6 +207,7 @@ ja: silenced: サイレンス済み statuses: 投稿数 subscribe: 購読する + subscribes: 購読 suspended: 停止済み suspension_irreversible: このアカウントのデータは削除され元に戻せなくなります。後日アカウントの凍結を解除することはできますがデータは元に戻せません。 suspension_reversible_hint_html: アカウントは停止されており、データは %{date} に完全に削除されます。それまではアカウントを元に戻すことができます。今すぐ完全に削除したい場合は以下から行うことができます。 diff --git a/config/routes.rb b/config/routes.rb index 65c58e8cc..f6f249ee3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -128,6 +128,7 @@ Rails.application.routes.draw do resources :lists, only: :index, controller: :lists resources :domain_blocks, only: :index, controller: :blocked_domains resources :bookmarks, only: :index, controller: :bookmarks + resources :account_subscribings, only: :index, controller: :account_subscribings end resources :two_factor_authentication_methods, only: [:index] do