From 22b0d4136815d8fedea855e8e74885ce17b6792c Mon Sep 17 00:00:00 2001 From: dinsmol Date: Fri, 3 Dec 2021 15:07:57 +0300 Subject: [PATCH 01/13] Add rollback statuses --- app/controllers/admin/domains_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index 8a086027b5..3125fe00e6 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -41,6 +41,8 @@ def edit end def update + rollback_history = @domain.json_statuses_history['admin_store_statuses_history'] + rollback_params = ActionController::Parameters.new(statuses: @domain.statuses).permit(:statuses) dp = ignore_empty_statuses @domain.is_admin = true @domain.admin_status_update dp[:statuses] @@ -49,6 +51,8 @@ def update flash[:notice] = I18n.t('domain_updated') redirect_to [:admin, @domain] else + @domain.reload + @domain.admin_status_update rollback_history build_associations flash.now[:alert] = "#{I18n.t('failed_to_update_domain')} #{@domain.errors.full_messages.join(', ')}" render 'edit' From 5e331bef224d3864981e50cbb76ab94475d08902 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 7 Dec 2021 09:38:42 +0300 Subject: [PATCH 02/13] Remove unused code --- app/controllers/admin/domains_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index 3125fe00e6..c912d713a8 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -42,7 +42,6 @@ def edit def update rollback_history = @domain.json_statuses_history['admin_store_statuses_history'] - rollback_params = ActionController::Parameters.new(statuses: @domain.statuses).permit(:statuses) dp = ignore_empty_statuses @domain.is_admin = true @domain.admin_status_update dp[:statuses] From ab3b957d0747cd9a364c482970f5e02bbd55f65e Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 7 Dec 2021 09:54:50 +0300 Subject: [PATCH 03/13] Fix error --- app/controllers/admin/domains_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index c912d713a8..b5ef428dd1 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -41,7 +41,7 @@ def edit end def update - rollback_history = @domain.json_statuses_history['admin_store_statuses_history'] + rollback_history = @domain.json_statuses_history&.[]('admin_store_statuses_history') dp = ignore_empty_statuses @domain.is_admin = true @domain.admin_status_update dp[:statuses] From 7ae814fe5b1c92e3d62f4fc9eb59ef7ac8777077 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 8 Dec 2021 00:17:39 +0300 Subject: [PATCH 04/13] Disable method length metrics --- app/controllers/admin/domains_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index b5ef428dd1..8946b006d0 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -3,6 +3,7 @@ class DomainsController < BaseController before_action :set_domain, only: %i[show edit update keep] authorize_resource + # rubocop:disable Metrics/MethodLength def index params[:q] ||= {} domains = if params[:statuses_contains] @@ -30,6 +31,7 @@ def index render_by_format('admin/domains/index', 'domains') end + # rubocop:enable Metrics/MethodLength def show # Validation is needed to warn users @@ -40,6 +42,7 @@ def edit build_associations end + # rubocop:disable Metrics/MethodLength def update rollback_history = @domain.json_statuses_history&.[]('admin_store_statuses_history') dp = ignore_empty_statuses @@ -57,6 +60,7 @@ def update render 'edit' end end + # rubocop:enable Metrics/MethodLength def versions @domain = Domain.where(id: params[:domain_id]).includes({ versions: :item }).first From 077eb87a4f9cd9849d0d9c89b27d6809653882ae Mon Sep 17 00:00:00 2001 From: dinsmol Date: Fri, 3 Dec 2021 15:07:57 +0300 Subject: [PATCH 05/13] Add rollback statuses --- app/controllers/admin/domains_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index 8a086027b5..3125fe00e6 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -41,6 +41,8 @@ def edit end def update + rollback_history = @domain.json_statuses_history['admin_store_statuses_history'] + rollback_params = ActionController::Parameters.new(statuses: @domain.statuses).permit(:statuses) dp = ignore_empty_statuses @domain.is_admin = true @domain.admin_status_update dp[:statuses] @@ -49,6 +51,8 @@ def update flash[:notice] = I18n.t('domain_updated') redirect_to [:admin, @domain] else + @domain.reload + @domain.admin_status_update rollback_history build_associations flash.now[:alert] = "#{I18n.t('failed_to_update_domain')} #{@domain.errors.full_messages.join(', ')}" render 'edit' From a4222907ab922667e131cc2df7b1209f4b180adb Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 7 Dec 2021 09:38:42 +0300 Subject: [PATCH 06/13] Remove unused code --- app/controllers/admin/domains_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index 3125fe00e6..c912d713a8 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -42,7 +42,6 @@ def edit def update rollback_history = @domain.json_statuses_history['admin_store_statuses_history'] - rollback_params = ActionController::Parameters.new(statuses: @domain.statuses).permit(:statuses) dp = ignore_empty_statuses @domain.is_admin = true @domain.admin_status_update dp[:statuses] From 46fe1a2671968add4be14b96b784f5b3d9951ef3 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Tue, 7 Dec 2021 09:54:50 +0300 Subject: [PATCH 07/13] Fix error --- app/controllers/admin/domains_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index c912d713a8..b5ef428dd1 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -41,7 +41,7 @@ def edit end def update - rollback_history = @domain.json_statuses_history['admin_store_statuses_history'] + rollback_history = @domain.json_statuses_history&.[]('admin_store_statuses_history') dp = ignore_empty_statuses @domain.is_admin = true @domain.admin_status_update dp[:statuses] From 0a715478ebfaf9ab3059b79eebb4241b4277e73c Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 8 Dec 2021 00:17:39 +0300 Subject: [PATCH 08/13] Disable method length metrics --- app/controllers/admin/domains_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index b5ef428dd1..8946b006d0 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -3,6 +3,7 @@ class DomainsController < BaseController before_action :set_domain, only: %i[show edit update keep] authorize_resource + # rubocop:disable Metrics/MethodLength def index params[:q] ||= {} domains = if params[:statuses_contains] @@ -30,6 +31,7 @@ def index render_by_format('admin/domains/index', 'domains') end + # rubocop:enable Metrics/MethodLength def show # Validation is needed to warn users @@ -40,6 +42,7 @@ def edit build_associations end + # rubocop:disable Metrics/MethodLength def update rollback_history = @domain.json_statuses_history&.[]('admin_store_statuses_history') dp = ignore_empty_statuses @@ -57,6 +60,7 @@ def update render 'edit' end end + # rubocop:enable Metrics/MethodLength def versions @domain = Domain.where(id: params[:domain_id]).includes({ versions: :item }).first From 77b9d02b5db744061899a38bc16f79ce9af9bf4d Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 8 Dec 2021 23:03:25 +0300 Subject: [PATCH 09/13] Add tests --- app/models/domain.rb | 2 ++ .../admin_area/domains/force_delete_test.rb | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/app/models/domain.rb b/app/models/domain.rb index 5e8a284d53..f5372e29bd 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -592,6 +592,8 @@ def update_not_by_locked_statuses(update) def admin_status_update(update) update_unless_locked_by_registrant(update) update_not_by_locked_statuses(update) + return unless update + # check for deleted status statuses.each do |s| unless update.include? s diff --git a/test/system/admin_area/domains/force_delete_test.rb b/test/system/admin_area/domains/force_delete_test.rb index 3ddd0b2677..81029e1806 100644 --- a/test/system/admin_area/domains/force_delete_test.rb +++ b/test/system/admin_area/domains/force_delete_test.rb @@ -21,6 +21,31 @@ def test_schedules_domain_force_delete assert_text 'Force delete procedure has been scheduled' end + def test_schedules_domain_force_delete_two + refute @domain.force_delete_scheduled? + + visit edit_admin_domain_url(@domain) + click_link_or_button 'Force delete domain' + @domain.reload + + assert @domain.force_delete_scheduled? + assert_current_path edit_admin_domain_path(@domain) + assert_text 'Force delete procedure has been scheduled' + + click_link_or_button 'Add new status' + last_input = page.all(:id, 'domain_statuses_').last + last_input.find(:xpath, 'option[10]').select_option + click_link_or_button 'Save' + assert_text 'Failed to update domain' + + click_link_or_button 'Cancel force delete' + @domain.reload + + refute @domain.force_delete_scheduled? + assert_current_path edit_admin_domain_path(@domain) + assert_text 'Force delete procedure has been cancelled' + end + def test_notifies_registrar assert_difference '@domain.registrar.notifications.size' do visit edit_admin_domain_url(@domain) From 07e791da366aaff2e4e5907f997b67daf13d8cd5 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 8 Dec 2021 23:12:56 +0300 Subject: [PATCH 10/13] Fix test name --- test/system/admin_area/domains/force_delete_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/admin_area/domains/force_delete_test.rb b/test/system/admin_area/domains/force_delete_test.rb index 81029e1806..377dad3527 100644 --- a/test/system/admin_area/domains/force_delete_test.rb +++ b/test/system/admin_area/domains/force_delete_test.rb @@ -21,7 +21,7 @@ def test_schedules_domain_force_delete assert_text 'Force delete procedure has been scheduled' end - def test_schedules_domain_force_delete_two + def test_force_delete_prohibit_adding_deleteprohibited_status refute @domain.force_delete_scheduled? visit edit_admin_domain_url(@domain) From fa5203d0a1292d937a0c81dec04a545ffb37d2bb Mon Sep 17 00:00:00 2001 From: dinsmol Date: Wed, 15 Dec 2021 17:31:53 +0300 Subject: [PATCH 11/13] Fix domain statuses logic --- app/models/domain.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/domain.rb b/app/models/domain.rb index f5372e29bd..2bab00eab4 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -121,8 +121,8 @@ def validate_reservation validate :status_is_consistant def status_is_consistant has_error = (hold_status? && statuses.include?(DomainStatus::SERVER_MANUAL_INZONE)) - if !has_error && (statuses & DELETE_STATUSES).any? - has_error = statuses.include? DomainStatus::SERVER_DELETE_PROHIBITED unless locked_by_registrant? + if !has_error && statuses.include?(DomainStatus::PENDING_DELETE) + has_error = statuses.include? DomainStatus::SERVER_DELETE_PROHIBITED end errors.add(:domains, I18n.t(:object_status_prohibits_operation)) if has_error end From ed2d877a59cae7bc9dba3cb37e6d619cb4595043 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 16 Dec 2021 01:14:44 +0300 Subject: [PATCH 12/13] Fix test --- test/system/admin_area/domains/force_delete_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/admin_area/domains/force_delete_test.rb b/test/system/admin_area/domains/force_delete_test.rb index 377dad3527..5751965d1a 100644 --- a/test/system/admin_area/domains/force_delete_test.rb +++ b/test/system/admin_area/domains/force_delete_test.rb @@ -36,7 +36,7 @@ def test_force_delete_prohibit_adding_deleteprohibited_status last_input = page.all(:id, 'domain_statuses_').last last_input.find(:xpath, 'option[10]').select_option click_link_or_button 'Save' - assert_text 'Failed to update domain' + assert_text 'Domain updated!' click_link_or_button 'Cancel force delete' @domain.reload From 9ddcaa81c41e746d073f4a1a31b2f1e38ec5e239 Mon Sep 17 00:00:00 2001 From: dinsmol Date: Thu, 16 Dec 2021 09:23:33 +0300 Subject: [PATCH 13/13] Fix test --- test/system/admin_area/domains/force_delete_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/system/admin_area/domains/force_delete_test.rb b/test/system/admin_area/domains/force_delete_test.rb index 5751965d1a..1e75925424 100644 --- a/test/system/admin_area/domains/force_delete_test.rb +++ b/test/system/admin_area/domains/force_delete_test.rb @@ -38,6 +38,7 @@ def test_force_delete_prohibit_adding_deleteprohibited_status click_link_or_button 'Save' assert_text 'Domain updated!' + visit edit_admin_domain_url(@domain) click_link_or_button 'Cancel force delete' @domain.reload