@@ -29,13 +29,35 @@ def validate_contacts
29
29
active_admins = admin_domain_contacts . select { |x | !x . marked_for_destruction? }
30
30
active_techs = tech_domain_contacts . select { |x | !x . marked_for_destruction? }
31
31
32
+ if require_admin_contacts? && active_admins . empty?
33
+ add_epp_error ( '2306' , 'contact' , nil , 'Admin contact is required' )
34
+ ok = false
35
+ end
36
+
32
37
# validate registrant here as well
33
38
( [ Contact . find ( registrant . id ) ] + active_admins + active_techs ) . each do |x |
34
39
unless x . valid?
35
40
add_epp_error ( '2304' , nil , nil , I18n . t ( :contact_is_not_valid , value : x . try ( :code ) ) )
36
41
ok = false
37
42
end
38
43
end
44
+
45
+ # Validate admin contacts ident type only for new domains or new admin contacts
46
+ allowed_types = Setting . admin_contacts_allowed_ident_type
47
+ if allowed_types . present?
48
+ active_admins . each do |admin_contact |
49
+ next if !new_record? && admin_contact . persisted? && !admin_contact . changed?
50
+
51
+ contact = admin_contact . contact
52
+ unless allowed_types [ contact . ident_type ] == true
53
+ add_epp_error ( '2306' , 'contact' , contact . code ,
54
+ I18n . t ( 'activerecord.errors.models.domain.admin_contact_invalid_ident_type' ,
55
+ ident_type : contact . ident_type ) )
56
+ ok = false
57
+ end
58
+ end
59
+ end
60
+
39
61
ok
40
62
end
41
63
@@ -95,7 +117,8 @@ def epp_code_map
95
117
[ :base , :key_data_not_allowed ] ,
96
118
[ :period , :not_a_number ] ,
97
119
[ :period , :not_an_integer ] ,
98
- [ :registrant , :cannot_be_missing ]
120
+ [ :registrant , :cannot_be_missing ] ,
121
+ [ :admin_contacts , :invalid_ident_type ]
99
122
] ,
100
123
'2308' => [
101
124
[ :base , :domain_name_blocked , { value : { obj : 'name' , val : name_dirty } } ] ,
@@ -414,15 +437,15 @@ def admin_contacts_validation_rules(for_org:)
414
437
end
415
438
416
439
def require_admin_contacts?
417
- return true if registrant . org?
440
+ return true if registrant . org? && Setting . admin_contacts_required_for_org
418
441
return false unless registrant . priv?
419
442
420
- underage_registrant?
443
+ underage_registrant? && Setting . admin_contacts_required_for_minors
421
444
end
422
445
423
446
def tech_contacts_validation_rules ( for_org :)
424
447
{
425
- min : 0 , # Технический контакт опционален для всех
448
+ min : 0 ,
426
449
max : -> { Setting . tech_contacts_max_count }
427
450
}
428
451
end
0 commit comments