diff --git a/app/models/domain.rb b/app/models/domain.rb index 469847203..1b0620262 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -152,6 +152,12 @@ class Domain < ActiveRecord::Base x.domain_statuses.create(value: DomainStatus::EXPIRED) if x.expirable? end end + + def start_redemption_grace_period + Domain.where('outzone_at <= ?', Time.zone.now).each do |x| + x.domain_statuses.create(value: DomainStatus::SERVER_HOLD) if x.server_holdable? + end + end end def name=(value) @@ -189,6 +195,13 @@ class Domain < ActiveRecord::Base domain_statuses.where(value: DomainStatus::EXPIRED).empty? end + def server_holdable? + return false if outzone_at > Time.zone.now + return false if domain_statuses.where(value: DomainStatus::SERVER_HOLD).any? + return false if domain_statuses.where(value: DomainStatus::SERVER_MANUAL_INZONE).any? + true + end + def pending_update? (domain_statuses.pluck(:value) & %W( #{DomainStatus::PENDING_UPDATE} @@ -329,6 +342,8 @@ class Domain < ActiveRecord::Base self.registered_at = Time.zone.now self.valid_from = Time.zone.now.to_date self.valid_to = valid_from + self.class.convert_period_to_time(period, period_unit) + self.outzone_at = self.valid_to + Setting.expire_warning_period.days + self.delete_at = self.outzone_at + Setting.redemption_grace_period.days end def manage_automatic_statuses diff --git a/config/initializers/initial_settings.rb b/config/initializers/initial_settings.rb index 018e4be22..824cf0fcc 100644 --- a/config/initializers/initial_settings.rb +++ b/config/initializers/initial_settings.rb @@ -32,6 +32,8 @@ if con.present? && con.table_exists?('settings') 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) + Setting.save_default(:expire_warning_period, 15) + Setting.save_default(:redemption_grace_period, 30) end # dev only setting diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index 6bf183f9f..e8bb34742 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -55,6 +55,13 @@ describe Domain do @domain.errors.full_messages.should match_array([]) end + it 'should have correct validity dates' do + valid_to = Time.zone.now.beginning_of_day + 1.year + @domain.valid_to.should == valid_to + @domain.outzone_at.should == valid_to + Setting.expire_warning_period.days + @domain.delete_at.should == valid_to + Setting.expire_warning_period.days + Setting.redemption_grace_period.days + end + it 'should validate uniqueness of tech contacts' do same_contact = Fabricate(:contact, code: 'same_contact') domain = Fabricate(:domain) @@ -96,6 +103,17 @@ describe Domain do @domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 1 end + it 'should start redemption grace period' do + Domain.start_redemption_grace_period + @domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 0 + + @domain.outzone_at = Time.zone.now + @domain.save + + Domain.start_redemption_grace_period + @domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 1 + end + context 'about registrant update confirm' do before :all do @domain.registrant_verification_token = 123