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.

56 lines
1.4 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. log_action :create, @domain_block
  19. redirect_to admin_domain_blocks_path, notice: I18n.t('admin.domain_blocks.created_msg')
  20. else
  21. render :new
  22. end
  23. end
  24. def show
  25. authorize @domain_block, :show?
  26. end
  27. def destroy
  28. authorize @domain_block, :destroy?
  29. UnblockDomainService.new.call(@domain_block, retroactive_unblock?)
  30. log_action :destroy, @domain_block
  31. redirect_to admin_domain_blocks_path, notice: I18n.t('admin.domain_blocks.destroyed_msg')
  32. end
  33. private
  34. def set_domain_block
  35. @domain_block = DomainBlock.find(params[:id])
  36. end
  37. def resource_params
  38. params.require(:domain_block).permit(:domain, :severity, :reject_media, :retroactive)
  39. end
  40. def retroactive_unblock?
  41. ActiveRecord::Type.lookup(:boolean).cast(resource_params[:retroactive])
  42. end
  43. end
  44. end