diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 3f054003b..ecd13ad55 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -429,6 +429,11 @@ class Epp::Domain < Domain 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 (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 + return false if errors.any? p = self.class.convert_period_to_time(period, unit) diff --git a/config/initializers/initial_settings.rb b/config/initializers/initial_settings.rb index 28a7d0d68..018e4be22 100644 --- a/config/initializers/initial_settings.rb +++ b/config/initializers/initial_settings.rb @@ -31,6 +31,7 @@ if con.present? && con.table_exists?('settings') Setting.save_default(:invoice_number_min, '131050') Setting.save_default(:invoice_number_max, '149999') Setting.save_default(:days_to_keep_overdue_invoices_active, 30) + Setting.save_default(:days_to_renew_domain_before_expire, 90) end # dev only setting diff --git a/config/locales/en.yml b/config/locales/en.yml index 2d4f14d66..0967fbcb9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -816,3 +816,4 @@ en: new_pricelist: New Pricelist valid: Valid category: Zone + object_is_not_eligible_for_renewal: 'Object is not eligible for renewal' diff --git a/db/data/20150609093515_add_renew_setting.rb b/db/data/20150609093515_add_renew_setting.rb new file mode 100644 index 000000000..f462c38cb --- /dev/null +++ b/db/data/20150609093515_add_renew_setting.rb @@ -0,0 +1,9 @@ +class AddRenewSetting < ActiveRecord::Migration + def self.up + Setting.days_to_renew_domain_before_expire = 90 + end + + def self.down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 0fed345ae..b3321641b 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -1949,7 +1949,10 @@ describe 'EPP Domain', epp: true do ### RENEW ### it 'renews a domain' do - exp_date = 1.year.since.to_date + domain.valid_to = Time.zone.now.to_date + 10.days + domain.save + + exp_date = domain.valid_to.to_date xml = @epp_xml.domain.renew( name: { value: domain.name }, curExpDate: { value: exp_date.to_s }, @@ -1979,7 +1982,9 @@ describe 'EPP Domain', epp: true do end it 'returns an error when period is invalid' do - exp_date = (1.year.since.to_date) + domain.valid_to = Time.zone.now.to_date + 10.days + domain.save + exp_date = domain.valid_to.to_date xml = @epp_xml.domain.renew( name: { value: domain.name }, @@ -1993,6 +1998,36 @@ describe 'EPP Domain', epp: true do response[:results][0][:value].should == '4' end + it 'does not renew a domain unless less than 90 days till expiration' do + domain.valid_to = Time.zone.now.to_date + 91.days + domain.save + 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' + + domain.valid_to = Time.zone.now.to_date + 90.days + domain.save + 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 == 'Command completed successfully' + response[:results][0][:result_code].should == '1000' + end + it 'does not renew foreign domain' do login_as :registrar2 do exp_date = 1.year.since.to_date