diff --git a/.reek b/.reek index 117b97186..aaf662290 100644 --- a/.reek +++ b/.reek @@ -145,7 +145,6 @@ DuplicateMethodCall: - Admin::DomainsController#build_associations - Admin::DomainsController#index - Admin::DomainsController#normalize_search_parameters - - Admin::DomainsController#schedule_force_delete - Admin::EppLogsController#index - Admin::EppLogsController#set_default_dates - Admin::LegalDocumentsController#show @@ -624,7 +623,6 @@ TooManyStatements: - Admin::DomainVersionsController#show - Admin::DomainsController#index - Admin::DomainsController#normalize_search_parameters - - Admin::DomainsController#schedule_force_delete - Admin::DomainsController#update - Admin::EppLogsController#index - Admin::InvoicesController#create diff --git a/app/controllers/admin/domains/force_delete_controller.rb b/app/controllers/admin/domains/force_delete_controller.rb new file mode 100644 index 000000000..5d72739d5 --- /dev/null +++ b/app/controllers/admin/domains/force_delete_controller.rb @@ -0,0 +1,39 @@ +module Admin + module Domains + class ForceDeleteController < BaseController + def create + authorize! :manage, domain + + domain.transaction do + domain.schedule_force_delete + domain.registrar.messages.create!(body: t('force_delete_set_on_domain', domain_name: domain.name)) + + if notify_by_email? + DomainDeleteMailer.forced(domain: domain, + registrar: domain.registrar, + registrant: domain.registrant, + template_name: params[:template_name]).deliver_now + end + end + + redirect_to edit_admin_domain_url(domain), notice: t('.scheduled') + end + + def destroy + authorize! :manage, domain + domain.cancel_force_delete + redirect_to edit_admin_domain_url(domain), notice: t('.cancelled') + end + + private + + def domain + @domain ||= Domain.find(params[:domain_id]) + end + + def notify_by_email? + ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:notify_by_email]) + end + end + end +end diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index 66bc615c5..576b5f8e1 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -62,34 +62,6 @@ module Admin end end - def schedule_force_delete - raise 'Template param cannot be empty' if params[:template_name].blank? - - @domain.transaction do - @domain.schedule_force_delete - @domain.registrar.messages.create!(body: I18n.t('force_delete_set_on_domain', domain_name: @domain.name)) - - if notify_by_email? - DomainDeleteMailer.forced(domain: @domain, - registrar: @domain.registrar, - registrant: @domain.registrant, - template_name: params[:template_name]).deliver_now - end - end - - redirect_to edit_admin_domain_url(@domain), notice: t('.scheduled') - end - - def cancel_force_delete - if @domain.cancel_force_delete - flash[:notice] = t('.cancelled') - else - flash.now[:alert] = I18n.t('failed_to_update_domain') - end - - redirect_to edit_admin_domain_url(@domain) - end - def versions @domain = Domain.where(id: params[:domain_id]).includes({ versions: :item }).first @versions = @domain.versions @@ -138,9 +110,5 @@ module Admin def force_delete_templates %w(removed_company death) end - - def notify_by_email? - ActiveRecord::Type::Boolean.new.type_cast_from_user(params[:notify_by_email]) - end end end diff --git a/app/presenters/domain_presenter.rb b/app/presenters/domain_presenter.rb index 11a066b7a..473155734 100644 --- a/app/presenters/domain_presenter.rb +++ b/app/presenters/domain_presenter.rb @@ -49,8 +49,8 @@ class DomainPresenter ) else view.link_to(view.t('admin.domains.force_delete_toggle_btn.cancel'), - view.cancel_force_delete_admin_domain_path(domain), - method: :patch, + view.admin_domain_force_delete_path(domain), + method: :delete, data: { confirm: view.t('admin.domains.force_delete_toggle_btn.cancel_confim') }, class: 'btn btn-primary') end diff --git a/app/views/admin/domains/_force_delete_dialog.html.erb b/app/views/admin/domains/_force_delete_dialog.html.erb index d5863e0de..4e68302f8 100644 --- a/app/views/admin/domains/_force_delete_dialog.html.erb +++ b/app/views/admin/domains/_force_delete_dialog.html.erb @@ -10,8 +10,8 @@