Settings export refactor (#1646)
* Refactor Export to take an account and know about the export types * Use Export instance in settings/exports#show
This commit is contained in:
parent
faefd8ec8f
commit
0e39cc6a35
@ -6,7 +6,7 @@ module Settings
|
|||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
|
|
||||||
def index
|
def index
|
||||||
export_data = Export.new(export_accounts).to_csv
|
@export = Export.new(current_account)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.csv { send_data export_data, filename: export_filename }
|
format.csv { send_data export_data, filename: export_filename }
|
||||||
|
@ -5,8 +5,8 @@ module Settings
|
|||||||
class BlockedAccountsController < BaseController
|
class BlockedAccountsController < BaseController
|
||||||
private
|
private
|
||||||
|
|
||||||
def export_accounts
|
def export_data
|
||||||
current_account.blocking
|
@export.to_blocked_accounts_csv
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,8 +5,8 @@ module Settings
|
|||||||
class FollowingAccountsController < BaseController
|
class FollowingAccountsController < BaseController
|
||||||
private
|
private
|
||||||
|
|
||||||
def export_accounts
|
def export_data
|
||||||
current_account.following
|
@export.to_following_accounts_csv
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,8 +5,8 @@ module Settings
|
|||||||
class MutedAccountsController < BaseController
|
class MutedAccountsController < BaseController
|
||||||
private
|
private
|
||||||
|
|
||||||
def export_accounts
|
def export_data
|
||||||
current_account.muting
|
@export.to_muted_accounts_csv
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,9 +6,6 @@ class Settings::ExportsController < ApplicationController
|
|||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@total_storage = current_account.media_attachments.sum(:file_file_size)
|
@export = Export.new(current_account)
|
||||||
@total_follows = current_account.following.count
|
|
||||||
@total_blocks = current_account.blocking.count
|
|
||||||
@total_mutes = current_account.muting.count
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2,13 +2,43 @@
|
|||||||
require 'csv'
|
require 'csv'
|
||||||
|
|
||||||
class Export
|
class Export
|
||||||
attr_reader :accounts
|
attr_reader :account
|
||||||
|
|
||||||
def initialize(accounts)
|
def initialize(account)
|
||||||
@accounts = accounts
|
@account = account
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_csv
|
def to_blocked_accounts_csv
|
||||||
|
to_csv account.blocking
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_muted_accounts_csv
|
||||||
|
to_csv account.muting
|
||||||
|
end
|
||||||
|
|
||||||
|
def to_following_accounts_csv
|
||||||
|
to_csv account.following
|
||||||
|
end
|
||||||
|
|
||||||
|
def total_storage
|
||||||
|
account.media_attachments.sum(:file_file_size)
|
||||||
|
end
|
||||||
|
|
||||||
|
def total_follows
|
||||||
|
account.following.count
|
||||||
|
end
|
||||||
|
|
||||||
|
def total_blocks
|
||||||
|
account.blocking.count
|
||||||
|
end
|
||||||
|
|
||||||
|
def total_mutes
|
||||||
|
account.muting.count
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def to_csv(accounts)
|
||||||
CSV.generate do |csv|
|
CSV.generate do |csv|
|
||||||
accounts.each do |account|
|
accounts.each do |account|
|
||||||
csv << [(account.local? ? account.local_username_and_domain : account.acct)]
|
csv << [(account.local? ? account.local_username_and_domain : account.acct)]
|
||||||
|
@ -5,17 +5,17 @@
|
|||||||
%tbody
|
%tbody
|
||||||
%tr
|
%tr
|
||||||
%th= t('exports.storage')
|
%th= t('exports.storage')
|
||||||
%td= number_to_human_size @total_storage
|
%td= number_to_human_size @export.total_storage
|
||||||
%td
|
%td
|
||||||
%tr
|
%tr
|
||||||
%th= t('exports.follows')
|
%th= t('exports.follows')
|
||||||
%td= @total_follows
|
%td= @export.total_follows
|
||||||
%td= table_link_to 'download', t('exports.csv'), settings_exports_follows_path(format: :csv)
|
%td= table_link_to 'download', t('exports.csv'), settings_exports_follows_path(format: :csv)
|
||||||
%tr
|
%tr
|
||||||
%th= t('exports.blocks')
|
%th= t('exports.blocks')
|
||||||
%td= @total_blocks
|
%td= @export.total_blocks
|
||||||
%td= table_link_to 'download', t('exports.csv'), settings_exports_blocks_path(format: :csv)
|
%td= table_link_to 'download', t('exports.csv'), settings_exports_blocks_path(format: :csv)
|
||||||
%tr
|
%tr
|
||||||
%th= t('exports.mutes')
|
%th= t('exports.mutes')
|
||||||
%td= @total_mutes
|
%td= @export.total_mutes
|
||||||
%td= table_link_to 'download', t('exports.csv'), settings_exports_mutes_path(format: :csv)
|
%td= table_link_to 'download', t('exports.csv'), settings_exports_mutes_path(format: :csv)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe Settings::ExportsController do
|
describe Settings::ExportsController do
|
||||||
|
render_views
|
||||||
|
|
||||||
before do
|
before do
|
||||||
sign_in Fabricate(:user), scope: :user
|
sign_in Fabricate(:user), scope: :user
|
||||||
end
|
end
|
||||||
@ -8,6 +10,7 @@ describe Settings::ExportsController do
|
|||||||
describe 'GET #show' do
|
describe 'GET #show' do
|
||||||
it 'returns http success' do
|
it 'returns http success' do
|
||||||
get :show
|
get :show
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user