diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index 8a086027b5..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,7 +42,9 @@ 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 @domain.is_admin = true @domain.admin_status_update dp[:statuses] @@ -49,11 +53,14 @@ 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' end end + # rubocop:enable Metrics/MethodLength def versions @domain = Domain.where(id: params[:domain_id]).includes({ versions: :item }).first diff --git a/app/models/domain.rb b/app/models/domain.rb index 5e8a284d53..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 @@ -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 6f50fd55a9..27d0a8770b 100644 --- a/test/system/admin_area/domains/force_delete_test.rb +++ b/test/system/admin_area/domains/force_delete_test.rb @@ -21,6 +21,32 @@ def test_schedules_domain_force_delete assert_text 'Force delete procedure has been scheduled' end + def test_force_delete_prohibit_adding_deleteprohibited_status + 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 'Domain updated!' + + visit edit_admin_domain_url(@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)