domain_blocks_controller.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # frozen_string_literal: true
  2. module Admin
  3. class DomainBlocksController < BaseController
  4. before_action :set_domain_block, only: [:show, :destroy]
  5. def index
  6. @domain_blocks = DomainBlock.page(params[:page])
  7. end
  8. def new
  9. @domain_block = DomainBlock.new
  10. end
  11. def create
  12. @domain_block = DomainBlock.new(resource_params)
  13. if @domain_block.save
  14. DomainBlockWorker.perform_async(@domain_block.id)
  15. redirect_to admin_domain_blocks_path, notice: I18n.t('admin.domain_blocks.created_msg')
  16. else
  17. render :new
  18. end
  19. end
  20. def show; end
  21. def destroy
  22. UnblockDomainService.new.call(@domain_block, retroactive_unblock?)
  23. redirect_to admin_domain_blocks_path, notice: I18n.t('admin.domain_blocks.destroyed_msg')
  24. end
  25. private
  26. def set_domain_block
  27. @domain_block = DomainBlock.find(params[:id])
  28. end
  29. def resource_params
  30. params.require(:domain_block).permit(:domain, :severity, :reject_media, :retroactive)
  31. end
  32. def retroactive_unblock?
  33. ActiveRecord::Type.lookup(:boolean).cast(resource_params[:retroactive])
  34. end
  35. end
  36. end