Use app time zone when calculating valid_to, outzone_at and delete_at domain attributes

#235
This commit is contained in:
Artur Beljajev 2016-11-07 02:05:22 +02:00
parent 8dc65a370f
commit 1cc780f3ce
4 changed files with 86 additions and 15 deletions

View file

@ -73,7 +73,6 @@ class Domain < ActiveRecord::Base
end
before_create :generate_auth_info
before_create :set_validity_dates
before_create -> { self.reserved = in_reserved_list?; nil }
before_save :manage_automatic_statuses
@ -542,13 +541,6 @@ class Domain < ActiveRecord::Base
end
# rubocop:enable Lint/Loop
def set_validity_dates
self.registered_at = Time.zone.now
self.valid_from = Time.zone.now
# we need + 1 day as this is more correct from juridical side
self.valid_to = valid_from.utc.beginning_of_day + self.class.convert_period_to_time(period, period_unit) + 1.day
end
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/MethodLength
def set_force_delete
@ -605,8 +597,8 @@ class Domain < ActiveRecord::Base
end
def set_graceful_expired
self.outzone_at = (valid_to + Setting.expire_warning_period.days).utc.beginning_of_day
self.delete_at = (outzone_at + Setting.redemption_grace_period.days).utc.beginning_of_day
self.outzone_at = valid_to + self.class.expire_warning_period
self.delete_at = outzone_at + self.class.redemption_grace_period
self.statuses |= [DomainStatus::EXPIRED]
end
@ -760,5 +752,13 @@ class Domain < ActiveRecord::Base
kit = PDFKit.new(html)
kit.to_pdf
end
def self.expire_warning_period
Setting.expire_warning_period.days
end
def self.redemption_grace_period
Setting.redemption_grace_period.days
end
end
# rubocop: enable Metrics/ClassLength

View file

@ -53,6 +53,9 @@ class Epp::Domain < Domain
domain = Epp::Domain.new
domain.attributes = domain.attrs_from(frame, current_user)
domain.attach_default_contacts
domain.registered_at = Time.zone.now
domain.valid_from = Time.zone.now
domain.valid_to = domain.valid_from.beginning_of_day + convert_period_to_time(domain.period, domain.period_unit) + 1.day
domain
end
end