diff --git a/app/models/domain.rb b/app/models/domain.rb index 5cef3b032..450aa0d9c 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -221,6 +221,18 @@ class Domain < ActiveRecord::Base true end + def renewable? + if Setting.days_to_renew_domain_before_expire != 0 + if (valid_to - Time.zone.now).to_i / 1.day >= Setting.days_to_renew_domain_before_expire + return false + end + end + + return false if domain_statuses.where(value: DomainStatus::DELETE_CANDIDATE).any? + + true + end + def pending_update? (domain_statuses.pluck(:value) & %W( #{DomainStatus::PENDING_UPDATE} diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 752ced9ab..323b7302c 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -427,21 +427,16 @@ class Epp::Domain < Domain ### RENEW ### def renew(cur_exp_date, period, unit = 'y') - # TODO: Check how much time before domain exp date can it be renewed validate_exp_dates(cur_exp_date) - if Setting.days_to_renew_domain_before_expire != 0 - if (valid_to - Time.zone.now).to_i / 1.day >= Setting.days_to_renew_domain_before_expire - add_epp_error('2105', nil, nil, I18n.t('object_is_not_eligible_for_renewal')) - end - end - + add_epp_error('2105', nil, nil, I18n.t('object_is_not_eligible_for_renewal')) unless renewable? return false if errors.any? p = self.class.convert_period_to_time(period, unit) self.valid_to = valid_to + p self.period = period self.period_unit = unit + save end diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 1973d84f1..7162db690 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -2047,6 +2047,26 @@ describe 'EPP Domain', epp: true do Setting.days_to_renew_domain_before_expire = 90 end + it 'does not renew a domain if it is a delete candidate' do + domain.valid_to = Time.zone.now + 10.days + domain.delete_at = Time.zone.now + domain.save + + Domain.start_delete_period + + exp_date = domain.valid_to.to_date + + xml = @epp_xml.domain.renew( + name: { value: domain.name }, + curExpDate: { value: exp_date.to_s }, + period: { value: '1', attrs: { unit: 'y' } } + ) + + response = epp_plain_request(xml) + response[:results][0][:msg].should == 'Object is not eligible for renewal' + response[:results][0][:result_code].should == '2105' + end + it 'does not renew foreign domain' do login_as :registrar2 do exp_date = 1.year.since.to_date