mirror of
https://github.com/internetee/registry.git
synced 2025-07-28 05:26:17 +02:00
- Add AgeValidation module for consistent age checks - Validate admin contacts must be at least 18 years old - Move age validation logic from Domain to shared module - Add tests for admin contact age validation - Fix JSON format for admin_contacts_allowed_ident_type setting This change ensures that administrative contacts must be adults (18+), using the same age validation logic as for registrants. The validation works with both birthday and Estonian ID formats. Settings are now properly stored as JSON strings for consistent parsing.
40 lines
1.1 KiB
Ruby
40 lines
1.1 KiB
Ruby
class AdminDomainContact < DomainContact
|
|
include AgeValidation
|
|
|
|
validate :validate_contact_age
|
|
|
|
# rubocop:disable Metrics/AbcSize
|
|
# rubocop:disable Metrics/MethodLength
|
|
def self.replace(current_contact, new_contact)
|
|
affected_domains = []
|
|
skipped_domains = []
|
|
admin_contacts = where(contact: current_contact)
|
|
|
|
admin_contacts.includes(:domain).find_each do |admin_contact|
|
|
if admin_contact.domain.bulk_update_prohibited?
|
|
skipped_domains << admin_contact.domain.name
|
|
next
|
|
end
|
|
begin
|
|
admin_contact.contact = new_contact
|
|
admin_contact.save!
|
|
affected_domains << admin_contact.domain.name
|
|
rescue ActiveRecord::RecordNotUnique
|
|
skipped_domains << admin_contact.domain.name
|
|
end
|
|
end
|
|
[affected_domains.sort, skipped_domains.sort]
|
|
end
|
|
# rubocop:enable Metrics/AbcSize
|
|
# rubocop:enable Metrics/MethodLength
|
|
|
|
private
|
|
|
|
def validate_contact_age
|
|
return unless contact&.underage?
|
|
|
|
errors.add(:contact, I18n.t(
|
|
'activerecord.errors.models.admin_domain_contact.contact_too_young'
|
|
))
|
|
end
|
|
end
|