From cd5de3bd1476cfff511c00e5c33f58b903bef0a1 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Fri, 31 Jan 2025 15:49:35 +0200 Subject: [PATCH] commit 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. --- app/interactions/actions/domain_create.rb | 2 +- app/models/domain.rb | 2 +- app/models/epp/domain.rb | 39 +++++++++++++++++++ .../epp/domain/create/base_test.rb | 2 +- test/models/domain_test.rb | 6 --- 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/app/interactions/actions/domain_create.rb b/app/interactions/actions/domain_create.rb index d39c470b7..bd4f032d2 100644 --- a/app/interactions/actions/domain_create.rb +++ b/app/interactions/actions/domain_create.rb @@ -15,7 +15,7 @@ module Actions assign_registrant assign_nameservers assign_domain_contacts - domain.attach_default_contacts + # domain.attach_default_contacts assign_expiry_time maybe_attach_legal_doc diff --git a/app/models/domain.rb b/app/models/domain.rb index 48df984c7..1d1a13083 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -173,7 +173,7 @@ class Domain < ApplicationRecord 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 } } end diff --git a/app/models/epp/domain.rb b/app/models/epp/domain.rb index 343bba3bd..ab5d0c16e 100644 --- a/app/models/epp/domain.rb +++ b/app/models/epp/domain.rb @@ -381,6 +381,20 @@ class Epp::Domain < Domain result 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 private @@ -391,4 +405,29 @@ class Epp::Domain < Domain registrant.code != code 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 diff --git a/test/integration/epp/domain/create/base_test.rb b/test/integration/epp/domain/create/base_test.rb index ec2c967e0..12eb5bb03 100644 --- a/test/integration/epp/domain/create/base_test.rb +++ b/test/integration/epp/domain/create/base_test.rb @@ -639,7 +639,7 @@ class EppDomainCreateBaseTest < EppTestCase assert_equal name, domain.name assert_equal registrant, domain.registrant assert_equal [contact], domain.admin_contacts - assert_equal [contact], domain.tech_contacts + assert_empty domain.tech_contacts assert_not_empty domain.transfer_code default_registration_period = 1.year + 1.day diff --git a/test/models/domain_test.rb b/test/models/domain_test.rb index 6c56cb928..d3efe684f 100644 --- a/test/models/domain_test.rb +++ b/test/models/domain_test.rb @@ -235,9 +235,7 @@ class DomainTest < ActiveSupport::TestCase def test_validates_tech_contact_count domain_contact_attributes = domain_contacts(:shop_william).dup.attributes domain = valid_domain - min_count = 1 max_count = 2 - Setting.tech_contacts_min_count = min_count Setting.tech_contacts_max_count = max_count domain.registrant.update!(ident_type: 'org') @@ -245,16 +243,12 @@ class DomainTest < ActiveSupport::TestCase 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 } domain.tech_domain_contacts.clear max_count.times { domain.tech_domain_contacts.build(domain_contact_attributes) } assert domain.valid?, proc { domain.errors.full_messages } - domain.tech_domain_contacts.clear - assert domain.invalid? - domain.tech_domain_contacts.clear max_count.next.times { domain.tech_domain_contacts.build(domain_contact_attributes) } assert domain.invalid?