diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-05-16 18:26:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-16 18:26:49 +0200 |
commit | b91196f4b73fff91997b8077619ae25b6d04a59e (patch) | |
tree | 9d52a2fbed1170b5180540878ff4fa9292ad3ff1 /app/controllers | |
parent | 3a084113067656ef9318b9fb5bcfea4fd2de6ffe (diff) |
Add confirmation page when importing blocked domains (#1773)
* Move glitch-soc-specific strings to glitch-soc-specific locale files * Add confirmation page when importing blocked domains
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/admin/domain_blocks_controller.rb | 21 | ||||
-rw-r--r-- | app/controllers/admin/export_domain_blocks_controller.rb | 49 |
2 files changed, 47 insertions, 23 deletions
diff --git a/app/controllers/admin/domain_blocks_controller.rb b/app/controllers/admin/domain_blocks_controller.rb index 16defc1ea..48e9781d6 100644 --- a/app/controllers/admin/domain_blocks_controller.rb +++ b/app/controllers/admin/domain_blocks_controller.rb @@ -4,6 +4,17 @@ module Admin class DomainBlocksController < BaseController before_action :set_domain_block, only: [:show, :destroy, :edit, :update] + def batch + @form = Form::DomainBlockBatch.new(form_domain_block_batch_params.merge(current_account: current_account, action: action_from_button)) + @form.save + rescue ActionController::ParameterMissing + flash[:alert] = I18n.t('admin.email_domain_blocks.no_domain_block_selected') + rescue Mastodon::NotPermittedError + flash[:alert] = I18n.t('admin.domain_blocks.created_msg') + else + redirect_to admin_instances_path(limited: '1'), notice: I18n.t('admin.domain_blocks.created_msg') + end + def new authorize :domain_block, :create? @domain_block = DomainBlock.new(domain: params[:_domain]) @@ -76,5 +87,15 @@ module Admin def resource_params params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate) end + + def form_domain_block_batch_params + params.require(:form_domain_block_batch).permit(domain_blocks_attributes: [:enabled, :domain, :severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate]) + end + + def action_from_button + if params[:save] + 'save' + end + end end end diff --git a/app/controllers/admin/export_domain_blocks_controller.rb b/app/controllers/admin/export_domain_blocks_controller.rb index 0ad5b92b5..db8863551 100644 --- a/app/controllers/admin/export_domain_blocks_controller.rb +++ b/app/controllers/admin/export_domain_blocks_controller.rb @@ -21,30 +21,33 @@ module Admin def import authorize :domain_block, :create? - begin - @import = Admin::Import.new(import_params) - parse_import_data!(export_headers) - - @data.take(ROWS_PROCESSING_LIMIT).each do |row| - domain = row['#domain'].strip - next if DomainBlock.rule_for(domain).present? - - domain_block = DomainBlock.new(domain: domain, - severity: row['#severity'].strip, - reject_media: row['#reject_media'].strip, - reject_reports: row['#reject_reports'].strip, - public_comment: row['#public_comment'].strip, - obfuscate: row['#obfuscate'].strip) - if domain_block.save - DomainBlockWorker.perform_async(domain_block.id) - log_action :create, domain_block - end - end - flash[:notice] = I18n.t('admin.domain_blocks.created_msg') - rescue ActionController::ParameterMissing - flash[:error] = I18n.t('admin.export_domain_blocks.no_file') + + @import = Admin::Import.new(import_params) + parse_import_data!(export_headers) + + @global_private_comment = I18n.t('admin.export_domain_blocks.import.private_comment_template', source: @import.data_file_name, date: I18n.l(Time.now.utc)) + + @form = Form::DomainBlockBatch.new + @domain_blocks = @data.take(ROWS_PROCESSING_LIMIT).filter_map do |row| + domain = row['#domain'].strip + next if DomainBlock.rule_for(domain).present? + + domain_block = DomainBlock.new(domain: domain, + severity: row['#severity'].strip, + reject_media: row['#reject_media'].strip, + reject_reports: row['#reject_reports'].strip, + private_comment: @global_private_comment, + public_comment: row['#public_comment']&.strip, + obfuscate: row['#obfuscate'].strip) + + domain_block if domain_block.valid? end - redirect_to admin_instances_path(limited: '1') + + @warning_domains = Instance.where(domain: @domain_blocks.map(&:domain)).where('EXISTS (SELECT 1 FROM follows JOIN accounts ON follows.account_id = accounts.id OR follows.target_account_id = accounts.id WHERE accounts.domain = instances.domain)').pluck(:domain) + rescue ActionController::ParameterMissing + flash.now[:alert] = I18n.t('admin.export_domain_blocks.no_file') + set_dummy_import! + render :new end private |