diff --git a/app/controllers/registrant/domain_delete_confirms_controller.rb b/app/controllers/registrant/domain_delete_confirms_controller.rb index 6cd0e1392..09e3bff58 100644 --- a/app/controllers/registrant/domain_delete_confirms_controller.rb +++ b/app/controllers/registrant/domain_delete_confirms_controller.rb @@ -1,12 +1,43 @@ class Registrant::DomainDeleteConfirmsController < RegistrantController - skip_before_action :authenticate_user!, only: [:show, :create] - skip_authorization_check only: [:show, :create] + skip_before_action :authenticate_user!, only: [:show, :update] + skip_authorization_check only: [:show, :update] def show + return if params[:confirmed] || params[:rejected] @domain = Domain.find(params[:id]) @domain = nil unless @domain.registrant_delete_confirmable?(params[:token]) end - def create + # # rubocop: disable Metrics/PerceivedComplexity + # # rubocop: disable Metrics/CyclomaticComplexity + def update + @domain = Domain.find(params[:id]) + unless @domain.registrant_delete_confirmable?(params[:token]) + flash[:alert] = t(:registrant_domain_verification_failed) + return render 'show' + end + + @registrant_verification = RegistrantVerification.new(domain_id: @domain.id, + domain_name: @domain.name, + verification_token: params[:token]) + if params[:rejected] + if @registrant_verification.domain_registrant_delete_reject! + flash[:notice] = t(:registrant_domain_verification_rejected) + redirect_to registrant_domain_delete_confirm_path(@domain.id, rejected: true) + else + flash[:alert] = t(:registrant_domain_verification_rejected_failed) + return render 'show' + end + elsif params[:confirmed] + if @registrant_verification.domain_registrant_delete_confirm! + flash[:notice] = t(:registrant_domain_verification_confirmed) + redirect_to registrant_domain_delete_confirm_path(@domain.id, confirmed: true) + else + flash[:alert] = t(:registrant_domain_verification_confirmed_failed) + return render 'show' + end + end end + # rubocop: enable Metrics/PerceivedComplexity + # rubocop: enable Metrics/CyclomaticComplexity end diff --git a/app/jobs/domain_delete_confirm_job.rb b/app/jobs/domain_delete_confirm_job.rb new file mode 100644 index 000000000..90a76e47b --- /dev/null +++ b/app/jobs/domain_delete_confirm_job.rb @@ -0,0 +1,16 @@ +class DomainDeleteConfirmJob < Que::Job + def run(domain_id, action) + # it's recommended to keep transaction against job table as short as possible. + ActiveRecord::Base.transaction do + domain = Epp::Domain.find(domain_id) + case action + when RegistrantVerification::CONFIRMED + domain.apply_pending_delete! + domain.clean_pendings! + when RegistrantVerification::REJECTED + domain.clean_pendings! + end + destroy # it's best to destroy the job in the same transaction + end + end +end diff --git a/app/jobs/domain_confirm_job.rb b/app/jobs/domain_update_confirm_job.rb similarity index 92% rename from app/jobs/domain_confirm_job.rb rename to app/jobs/domain_update_confirm_job.rb index e1f1c0e55..2310eaad4 100644 --- a/app/jobs/domain_confirm_job.rb +++ b/app/jobs/domain_update_confirm_job.rb @@ -1,4 +1,4 @@ -class DomainConfirmJob < Que::Job +class DomainUpdateConfirmJob < Que::Job def run(domain_id, action) # it's recommended to keep transaction against job table as short as possible. ActiveRecord::Base.transaction do diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 0eae3db45..f31042440 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -390,6 +390,15 @@ class Epp::Domain < Domain clean_pendings! if update(frame, user, false) end + def apply_pending_delete! + preclean_pendings + user = ApiUser.find(pending_json['current_user_id']) + frame = Nokogiri::XML(pending_json['frame']) + statuses.delete(DomainStatus::PENDING_DELETE) + + clean_pendings! if epp_destroy(frame, user, false) + end + def attach_legal_document(legal_document_data) return unless legal_document_data @@ -399,10 +408,10 @@ class Epp::Domain < Domain ) end - def epp_destroy(frame, user_id) + def epp_destroy(frame, user_id, verify=true) return false unless valid? - if frame.css('delete').attr('verified').to_s.downcase != 'yes' + if verify && frame.css('delete').attr('verified').to_s.downcase != 'yes' registrant_verification_asked!(frame.to_s, user_id) self.deliver_emails = true # turn on email delivery for epp pending_delete! diff --git a/app/models/registrant_verification.rb b/app/models/registrant_verification.rb index fb7a56839..d0c015ecb 100644 --- a/app/models/registrant_verification.rb +++ b/app/models/registrant_verification.rb @@ -17,12 +17,24 @@ class RegistrantVerification < ActiveRecord::Base def domain_registrant_change_confirm! self.action_type = DOMAIN_REGISTRANT_CHANGE self.action = CONFIRMED - DomainConfirmJob.enqueue domain.id, CONFIRMED if save + DomainUpdateConfirmJob.enqueue domain.id, CONFIRMED if save end def domain_registrant_change_reject! self.action_type = DOMAIN_REGISTRANT_CHANGE self.action = REJECTED - DomainConfirmJob.enqueue domain.id, REJECTED if save + DomainUpdateConfirmJob.enqueue domain.id, REJECTED if save + end + + def domain_registrant_delete_confirm! + self.action_type = DOMAIN_DELETE + self.action = CONFIRMED + DomainDeleteConfirmJob.enqueue domain.id, CONFIRMED if save + end + + def domain_registrant_delete_reject! + self.action_type = DOMAIN_DELETE + self.action = REJECTED + DomainDeleteConfirmJob.enqueue domain.id, REJECTED if save end end diff --git a/app/views/registrant/domain_delete_confirms/show.haml b/app/views/registrant/domain_delete_confirms/show.haml index 0484fc153..fca337844 100644 --- a/app/views/registrant/domain_delete_confirms/show.haml +++ b/app/views/registrant/domain_delete_confirms/show.haml @@ -1,4 +1,44 @@ -- if @domain.present? +- if params[:confirmed].present? + .row + .col-md-12 + %h1= t(:domain_delete_confirmed_title) + .row + .col-md-12 + %p= t(:domain_delete_confirmed_body) +- elsif params[:rejected].present? + .row + .col-md-12 + %h1= t(:domain_delete_rejected_title) + .row + .col-md-12 + %p= t(:domain_delete_rejected_body) - else - %h1= t(:not_valid_domain_verification_title).html_safe - %p= t(:not_valid_domain_verification_body).html_safe + - if @domain.present? + .row + .col-md-12 + %h1= t(:domain_delete_title) + .row + .col-md-12 + %p= t(:domain_delete_body) + + %hr + .row + .col-md-12.text-center.confirmation + .column-keys + %p= t(:domain_name) + ':' + %p= t(:registrant) + ':' + .column-values + %p= @domain.name + %p= "#{@domain.registrant_name} (#{@domain.registrant.ident})" + + .row + .col-md-12.text-center + .confirmation + = form_for registrant_domain_delete_confirm_path(@domain.id), method: :patch do |f| + = hidden_field_tag :token, params[:token] + = f.button t(:confirm_domain_delete), name: 'confirmed', class: 'btn btn-primary' + = f.button t(:reject_domain_delete), name: 'rejected', class: 'btn btn-warning' + %hr + - else + %h1= t(:not_valid_domain_verification_title).html_safe + %p= t(:not_valid_domain_verification_body).html_safe diff --git a/config/locales/en.yml b/config/locales/en.yml index 674df707f..e6faa1420 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -793,14 +793,20 @@ en: new_pending_registrant: 'New registrant' current_registrant: 'Current registrant' registrant_domain_verification_failed: 'Domain verification not available' - domain_registrant_change_confirmed_title: 'Domain owner change has been confirmed' - domain_registrant_change_confirmed_body: 'You have successfully confirmed domain owner change.' - registrant_domain_verification_confirmed: 'Domain owner change has successfully confirmed.' - registrant_domain_verification_confirmed_failed: 'Something went wrong' + domain_registrant_change_confirmed_title: 'Domain owner change has been received' + domain_registrant_change_confirmed_body: 'You have successfully submitted domain owner change confirmation. You will receive email confirmation.' + registrant_domain_verification_confirmed: 'Domain owner change has successfully received.' + registrant_domain_verification_confirmed_failed: 'Something went wrong.' domain_registrant_change_rejected_title: 'Domain owner change has been rejected' domain_registrant_change_rejected_body: 'You have rejected domain owner change.' registrant_domain_verification_rejected: 'Domain owner change has been rejected successfully.' - registrant_domain_verification_rejected_failed: 'Something went wrong' + registrant_domain_verification_rejected_failed: 'Something went wrong.' + domain_delete_title: 'Please confirm or reject domain deletation' + domain_delete_body: 'There is a request to delete a domain. Before doing it we need your confirmation.' + domain_delete_confirmed_title: 'Domain deletion has been received successfully' + domain_delete_confirmed_body: 'You have successfully submitted delete confirmation. You will receive registry final confirmation to email.' + domain_delete_rejected_title: 'Domain deletion has been rejected successfully' + domain_delete_rejected_body: 'You have rejected domain deletion.' ip_is_not_whitelisted: 'IP is not whitelisted' no_permission: 'No permission' access_denied: 'Access denied'