Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ForceDelete prohibit settings serverDeleteProhibited #2232

Merged
merged 16 commits into from
Dec 20, 2021
4 changes: 2 additions & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
- name: Save coverage
run: ./cc-test-reporter format-coverage --output coverage/codeclimate.${{ matrix.ruby }}.json

- uses: actions/upload-artifact@v2.2.4
- uses: actions/upload-artifact@v2.3.0
with:
name: coverage-${{ matrix.ruby }}
path: coverage/codeclimate.${{ matrix.ruby }}.json
Expand All @@ -104,7 +104,7 @@ jobs:
- name: Give test coverage reporter executable permissions
run: chmod +x cc-test-reporter

- uses: actions/download-artifact@v2.0.10
- uses: actions/download-artifact@v2.1.0
with:
name: coverage-${{ matrix.ruby }}
path: coverage
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/admin/domains_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions app/models/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions test/system/admin_area/domains/force_delete_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down