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
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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?
|
||||
@import = Admin::Import.new(import_params)
|
||||
parse_import_data!(export_headers)
|
||||
|
||||
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')
|
||||
@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
|
||||
|
||||
@@ -102,6 +102,12 @@ ready(() => {
|
||||
const registrationMode = document.getElementById('form_admin_settings_registrations_mode');
|
||||
if (registrationMode) onChangeRegistrationMode(registrationMode);
|
||||
|
||||
const checkAllElement = document.querySelector('#batch_checkbox_all');
|
||||
if (checkAllElement) {
|
||||
checkAllElement.checked = [].every.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked);
|
||||
checkAllElement.indeterminate = !checkAllElement.checked && [].some.call(document.querySelectorAll(batchCheckboxClassName), (content) => content.checked);
|
||||
}
|
||||
|
||||
document.querySelector('a#add-instance-button')?.addEventListener('click', (e) => {
|
||||
const domain = document.getElementById('by_domain')?.value;
|
||||
|
||||
|
||||
35
app/models/form/domain_block_batch.rb
Normal file
35
app/models/form/domain_block_batch.rb
Normal file
@@ -0,0 +1,35 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Form::DomainBlockBatch
|
||||
include ActiveModel::Model
|
||||
include Authorization
|
||||
include AccountableConcern
|
||||
|
||||
attr_accessor :domain_blocks_attributes, :action, :current_account
|
||||
|
||||
def save
|
||||
case action
|
||||
when 'save'
|
||||
save!
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def domain_blocks
|
||||
@domain_blocks ||= domain_blocks_attributes.values.filter_map do |attributes|
|
||||
DomainBlock.new(attributes.without('enabled')) if ActiveModel::Type::Boolean.new.cast(attributes['enabled'])
|
||||
end
|
||||
end
|
||||
|
||||
def save!
|
||||
domain_blocks.each do |domain_block|
|
||||
authorize(domain_block, :create?)
|
||||
next if DomainBlock.rule_for(domain_block.domain).present?
|
||||
|
||||
domain_block.save!
|
||||
DomainBlockWorker.perform_async(domain_block.id)
|
||||
log_action :create, domain_block
|
||||
end
|
||||
end
|
||||
end
|
||||
27
app/views/admin/export_domain_blocks/_domain_block.html.haml
Normal file
27
app/views/admin/export_domain_blocks/_domain_block.html.haml
Normal file
@@ -0,0 +1,27 @@
|
||||
- existing_relationships ||= false
|
||||
|
||||
.batch-table__row{ class: [existing_relationships && 'batch-table__row--attention'] }
|
||||
%label.batch-table__row__select.batch-table__row__select--aligned.batch-checkbox
|
||||
= f.check_box :enabled, checked: !existing_relationships
|
||||
.batch-table__row__content.pending-account
|
||||
.pending-account__header
|
||||
%strong
|
||||
= f.object.domain
|
||||
= f.hidden_field :domain
|
||||
= f.hidden_field :severity
|
||||
= f.hidden_field :reject_media
|
||||
= f.hidden_field :reject_reports
|
||||
= f.hidden_field :obfuscate
|
||||
= f.hidden_field :private_comment
|
||||
= f.hidden_field :public_comment
|
||||
|
||||
%br/
|
||||
|
||||
= f.object.policies.map { |policy| t(policy, scope: 'admin.instances.content_policies.policies') }.join(' • ')
|
||||
- if f.object.public_comment.present?
|
||||
•
|
||||
= f.object.public_comment
|
||||
- if existing_relationships
|
||||
•
|
||||
= fa_icon 'warning fw'
|
||||
= t('admin.export_domain_blocks.import.existing_relationships_warning')
|
||||
21
app/views/admin/export_domain_blocks/import.html.haml
Normal file
21
app/views/admin/export_domain_blocks/import.html.haml
Normal file
@@ -0,0 +1,21 @@
|
||||
- content_for :page_title do
|
||||
= t('admin.export_domain_blocks.import.title')
|
||||
|
||||
%p= t('admin.export_domain_blocks.import.description_html')
|
||||
|
||||
- if defined?(@global_private_comment) && @global_private_comment.present?
|
||||
%p= t('admin.export_domain_blocks.import.private_comment_description_html', comment: @global_private_comment)
|
||||
|
||||
= form_for(@form, url: batch_admin_domain_blocks_path) do |f|
|
||||
.batch-table
|
||||
.batch-table__toolbar
|
||||
%label.batch-table__toolbar__select.batch-checkbox-all
|
||||
= check_box_tag :batch_checkbox_all, nil, false
|
||||
.batch-table__toolbar__actions
|
||||
= f.button safe_join([fa_icon('copy'), t('admin.domain_blocks.import')]), name: :save, class: 'table-action-link', type: :submit, data: { confirm: t('admin.reports.are_you_sure') }
|
||||
.batch-table__body
|
||||
- if @domain_blocks.empty?
|
||||
= nothing_here 'nothing-here--under-tabs'
|
||||
- else
|
||||
= f.simple_fields_for :domain_blocks, @domain_blocks do |ff|
|
||||
= render 'domain_block', f: ff, existing_relationships: @warning_domains.include?(ff.object.domain)
|
||||
Reference in New Issue
Block a user