mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 16:32:04 +02:00
parent
c442e502b0
commit
a3b3490591
9 changed files with 372 additions and 77 deletions
|
@ -107,7 +107,6 @@ class Domain < ActiveRecord::Base
|
|||
validates :period, numericality: { only_integer: true }
|
||||
validates :registrant, :registrar, presence: true
|
||||
|
||||
validate :validate_period
|
||||
validate :validate_reservation
|
||||
def validate_reservation
|
||||
return if persisted? || !in_reserved_list?
|
||||
|
@ -229,12 +228,6 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
class << self
|
||||
def convert_period_to_time(period, unit)
|
||||
return (period.to_i / 365).years if unit == 'd'
|
||||
return (period.to_i / 12).years if unit == 'm'
|
||||
return period.to_i.years if unit == 'y'
|
||||
end
|
||||
|
||||
def included
|
||||
includes(
|
||||
:registrant,
|
||||
|
@ -450,18 +443,16 @@ class Domain < ActiveRecord::Base
|
|||
self.delete_at = nil
|
||||
end
|
||||
|
||||
def pricelist(operation, period_i = nil, unit = nil)
|
||||
def pricelist(operation_category, period_i = nil, unit = nil)
|
||||
period_i ||= period
|
||||
unit ||= period_unit
|
||||
|
||||
# TODO: test if name.scan(/\.(.+)\z/).first.first is faster
|
||||
zone = name.split('.').drop(1).join('.')
|
||||
zone_name = name.split('.').drop(1).join('.')
|
||||
zone = DNS::Zone.find_by(origin: zone_name)
|
||||
|
||||
p = period_i / 365 if unit == 'd'
|
||||
p = period_i / 12 if unit == 'm'
|
||||
p = period_i if unit == 'y'
|
||||
duration = "P#{period_i}#{unit.upcase}"
|
||||
|
||||
Pricelist.pricelist_for(zone, operation, "#{p}year".pluralize(p))
|
||||
Billing::Price.price_for(zone, operation_category, duration)
|
||||
end
|
||||
|
||||
### VALIDATIONS ###
|
||||
|
@ -476,19 +467,6 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def validate_period
|
||||
return unless period.present?
|
||||
if period_unit == 'd'
|
||||
valid_values = %w(365 730 1095)
|
||||
elsif period_unit == 'm'
|
||||
valid_values = %w(12 24 36)
|
||||
else
|
||||
valid_values = %w(1 2 3)
|
||||
end
|
||||
|
||||
errors.add(:period, :out_of_range) unless valid_values.include?(period.to_s)
|
||||
end
|
||||
|
||||
# used for highlighting form tabs
|
||||
def parent_valid?
|
||||
assoc_errors = errors.keys.select { |x| x.match(/\./) }
|
||||
|
|
|
@ -55,7 +55,12 @@ class Epp::Domain < Domain
|
|||
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
|
||||
|
||||
period = domain.period.to_i
|
||||
plural_period_unit_name = (domain.period_unit == 'm' ? 'months' : 'years').to_sym
|
||||
expire_time = (Time.zone.now.advance(plural_period_unit_name => period) + 1.day).beginning_of_day
|
||||
domain.expire_time = expire_time
|
||||
|
||||
domain
|
||||
end
|
||||
end
|
||||
|
@ -109,7 +114,6 @@ class Epp::Domain < Domain
|
|||
[:base, :domain_status_prohibits_operation]
|
||||
],
|
||||
'2306' => [ # Parameter policy error
|
||||
[:period, :out_of_range, { value: { obj: 'period', val: period } }],
|
||||
[:base, :ds_data_with_key_not_allowed],
|
||||
[:base, :ds_data_not_allowed],
|
||||
[:base, :key_data_not_allowed],
|
||||
|
@ -588,8 +592,6 @@ class Epp::Domain < Domain
|
|||
save(validate: false)
|
||||
end
|
||||
|
||||
### RENEW ###
|
||||
|
||||
def renew(cur_exp_date, period, unit = 'y')
|
||||
@is_renewal = true
|
||||
validate_exp_dates(cur_exp_date)
|
||||
|
@ -597,19 +599,11 @@ class Epp::Domain < Domain
|
|||
add_epp_error('2105', nil, nil, I18n.t('object_is_not_eligible_for_renewal')) unless renewable?
|
||||
return false if errors.any?
|
||||
|
||||
p = self.class.convert_period_to_time(period, unit)
|
||||
renewed_expire_time = valid_to + p
|
||||
period = period.to_i
|
||||
plural_period_unit_name = (unit == 'm' ? 'months' : 'years').to_sym
|
||||
renewed_expire_time = valid_to.advance(plural_period_unit_name => period.to_i)
|
||||
|
||||
# Change it when Pricelist model periods change
|
||||
max_reg_time = 4.years.from_now
|
||||
|
||||
if renewed_expire_time >= max_reg_time
|
||||
add_epp_error('2105', nil, nil, I18n.t('epp.domains.object_is_not_eligible_for_renewal',
|
||||
max_date: max_reg_time.to_date.to_s(:db)))
|
||||
return false if errors.any?
|
||||
end
|
||||
|
||||
self.valid_to = renewed_expire_time
|
||||
self.expire_time = renewed_expire_time
|
||||
self.outzone_at = nil
|
||||
self.delete_at = nil
|
||||
self.period = period
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue