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.

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