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.

54 lines
1.3 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. authorize :domain_block, :index?
  7. @domain_blocks = DomainBlock.page(params[:page])
  8. end
  9. def new
  10. authorize :domain_block, :create?
  11. @domain_block = DomainBlock.new
  12. end
  13. def create
  14. authorize :domain_block, :create?
  15. @domain_block = DomainBlock.new(resource_params)
  16. if @domain_block.save
  17. DomainBlockWorker.perform_async(@domain_block.id)
  18. redirect_to admin_domain_blocks_path, notice: I18n.t('admin.domain_blocks.created_msg')
  19. else
  20. render :new
  21. end
  22. end
  23. def show
  24. authorize @domain_block, :show?
  25. end
  26. def destroy
  27. authorize @domain_block, :destroy?
  28. UnblockDomainService.new.call(@domain_block, retroactive_unblock?)
  29. redirect_to admin_domain_blocks_path, notice: I18n.t('admin.domain_blocks.destroyed_msg')
  30. end
  31. private
  32. def set_domain_block
  33. @domain_block = DomainBlock.find(params[:id])
  34. end
  35. def resource_params
  36. params.require(:domain_block).permit(:domain, :severity, :reject_media, :retroactive)
  37. end
  38. def retroactive_unblock?
  39. ActiveRecord::Type.lookup(:boolean).cast(resource_params[:retroactive])
  40. end
  41. end
  42. end