2016-12-13 21:42:10 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-11 04:27:03 +09:00
|
|
|
module Admin
|
|
|
|
class DomainBlocksController < BaseController
|
2019-08-08 03:20:23 +09:00
|
|
|
before_action :set_domain_block, only: [:show, :destroy, :edit, :update]
|
2017-05-07 00:03:34 +09:00
|
|
|
|
2022-05-17 01:26:49 +09:00
|
|
|
def batch
|
2022-07-05 18:57:30 +09:00
|
|
|
authorize :domain_block, :create?
|
2022-05-17 01:26:49 +09:00
|
|
|
@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
|
|
|
|
|
2017-04-11 04:27:03 +09:00
|
|
|
def new
|
2017-11-12 04:23:33 +09:00
|
|
|
authorize :domain_block, :create?
|
2019-01-08 21:39:49 +09:00
|
|
|
@domain_block = DomainBlock.new(domain: params[:_domain])
|
2017-04-11 04:27:03 +09:00
|
|
|
end
|
2017-04-04 01:55:06 +09:00
|
|
|
|
2019-08-08 03:20:23 +09:00
|
|
|
def edit
|
|
|
|
authorize :domain_block, :create?
|
|
|
|
end
|
|
|
|
|
2017-04-11 04:27:03 +09:00
|
|
|
def create
|
2017-11-12 04:23:33 +09:00
|
|
|
authorize :domain_block, :create?
|
|
|
|
|
2017-04-11 04:27:03 +09:00
|
|
|
@domain_block = DomainBlock.new(resource_params)
|
2019-06-22 07:13:10 +09:00
|
|
|
existing_domain_block = resource_params[:domain].present? ? DomainBlock.rule_for(resource_params[:domain]) : nil
|
2017-04-04 01:55:06 +09:00
|
|
|
|
2019-05-04 03:36:36 +09:00
|
|
|
if existing_domain_block.present? && !@domain_block.stricter_than?(existing_domain_block)
|
|
|
|
@domain_block.save
|
2019-07-20 06:13:21 +09:00
|
|
|
flash.now[:alert] = I18n.t('admin.domain_blocks.existing_domain_block_html', name: existing_domain_block.domain, unblock_url: admin_domain_block_path(existing_domain_block)).html_safe # rubocop:disable Rails/OutputSafety
|
2021-03-19 10:45:34 +09:00
|
|
|
@domain_block.errors.delete(:domain)
|
2017-04-19 22:37:42 +09:00
|
|
|
render :new
|
2019-05-04 03:36:36 +09:00
|
|
|
else
|
|
|
|
if existing_domain_block.present?
|
|
|
|
@domain_block = existing_domain_block
|
|
|
|
@domain_block.update(resource_params)
|
|
|
|
end
|
2020-12-14 17:06:34 +09:00
|
|
|
|
2019-05-04 03:36:36 +09:00
|
|
|
if @domain_block.save
|
|
|
|
DomainBlockWorker.perform_async(@domain_block.id)
|
|
|
|
log_action :create, @domain_block
|
|
|
|
redirect_to admin_instances_path(limited: '1'), notice: I18n.t('admin.domain_blocks.created_msg')
|
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
2017-04-11 04:27:03 +09:00
|
|
|
end
|
2017-04-04 01:55:06 +09:00
|
|
|
end
|
|
|
|
|
2019-08-08 03:20:23 +09:00
|
|
|
def update
|
2020-12-14 17:06:34 +09:00
|
|
|
authorize :domain_block, :update?
|
2019-08-08 03:20:23 +09:00
|
|
|
|
|
|
|
@domain_block.update(update_params)
|
|
|
|
|
|
|
|
severity_changed = @domain_block.severity_changed?
|
|
|
|
|
|
|
|
if @domain_block.save
|
|
|
|
DomainBlockWorker.perform_async(@domain_block.id, severity_changed)
|
2020-12-14 17:06:34 +09:00
|
|
|
log_action :update, @domain_block
|
2019-08-08 03:20:23 +09:00
|
|
|
redirect_to admin_instances_path(limited: '1'), notice: I18n.t('admin.domain_blocks.created_msg')
|
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-16 19:51:30 +09:00
|
|
|
def destroy
|
2017-11-12 04:23:33 +09:00
|
|
|
authorize @domain_block, :destroy?
|
2019-05-15 02:05:02 +09:00
|
|
|
UnblockDomainService.new.call(@domain_block)
|
2017-11-24 10:05:53 +09:00
|
|
|
log_action :destroy, @domain_block
|
2019-01-08 21:39:49 +09:00
|
|
|
redirect_to admin_instances_path(limited: '1'), notice: I18n.t('admin.domain_blocks.destroyed_msg')
|
2017-04-16 19:51:30 +09:00
|
|
|
end
|
|
|
|
|
2017-04-11 04:27:03 +09:00
|
|
|
private
|
2017-04-04 01:55:06 +09:00
|
|
|
|
2017-05-07 00:03:34 +09:00
|
|
|
def set_domain_block
|
|
|
|
@domain_block = DomainBlock.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2019-08-08 03:20:23 +09:00
|
|
|
def update_params
|
2020-12-18 16:30:41 +09:00
|
|
|
params.require(:domain_block).permit(:severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate)
|
2019-08-08 03:20:23 +09:00
|
|
|
end
|
|
|
|
|
2017-04-11 04:27:03 +09:00
|
|
|
def resource_params
|
2020-12-18 16:30:41 +09:00
|
|
|
params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_reports, :private_comment, :public_comment, :obfuscate)
|
2017-04-30 07:25:38 +09:00
|
|
|
end
|
2022-05-17 01:26:49 +09:00
|
|
|
|
|
|
|
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
|
2016-12-13 21:42:10 +09:00
|
|
|
end
|
|
|
|
end
|