feat: make technical contacts optional for all domains

- Remove automatic tech contact assignment from admin contacts
- Set minimum tech contacts to 0 for all registrant types
- Update tests to reflect optional tech contacts
- Keep max tech contacts limit from settings

This change implements the requirement to make technical contacts optional
for all domain types while maintaining the maximum limit from settings.
Previously tech contacts were required for organizations and automatically
copied from admin contacts.
This commit is contained in:
oleghasjanov 2025-01-31 15:49:35 +02:00
parent c2affb393f
commit cd5de3bd14
5 changed files with 42 additions and 9 deletions

View file

@ -15,7 +15,7 @@ module Actions
assign_registrant assign_registrant
assign_nameservers assign_nameservers
assign_domain_contacts assign_domain_contacts
domain.attach_default_contacts # domain.attach_default_contacts
assign_expiry_time assign_expiry_time
maybe_attach_legal_doc maybe_attach_legal_doc

View file

@ -173,7 +173,7 @@ class Domain < ApplicationRecord
def self.tech_contacts_validation_rules(for_org:) def self.tech_contacts_validation_rules(for_org:)
{ {
min: -> { for_org ? Setting.tech_contacts_min_count : 0 }, min: -> { 0 },
max: -> { Setting.tech_contacts_max_count } max: -> { Setting.tech_contacts_max_count }
} }
end end

View file

@ -381,6 +381,20 @@ class Epp::Domain < Domain
result result
end end
def admin_contacts_validation_rules(for_org:)
{
min: -> { for_org ? Setting.admin_contacts_min_count : 0 },
max: -> { Setting.admin_contacts_max_count }
}
end
def tech_contacts_validation_rules(for_org:)
{
min: 0,
max: -> { Setting.tech_contacts_max_count }
}
end
end end
private private
@ -391,4 +405,29 @@ class Epp::Domain < Domain
registrant.code != code registrant.code != code
end end
def admin_contacts_validation_rules(for_org:)
{
min: -> { for_org ? Setting.admin_contacts_min_count : 0 },
max: -> { Setting.admin_contacts_max_count }
}
end
def require_admin_contacts?
return true if registrant.org?
return false unless registrant.priv?
underage_registrant?
end
def tech_contacts_validation_rules(for_org:)
{
min: 0, # Технический контакт опционален для всех
max: -> { Setting.tech_contacts_max_count }
}
end
def require_tech_contacts?
registrant.present? && registrant.org?
end
end end

View file

@ -639,7 +639,7 @@ class EppDomainCreateBaseTest < EppTestCase
assert_equal name, domain.name assert_equal name, domain.name
assert_equal registrant, domain.registrant assert_equal registrant, domain.registrant
assert_equal [contact], domain.admin_contacts assert_equal [contact], domain.admin_contacts
assert_equal [contact], domain.tech_contacts assert_empty domain.tech_contacts
assert_not_empty domain.transfer_code assert_not_empty domain.transfer_code
default_registration_period = 1.year + 1.day default_registration_period = 1.year + 1.day

View file

@ -235,9 +235,7 @@ class DomainTest < ActiveSupport::TestCase
def test_validates_tech_contact_count def test_validates_tech_contact_count
domain_contact_attributes = domain_contacts(:shop_william).dup.attributes domain_contact_attributes = domain_contacts(:shop_william).dup.attributes
domain = valid_domain domain = valid_domain
min_count = 1
max_count = 2 max_count = 2
Setting.tech_contacts_min_count = min_count
Setting.tech_contacts_max_count = max_count Setting.tech_contacts_max_count = max_count
domain.registrant.update!(ident_type: 'org') domain.registrant.update!(ident_type: 'org')
@ -245,16 +243,12 @@ class DomainTest < ActiveSupport::TestCase
assert domain.registrant.org? assert domain.registrant.org?
domain.tech_domain_contacts.clear domain.tech_domain_contacts.clear
min_count.times { domain.tech_domain_contacts.build(domain_contact_attributes) }
assert domain.valid?, proc { domain.errors.full_messages } assert domain.valid?, proc { domain.errors.full_messages }
domain.tech_domain_contacts.clear domain.tech_domain_contacts.clear
max_count.times { domain.tech_domain_contacts.build(domain_contact_attributes) } max_count.times { domain.tech_domain_contacts.build(domain_contact_attributes) }
assert domain.valid?, proc { domain.errors.full_messages } assert domain.valid?, proc { domain.errors.full_messages }
domain.tech_domain_contacts.clear
assert domain.invalid?
domain.tech_domain_contacts.clear domain.tech_domain_contacts.clear
max_count.next.times { domain.tech_domain_contacts.build(domain_contact_attributes) } max_count.next.times { domain.tech_domain_contacts.build(domain_contact_attributes) }
assert domain.invalid? assert domain.invalid?