You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

  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