diff --git a/app/controllers/admin/export_domain_blocks_controller.rb b/app/controllers/admin/export_domain_blocks_controller.rb index 9caafd9684fef6..205b2c032f1c6b 100644 --- a/app/controllers/admin/export_domain_blocks_controller.rb +++ b/app/controllers/admin/export_domain_blocks_controller.rb @@ -36,7 +36,18 @@ def import reject_reports: row.fetch('#reject_reports', false), private_comment: @global_private_comment, public_comment: row['#public_comment'], - obfuscate: row.fetch('#obfuscate', false)) + obfuscate: row.fetch('#obfuscate', false), + reject_favourite: row.fetch('#reject_favourite', false), + reject_reply: row.fetch('#reject_reply', false), + reject_send_sensitive: row.fetch('#reject_send_sensitive', false), + reject_hashtag: row.fetch('#reject_hashtag', false), + reject_straight_follow: row.fetch('#reject_straight_follow', false), + reject_new_follow: row.fetch('#reject_new_follow', false), + hidden: row.fetch('#hidden', false), + detect_invalid_subscription: row.fetch('#detect_invalid_subscription', false), + reject_reply_exclude_followers: row.fetch('#reject_reply_exclude_followers', false), + reject_friend: row.fetch('#reject_friend', false), + block_trends: row.fetch('#block_trends', false)) if domain_block.invalid? flash.now[:alert] = I18n.t('admin.export_domain_blocks.invalid_domain_block', error: domain_block.errors.full_messages.join(', ')) @@ -67,13 +78,49 @@ def export_filename end def export_headers - %w(#domain #severity #reject_media #reject_reports #public_comment #obfuscate) + %w( + #domain + #severity + #reject_media + #reject_reports + #public_comment + #obfuscate + #reject_favourite + #reject_reply + #reject_send_sensitive + #reject_hashtag + #reject_straight_follow + #reject_new_follow + #hidden + #detect_invalid_subscription + #reject_reply_exclude_followers + #reject_friend + #block_trends + ) end def export_data CSV.generate(headers: export_headers, write_headers: true) do |content| DomainBlock.with_limitations.order(id: :asc).each do |instance| - content << [instance.domain, instance.severity, instance.reject_media, instance.reject_reports, instance.public_comment, instance.obfuscate] + content << [ + instance.domain, + instance.severity, + instance.reject_media, + instance.reject_reports, + instance.public_comment, + instance.obfuscate, + instance.reject_favourite, + instance.reject_reply, + instance.reject_send_sensitive, + instance.reject_hashtag, + instance.reject_straight_follow, + instance.reject_new_follow, + instance.hidden, + instance.detect_invalid_subscription, + instance.reject_reply_exclude_followers, + instance.reject_friend, + instance.block_trends, + ] end end end diff --git a/app/models/admin/import.rb b/app/models/admin/import.rb index c94afe6c623360..90db439a5d7e2d 100644 --- a/app/models/admin/import.rb +++ b/app/models/admin/import.rb @@ -34,7 +34,9 @@ def csv_data field&.strip when '#severity' field&.strip&.to_sym - when '#reject_media', '#reject_favourite', '#reject_reply', '#reject_reports', '#obfuscate' + when '#reject_media', '#reject_reports', '#obfuscate', '#reject_favourite', '#reject_reply', '#reject_send_sensitive', + '#reject_hashtag', '#reject_straight_follow', '#reject_new_follow', '#hidden', '#detect_invalid_subscription', + '#reject_reply_exclude_followers', '#reject_friend', '#block_trends' ActiveModel::Type::Boolean.new.cast(field) else field diff --git a/spec/controllers/admin/export_domain_blocks_controller_spec.rb b/spec/controllers/admin/export_domain_blocks_controller_spec.rb index bfcccfa06cf595..b4e60e55a937a7 100644 --- a/spec/controllers/admin/export_domain_blocks_controller_spec.rb +++ b/spec/controllers/admin/export_domain_blocks_controller_spec.rb @@ -22,6 +22,7 @@ Fabricate(:domain_block, domain: 'bad.domain', severity: 'silence', public_comment: 'bad server') Fabricate(:domain_block, domain: 'worse.domain', severity: 'suspend', reject_media: true, reject_reports: true, public_comment: 'worse server', obfuscate: true) Fabricate(:domain_block, domain: 'reject.media', severity: 'noop', reject_media: true, public_comment: 'reject media and test unicode characters ♥') + Fabricate(:domain_block, domain: 'little.spam', severity: 'noop', public_comment: 'has some spams', reject_favourite: true, reject_reply: true, reject_straight_follow: true) Fabricate(:domain_block, domain: 'no.op', severity: 'noop', public_comment: 'noop') get :export, params: { format: :csv } @@ -43,7 +44,16 @@ def domain_blocks_csv_file end it 'renders page with expected domain blocks' do - expect(assigns(:domain_blocks).map { |block| [block.domain, block.severity.to_sym] }).to contain_exactly(['bad.domain', :silence], ['worse.domain', :suspend], ['reject.media', :noop]) + expect(assigns(:domain_blocks).map { |block| [block.domain, block.severity.to_sym] }).to contain_exactly(['bad.domain', :silence], ['worse.domain', :suspend], ['reject.media', :noop], ['little.spam', :noop]) + end + + it 'renders page with extended domain blocks' do + expect(assigns(:domain_blocks).map { |block| [block.domain, block.reject_favourite, block.reject_reply, block.reject_friend] }).to contain_exactly( + ['bad.domain', false, false, false], + ['worse.domain', false, false, false], + ['reject.media', false, false, false], + ['little.spam', true, true, false] + ) end it 'returns http success' do diff --git a/spec/fixtures/files/domain_blocks.csv b/spec/fixtures/files/domain_blocks.csv index 9dbfb4eaf7b065..066e6b7d985909 100644 --- a/spec/fixtures/files/domain_blocks.csv +++ b/spec/fixtures/files/domain_blocks.csv @@ -1,4 +1,5 @@ -#domain,#severity,#reject_media,#reject_reports,#public_comment,#obfuscate -bad.domain,silence,false,false,bad server,false -worse.domain,suspend,true,true,worse server,true -reject.media,noop,true,false,reject media and test unicode characters ♥,false +#domain,#severity,#reject_media,#reject_reports,#public_comment,#obfuscate,#reject_favourite,#reject_reply,#reject_send_sensitive,#reject_hashtag,#reject_straight_follow,#reject_new_follow,#hidden,#detect_invalid_subscription,#reject_reply_exclude_followers,#reject_friend,#block_trends +bad.domain,silence,false,false,bad server,false,false,false,false,false,false,false,false,false,false,false,false +worse.domain,suspend,true,true,worse server,true,false,false,false,false,false,false,false,false,false,false,false +reject.media,noop,true,false,reject media and test unicode characters ♥,false,false,false,false,false,false,false,false,false,false,false,false +little.spam,noop,false,false,has some spams,false,true,true,false,false,true,false,false,false,false,false,false diff --git a/spec/models/form/import_spec.rb b/spec/models/form/import_spec.rb index 872697485ed269..b4b5bbf8976856 100644 --- a/spec/models/form/import_spec.rb +++ b/spec/models/form/import_spec.rb @@ -291,7 +291,7 @@ it_behaves_like 'on successful import', 'blocking', 'merge', 'imports.txt', (%w(user@example.com user@test.com).map { |acct| { 'acct' => acct } }) it_behaves_like 'on successful import', 'blocking', 'overwrite', 'imports.txt', (%w(user@example.com user@test.com).map { |acct| { 'acct' => acct } }) it_behaves_like 'on successful import', 'muting', 'merge', 'imports.txt', (%w(user@example.com user@test.com).map { |acct| { 'acct' => acct } }) - it_behaves_like 'on successful import', 'domain_blocking', 'merge', 'domain_blocks.csv', (%w(bad.domain worse.domain reject.media).map { |domain| { 'domain' => domain } }) + it_behaves_like 'on successful import', 'domain_blocking', 'merge', 'domain_blocks.csv', (%w(bad.domain worse.domain reject.media little.spam).map { |domain| { 'domain' => domain } }) it_behaves_like 'on successful import', 'bookmarks', 'merge', 'bookmark-imports.txt', (%w(https://example.com/statuses/1312 https://local.com/users/foo/statuses/42 https://unknown-remote.com/users/bar/statuses/1 https://example.com/statuses/direct).map { |uri| { 'uri' => uri } }) it_behaves_like 'on successful import', 'following', 'merge', 'following_accounts.csv', [