Renew: Attach uneligibility reason

This commit is contained in:
Karl Erik Õunapuu 2020-09-28 14:57:52 +03:00
parent 9976e3dd93
commit 29897043b0
No known key found for this signature in database
GPG key ID: C9DD647298A34764
3 changed files with 22 additions and 8 deletions

View file

@ -306,12 +306,7 @@ class Domain < ApplicationRecord
end
def renewable?
disallowed = [DomainStatus::DELETE_CANDIDATE, DomainStatus::PENDING_RENEW,
DomainStatus::PENDING_TRANSFER, DomainStatus::CLIENT_RENEW_PROHIBITED,
DomainStatus::PENDING_UPDATE, DomainStatus::PENDING_DELETE,
DomainStatus::PENDING_DELETE_CONFIRMATION, DomainStatus::SERVER_RENEW_PROHIBITED]
return false unless (statuses & disallowed).empty?
return false unless renew_blocking_statuses.empty?
return true unless Setting.days_to_renew_domain_before_expire != 0
# if you can renew domain at days_to_renew before domain expiration
@ -322,6 +317,15 @@ class Domain < ApplicationRecord
true
end
def renew_blocking_statuses
disallowed = [DomainStatus::DELETE_CANDIDATE, DomainStatus::PENDING_RENEW,
DomainStatus::PENDING_TRANSFER, DomainStatus::CLIENT_RENEW_PROHIBITED,
DomainStatus::PENDING_UPDATE, DomainStatus::PENDING_DELETE,
DomainStatus::PENDING_DELETE_CONFIRMATION, DomainStatus::SERVER_RENEW_PROHIBITED]
(statuses & disallowed)
end
def notify_registrar(message_key)
registrar.notifications.create!(
text: "#{I18n.t(message_key)}: #{name}",

View file

@ -581,11 +581,14 @@ class Epp::Domain < Domain
save(validate: false)
end
### RENEW ###
def renew(cur_exp_date, period, unit = 'y')
@is_renewal = true
validate_exp_dates(cur_exp_date)
add_epp_error('2105', nil, nil, I18n.t('object_is_not_eligible_for_renewal')) unless renewable?
add_renew_epp_errors unless renewable?
return false if errors.any?
period = period.to_i
@ -613,6 +616,13 @@ class Epp::Domain < Domain
save
end
def add_renew_epp_errors
if renew_blocking_statuses.any? && !renewable?
add_epp_error('2304', 'status', renew_blocking_statuses,
I18n.t('object_status_prohibits_operation'))
end
end
### TRANSFER ###
def transfer(frame, action, current_user)

View file

@ -196,7 +196,7 @@ class EppDomainRenewBaseTest < EppTestCase
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
domain.reload
assert_epp_response :object_is_not_eligible_for_renewal
assert_epp_response :object_status_prohibits_operation
assert_equal original_valid_to, domain.valid_to
end
end