mirror of
https://github.com/internetee/registry.git
synced 2025-07-01 16:53:37 +02:00
Set validity, outzone, delete dates on domain creation #2622
This commit is contained in:
parent
ffb1ab6521
commit
6546f51acf
3 changed files with 35 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue