Skip to content

Commit

Permalink
Merge pull request #2232 from internetee/2218-fd-prohibit-settings-se…
Browse files Browse the repository at this point in the history
…rverdeleteprohibited

ForceDelete prohibit settings serverDeleteProhibited
  • Loading branch information
vohmar authored Dec 20, 2021
2 parents 822abc6 + 9ddcaa8 commit ee1c730
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
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

0 comments on commit ee1c730

Please sign in to comment.