fixes by review and codeclimat

This commit is contained in:
dinsmol 2021-07-08 17:07:43 +03:00
parent 77d2e402b4
commit 5bed817c35
3 changed files with 11 additions and 4 deletions

View file

@ -8,6 +8,9 @@ class Epp::Contact < Contact
# disable STI, there is type column present
self.inheritance_column = :sti_disabled
VALID_BIRTH_DATE_FROM = Time.zone.today - 150.years
VALID_BIRTH_DATE_TO = Time.zone.tomorrow
before_validation :manage_permissions
def manage_permissions
@ -21,14 +24,18 @@ class Epp::Contact < Contact
def validate_birthday_ident
return unless Depp::Contact::SELECTION_TYPES[2].include?(ident_type)
if (Date.parse(ident) rescue ArgumentError) == ArgumentError
if begin
Date.parse(ident)
rescue StandardError
ArgumentError
end == ArgumentError
add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident_date_format'))
@error = true
return
end
contact_ident_date = Date.parse(ident)
valid_time_range = (Date.today - 125.years)...(Date.tomorrow - 18.years)
valid_time_range = VALID_BIRTH_DATE_FROM...VALID_BIRTH_DATE_TO
return if valid_time_range.cover?(contact_ident_date)
add_epp_error('2308', nil, nil, I18n.t('epp.contacts.errors.valid_ident_date_range'))

View file

@ -13,7 +13,7 @@ en:
Date format is invalid
valid_ident_date_range: >-
Ident update is not allowed.
Age must be over 18 and under 125
Age must be over 0 and under 150
ident_update: >-
Only ident type and country can be updated in case of invalid ident.
Please create new contact object to update ident code

View file

@ -87,7 +87,7 @@ class EppContactCreateBaseTest < EppTestCase
phone = '+1.2'
birthday_wrong_format = '1111-22-33'
birthday_above_valid_range = '1800-01-01'
birthday_below_valid_range = '2008-07-09'
birthday_below_valid_range = '2050-07-09'
request_xml = <<-XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>