2016-12-13 04:42:10 -08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-10 12:27:03 -07:00
|
|
|
module Admin
|
|
|
|
class DomainBlocksController < BaseController
|
2017-05-06 08:03:34 -07:00
|
|
|
before_action :set_domain_block, only: [:show, :destroy]
|
|
|
|
|
2017-04-10 12:27:03 -07:00
|
|
|
def index
|
2017-11-11 11:23:33 -08:00
|
|
|
authorize :domain_block, :index?
|
2017-05-02 11:56:28 -07:00
|
|
|
@domain_blocks = DomainBlock.page(params[:page])
|
2017-04-10 12:27:03 -07:00
|
|
|
end
|
2016-12-13 04:42:10 -08:00
|
|
|
|
2017-04-10 12:27:03 -07:00
|
|
|
def new
|
2017-11-11 11:23:33 -08:00
|
|
|
authorize :domain_block, :create?
|
2017-04-10 12:27:03 -07:00
|
|
|
@domain_block = DomainBlock.new
|
|
|
|
end
|
2017-04-03 09:55:06 -07:00
|
|
|
|
2017-04-10 12:27:03 -07:00
|
|
|
def create
|
2017-11-11 11:23:33 -08:00
|
|
|
authorize :domain_block, :create?
|
|
|
|
|
2017-04-10 12:27:03 -07:00
|
|
|
@domain_block = DomainBlock.new(resource_params)
|
2017-04-03 09:55:06 -07:00
|
|
|
|
2017-04-10 12:27:03 -07:00
|
|
|
if @domain_block.save
|
|
|
|
DomainBlockWorker.perform_async(@domain_block.id)
|
2017-11-23 17:05:53 -08:00
|
|
|
log_action :create, @domain_block
|
2017-04-16 10:37:01 -07:00
|
|
|
redirect_to admin_domain_blocks_path, notice: I18n.t('admin.domain_blocks.created_msg')
|
2017-04-10 12:27:03 -07:00
|
|
|
else
|
2017-04-19 06:37:42 -07:00
|
|
|
render :new
|
2017-04-10 12:27:03 -07:00
|
|
|
end
|
2017-04-03 09:55:06 -07:00
|
|
|
end
|
|
|
|
|
2017-11-11 11:23:33 -08:00
|
|
|
def show
|
|
|
|
authorize @domain_block, :show?
|
|
|
|
end
|
2017-04-16 03:51:30 -07:00
|
|
|
|
|
|
|
def destroy
|
2017-11-11 11:23:33 -08:00
|
|
|
authorize @domain_block, :destroy?
|
2017-04-29 15:25:38 -07:00
|
|
|
UnblockDomainService.new.call(@domain_block, retroactive_unblock?)
|
2017-11-23 17:05:53 -08:00
|
|
|
log_action :destroy, @domain_block
|
2017-04-16 10:37:01 -07:00
|
|
|
redirect_to admin_domain_blocks_path, notice: I18n.t('admin.domain_blocks.destroyed_msg')
|
2017-04-16 03:51:30 -07:00
|
|
|
end
|
|
|
|
|
2017-04-10 12:27:03 -07:00
|
|
|
private
|
2017-04-03 09:55:06 -07:00
|
|
|
|
2017-05-06 08:03:34 -07:00
|
|
|
def set_domain_block
|
|
|
|
@domain_block = DomainBlock.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2017-04-10 12:27:03 -07:00
|
|
|
def resource_params
|
2017-04-16 03:51:30 -07:00
|
|
|
params.require(:domain_block).permit(:domain, :severity, :reject_media, :retroactive)
|
2017-04-10 12:27:03 -07:00
|
|
|
end
|
2017-04-29 15:25:38 -07:00
|
|
|
|
|
|
|
def retroactive_unblock?
|
2017-05-06 08:03:34 -07:00
|
|
|
ActiveRecord::Type.lookup(:boolean).cast(resource_params[:retroactive])
|
2017-04-29 15:25:38 -07:00
|
|
|
end
|
2016-12-13 04:42:10 -08:00
|
|
|
end
|
|
|
|
end
|