2016-12-13 12:42:10 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
module Admin
|
|
|
|
class DomainBlocksController < BaseController
|
2017-05-06 16:03:34 +01:00
|
|
|
before_action :set_domain_block, only: [:show, :destroy]
|
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
def new
|
2017-11-11 19:23:33 +00:00
|
|
|
authorize :domain_block, :create?
|
2019-01-08 12:39:49 +00:00
|
|
|
@domain_block = DomainBlock.new(domain: params[:_domain])
|
2017-04-10 20:27:03 +01:00
|
|
|
end
|
2017-04-03 17:55:06 +01:00
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
def create
|
2017-11-11 19:23:33 +00:00
|
|
|
authorize :domain_block, :create?
|
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
@domain_block = DomainBlock.new(resource_params)
|
2019-05-03 19:36:36 +01:00
|
|
|
existing_domain_block = resource_params[:domain].present? ? DomainBlock.find_by(domain: resource_params[:domain]) : nil
|
2017-04-03 17:55:06 +01:00
|
|
|
|
2019-05-03 19:36:36 +01:00
|
|
|
if existing_domain_block.present? && !@domain_block.stricter_than?(existing_domain_block)
|
|
|
|
@domain_block.save
|
|
|
|
flash[: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
|
|
|
|
@domain_block.errors[:domain].clear
|
2017-04-19 14:37:42 +01:00
|
|
|
render :new
|
2019-05-03 19:36:36 +01:00
|
|
|
else
|
|
|
|
if existing_domain_block.present?
|
|
|
|
@domain_block = existing_domain_block
|
|
|
|
@domain_block.update(resource_params)
|
|
|
|
end
|
|
|
|
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-10 20:27:03 +01:00
|
|
|
end
|
2017-04-03 17:55:06 +01:00
|
|
|
end
|
|
|
|
|
2017-11-11 19:23:33 +00:00
|
|
|
def show
|
|
|
|
authorize @domain_block, :show?
|
|
|
|
end
|
2017-04-16 11:51:30 +01:00
|
|
|
|
|
|
|
def destroy
|
2017-11-11 19:23:33 +00:00
|
|
|
authorize @domain_block, :destroy?
|
2017-04-29 23:25:38 +01:00
|
|
|
UnblockDomainService.new.call(@domain_block, retroactive_unblock?)
|
2017-11-24 01:05:53 +00:00
|
|
|
log_action :destroy, @domain_block
|
2019-01-08 12:39:49 +00:00
|
|
|
redirect_to admin_instances_path(limited: '1'), notice: I18n.t('admin.domain_blocks.destroyed_msg')
|
2017-04-16 11:51:30 +01:00
|
|
|
end
|
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
private
|
2017-04-03 17:55:06 +01:00
|
|
|
|
2017-05-06 16:03:34 +01:00
|
|
|
def set_domain_block
|
|
|
|
@domain_block = DomainBlock.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2017-04-10 20:27:03 +01:00
|
|
|
def resource_params
|
2018-10-20 07:02:44 +01:00
|
|
|
params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_reports, :retroactive)
|
2017-04-10 20:27:03 +01:00
|
|
|
end
|
2017-04-29 23:25:38 +01:00
|
|
|
|
|
|
|
def retroactive_unblock?
|
2017-05-06 16:03:34 +01:00
|
|
|
ActiveRecord::Type.lookup(:boolean).cast(resource_params[:retroactive])
|
2017-04-29 23:25:38 +01:00
|
|
|
end
|
2016-12-13 12:42:10 +00:00
|
|
|
end
|
|
|
|
end
|