Allow import/export of mutes list (#1541)
* Allow export of mutes list * Allow importing of mutes list * Refactor to use Settings::Exports::BaseController and DRY up exports codegh/stable
parent
08fce08217
commit
7f0a865b05
|
@ -0,0 +1,23 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Settings
|
||||||
|
module Exports
|
||||||
|
class BaseController < ApplicationController
|
||||||
|
before_action :authenticate_user!
|
||||||
|
|
||||||
|
def index
|
||||||
|
export_data = Export.new(export_accounts).to_csv
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.csv { send_data export_data, filename: export_filename }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def export_filename
|
||||||
|
"#{controller_name}.csv"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,15 +2,11 @@
|
||||||
|
|
||||||
module Settings
|
module Settings
|
||||||
module Exports
|
module Exports
|
||||||
class BlockedAccountsController < ApplicationController
|
class BlockedAccountsController < BaseController
|
||||||
before_action :authenticate_user!
|
private
|
||||||
|
|
||||||
def index
|
def export_accounts
|
||||||
export_data = Export.new(current_account.blocking).to_csv
|
current_account.blocking
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.csv { send_data export_data, filename: 'blocking.csv' }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,15 +2,11 @@
|
||||||
|
|
||||||
module Settings
|
module Settings
|
||||||
module Exports
|
module Exports
|
||||||
class FollowingAccountsController < ApplicationController
|
class FollowingAccountsController < BaseController
|
||||||
before_action :authenticate_user!
|
private
|
||||||
|
|
||||||
def index
|
def export_accounts
|
||||||
export_data = Export.new(current_account.following).to_csv
|
current_account.following
|
||||||
|
|
||||||
respond_to do |format|
|
|
||||||
format.csv { send_data export_data, filename: 'following.csv' }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Settings
|
||||||
|
module Exports
|
||||||
|
class MutedAccountsController < BaseController
|
||||||
|
private
|
||||||
|
|
||||||
|
def export_accounts
|
||||||
|
current_account.muting
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -9,5 +9,6 @@ class Settings::ExportsController < ApplicationController
|
||||||
@total_storage = current_account.media_attachments.sum(:file_file_size)
|
@total_storage = current_account.media_attachments.sum(:file_file_size)
|
||||||
@total_follows = current_account.following.count
|
@total_follows = current_account.following.count
|
||||||
@total_blocks = current_account.blocking.count
|
@total_blocks = current_account.blocking.count
|
||||||
|
@total_mutes = current_account.muting.count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
class Import < ApplicationRecord
|
class Import < ApplicationRecord
|
||||||
self.inheritance_column = false
|
self.inheritance_column = false
|
||||||
|
|
||||||
enum type: [:following, :blocking]
|
enum type: [:following, :blocking, :muting]
|
||||||
|
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
|
|
||||||
|
|
|
@ -15,3 +15,7 @@
|
||||||
%th= t('exports.blocks')
|
%th= t('exports.blocks')
|
||||||
%td= @total_blocks
|
%td= @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
|
||||||
|
%th= t('exports.mutes')
|
||||||
|
%td= @total_mutes
|
||||||
|
%td= table_link_to 'download', t('exports.csv'), settings_exports_mutes_path(format: :csv)
|
||||||
|
|
|
@ -16,6 +16,8 @@ class ImportWorker
|
||||||
process_blocks
|
process_blocks
|
||||||
when 'following'
|
when 'following'
|
||||||
process_follows
|
process_follows
|
||||||
|
when 'muting'
|
||||||
|
process_mutes
|
||||||
end
|
end
|
||||||
|
|
||||||
@import.destroy
|
@import.destroy
|
||||||
|
@ -35,6 +37,18 @@ class ImportWorker
|
||||||
CSV.new(import_contents).reject(&:blank?)
|
CSV.new(import_contents).reject(&:blank?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def process_mutes
|
||||||
|
import_rows.each do |row|
|
||||||
|
begin
|
||||||
|
target_account = FollowRemoteAccountService.new.call(row.first)
|
||||||
|
next if target_account.nil?
|
||||||
|
MuteService.new.call(from_account, target_account)
|
||||||
|
rescue Goldfinger::Error, HTTP::Error, OpenSSL::SSL::SSLError
|
||||||
|
next
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def process_blocks
|
def process_blocks
|
||||||
import_rows.each do |row|
|
import_rows.each do |row|
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -76,6 +76,7 @@ en:
|
||||||
x_seconds: "%{count}s"
|
x_seconds: "%{count}s"
|
||||||
exports:
|
exports:
|
||||||
blocks: You block
|
blocks: You block
|
||||||
|
mutes: You mute
|
||||||
csv: CSV
|
csv: CSV
|
||||||
follows: You follow
|
follows: You follow
|
||||||
storage: Media storage
|
storage: Media storage
|
||||||
|
@ -92,6 +93,7 @@ en:
|
||||||
types:
|
types:
|
||||||
blocking: Blocking list
|
blocking: Blocking list
|
||||||
following: Following list
|
following: Following list
|
||||||
|
muting: Muting list
|
||||||
upload: Upload
|
upload: Upload
|
||||||
landing_strip_html: <strong>%{name}</strong> is a user on <strong>%{domain}</strong>. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can <a href="%{sign_up_path}">sign up here</a>.
|
landing_strip_html: <strong>%{name}</strong> is a user on <strong>%{domain}</strong>. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can <a href="%{sign_up_path}">sign up here</a>.
|
||||||
media_attachments:
|
media_attachments:
|
||||||
|
|
|
@ -57,6 +57,7 @@ Rails.application.routes.draw do
|
||||||
namespace :exports, constraints: { format: :csv } do
|
namespace :exports, constraints: { format: :csv } do
|
||||||
resources :follows, only: :index, controller: :following_accounts
|
resources :follows, only: :index, controller: :following_accounts
|
||||||
resources :blocks, only: :index, controller: :blocked_accounts
|
resources :blocks, only: :index, controller: :blocked_accounts
|
||||||
|
resources :mutes, only: :index, controller: :muted_accounts
|
||||||
end
|
end
|
||||||
|
|
||||||
resource :two_factor_auth, only: [:show, :new, :create] do
|
resource :two_factor_auth, only: [:show, :new, :create] do
|
||||||
|
|
|
@ -11,7 +11,7 @@ describe Settings::Exports::BlockedAccountsController do
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
expect(response.content_type).to eq 'text/csv'
|
expect(response.content_type).to eq 'text/csv'
|
||||||
expect(response.headers['Content-Disposition']).to eq 'attachment; filename="blocking.csv"'
|
expect(response.headers['Content-Disposition']).to eq 'attachment; filename="blocked_accounts.csv"'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ describe Settings::Exports::FollowingAccountsController do
|
||||||
|
|
||||||
expect(response).to have_http_status(:success)
|
expect(response).to have_http_status(:success)
|
||||||
expect(response.content_type).to eq 'text/csv'
|
expect(response.content_type).to eq 'text/csv'
|
||||||
expect(response.headers['Content-Disposition']).to eq 'attachment; filename="following.csv"'
|
expect(response.headers['Content-Disposition']).to eq 'attachment; filename="following_accounts.csv"'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
describe Settings::Exports::MutedAccountsController do
|
||||||
|
before do
|
||||||
|
sign_in Fabricate(:user), scope: :user
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'GET #index' do
|
||||||
|
it 'returns a csv of the muting accounts' do
|
||||||
|
get :index, format: :csv
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
expect(response.content_type).to eq 'text/csv'
|
||||||
|
expect(response.headers['Content-Disposition']).to eq 'attachment; filename="muted_accounts.csv"'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Reference in New Issue