Make admin contacts optional for private registrants

This change makes admin contacts optional for private registrants while keeping them mandatory for organizations. The changes include:

- Updated Domain model validations to make admin and tech contacts optional (min=0) for private registrants
- Added validation rules methods to handle different requirements based on registrant type
- Modified EPP domain creation to support domains without admin contacts for private registrants
- Updated attach_default_contacts to skip adding contacts for private registrants
- Added comprehensive test coverage for:
  - Domain model validations with private/org registrants
  - EPP domain creation without admin contacts for private registrants
  - REPP API contact management for private registrants

This implements the requirement to make admin contacts optional for private registrations of .ee domains while maintaining the existing validation rules for organizations.
This commit is contained in:
oleghasjanov 2025-01-07 12:24:57 +02:00
parent bfe2a10889
commit 3c169bb00b
5 changed files with 173 additions and 8 deletions

View file

@ -221,6 +221,10 @@ class DomainTest < ActiveSupport::TestCase
assert domain.valid?, proc { domain.errors.full_messages }
domain.admin_domain_contacts.clear
domain.registrant.update!(ident_type: 'org')
domain.reload
assert domain.registrant.org?
assert domain.invalid?
domain.admin_domain_contacts.clear
@ -236,6 +240,10 @@ class DomainTest < ActiveSupport::TestCase
Setting.tech_contacts_min_count = min_count
Setting.tech_contacts_max_count = max_count
domain.registrant.update!(ident_type: 'org')
domain.reload
assert domain.registrant.org?
domain.tech_domain_contacts.clear
min_count.times { domain.tech_domain_contacts.build(domain_contact_attributes) }
assert domain.valid?, proc { domain.errors.full_messages }
@ -475,6 +483,56 @@ class DomainTest < ActiveSupport::TestCase
assert_not @domain.renewable?
end
def test_validates_admin_contact_count_for_private_registrant
domain_contact_attributes = domain_contacts(:shop_jane).dup.attributes
domain = valid_domain
max_count = 2
Setting.admin_contacts_max_count = max_count
domain.registrant.update!(ident_type: 'priv')
domain.reload
assert_not domain.registrant.org?
# Valid without any admin contacts
domain.admin_domain_contacts.clear
assert domain.valid?, proc { domain.errors.full_messages }
# Valid with some admin contacts
domain.admin_domain_contacts.clear
max_count.pred.times { domain.admin_domain_contacts.build(domain_contact_attributes) }
assert domain.valid?, proc { domain.errors.full_messages }
# Invalid when exceeding max contacts
domain.admin_domain_contacts.clear
max_count.next.times { domain.admin_domain_contacts.build(domain_contact_attributes) }
assert domain.invalid?
end
def test_validates_tech_contact_count_for_private_registrant
domain_contact_attributes = domain_contacts(:shop_william).dup.attributes
domain = valid_domain
max_count = 2
Setting.tech_contacts_max_count = max_count
domain.registrant.update!(ident_type: 'priv')
domain.reload
assert_not domain.registrant.org?
# Valid without any tech contacts
domain.tech_domain_contacts.clear
assert domain.valid?, proc { domain.errors.full_messages }
# Valid with some tech contacts
domain.tech_domain_contacts.clear
max_count.pred.times { domain.tech_domain_contacts.build(domain_contact_attributes) }
assert domain.valid?, proc { domain.errors.full_messages }
# Invalid when exceeding max contacts
domain.tech_domain_contacts.clear
max_count.next.times { domain.tech_domain_contacts.build(domain_contact_attributes) }
assert domain.invalid?
end
private
def valid_domain