Add domain delete period method #2622

This commit is contained in:
Martin Lensment 2015-06-10 12:11:16 +03:00
parent 249262e224
commit 21829faf38
3 changed files with 52 additions and 11 deletions

View file

@ -147,7 +147,7 @@ class Domain < ActiveRecord::Base
)
end
def expire_domains
def start_expire_period
Domain.where('valid_to <= ?', Time.zone.now).each do |x|
x.domain_statuses.create(value: DomainStatus::EXPIRED) if x.expirable?
end
@ -158,6 +158,12 @@ class Domain < ActiveRecord::Base
x.domain_statuses.create(value: DomainStatus::SERVER_HOLD) if x.server_holdable?
end
end
def start_delete_period
Domain.where('delete_at <= ?', Time.zone.now).each do |x|
x.domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if x.deletable?
end
end
end
def name=(value)
@ -202,6 +208,13 @@ class Domain < ActiveRecord::Base
true
end
def deletable?
return false if delete_at > Time.zone.now
return false if domain_statuses.where(value: DomainStatus::DELETE_CANDIDATE).any?
return false if domain_statuses.where(value: DomainStatus::SERVER_DELETE_PROHIBITED).any?
true
end
def pending_update?
(domain_statuses.pluck(:value) & %W(
#{DomainStatus::PENDING_UPDATE}
@ -340,13 +353,15 @@ class Domain < ActiveRecord::Base
def set_validity_dates
self.registered_at = Time.zone.now
self.valid_from = Time.zone.now.to_date
self.valid_from = Time.zone.now
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
self.outzone_at = valid_to + Setting.expire_warning_period.days
self.delete_at = outzone_at + Setting.redemption_grace_period.days
end
def manage_automatic_statuses
# domain_statuses.create(value: DomainStatus::DELETE_CANDIDATE) if deletable?
if domain_statuses.empty? && valid?
domain_statuses.create(value: DomainStatus::OK)
elsif domain_statuses.length > 1 || !valid?

View file

@ -317,7 +317,7 @@ describe 'EPP Domain', epp: true do
response = epp_plain_request(xml)
response[:msg].should == 'Command completed successfully'
response[:result_code].should == '1000'
Domain.first.valid_to.should == 1.year.since.to_date
Domain.first.valid_to.should be_within(5).of(1.year.since)
end
it 'does not create a domain with invalid period' do

View file

@ -56,10 +56,10 @@ describe Domain do
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
valid_to = Time.zone.now + 1.year
@domain.valid_to.should be_within(5).of(valid_to)
@domain.outzone_at.should be_within(5).of(valid_to + Setting.expire_warning_period.days)
@domain.delete_at.should be_within(5).of(valid_to + Setting.expire_warning_period.days + Setting.redemption_grace_period.days)
end
it 'should validate uniqueness of tech contacts' do
@ -93,13 +93,16 @@ describe Domain do
end
it 'should expire domains' do
Domain.expire_domains
Domain.start_expire_period
@domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 0
@domain.valid_to = Time.zone.now - 10.days
@domain.save
Domain.expire_domains
Domain.start_expire_period
@domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 1
Domain.start_expire_period
@domain.domain_statuses.where(value: DomainStatus::EXPIRED).count.should == 1
end
@ -108,12 +111,35 @@ describe Domain do
@domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 0
@domain.outzone_at = Time.zone.now
@domain.domain_statuses.create(value: DomainStatus::SERVER_MANUAL_INZONE) # this prohibits server_hold
@domain.save
Domain.start_redemption_grace_period
@domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 0
@domain.domain_statuses.destroy_all
Domain.start_redemption_grace_period
@domain.domain_statuses.where(value: DomainStatus::SERVER_HOLD).count.should == 1
end
it 'should start delete period' do
Domain.start_delete_period
@domain.domain_statuses.where(value: DomainStatus::DELETE_CANDIDATE).count.should == 0
@domain.delete_at = Time.zone.now
@domain.domain_statuses.create(value: DomainStatus::SERVER_DELETE_PROHIBITED) # this prohibits delete_candidate
@domain.save
Domain.start_delete_period
@domain.domain_statuses.where(value: DomainStatus::DELETE_CANDIDATE).count.should == 0
@domain.domain_statuses.destroy_all
Domain.start_delete_period
@domain.domain_statuses.where(value: DomainStatus::DELETE_CANDIDATE).count.should == 1
end
context 'about registrant update confirm' do
before :all do
@domain.registrant_verification_token = 123