mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 00:12:03 +02:00
Contacts validation improvement
This commit is contained in:
parent
7b750b7d9b
commit
8697f8eabb
5 changed files with 29 additions and 18 deletions
|
@ -45,6 +45,7 @@ module Epp::Common
|
|||
|
||||
# for debugging
|
||||
@errors << { code: '1', msg: 'handle_errors was executed when there were actually no errors' } if @errors.blank?
|
||||
|
||||
render '/epp/error'
|
||||
end
|
||||
|
||||
|
|
|
@ -35,16 +35,18 @@ module Epp::DomainsHelper
|
|||
end
|
||||
|
||||
def update_domain
|
||||
@domain = find_domain
|
||||
Domain.transaction do
|
||||
@domain = find_domain
|
||||
|
||||
handle_errors(@domain) and return unless @domain
|
||||
handle_errors(@domain) and return unless @domain.parse_and_attach_domain_dependencies(@ph, parsed_frame.css('add'))
|
||||
handle_errors(@domain) and return unless @domain.parse_and_detach_domain_dependencies(parsed_frame.css('rem'))
|
||||
handle_errors(@domain) and return unless @domain.parse_and_update_domain_dependencies(parsed_frame.css('chg'))
|
||||
handle_errors(@domain) and return unless @domain.parse_and_update_domain_attributes(parsed_frame.css('chg'))
|
||||
handle_errors(@domain) and return unless @domain.save
|
||||
handle_errors(@domain) and return unless @domain
|
||||
handle_errors(@domain) and return unless @domain.parse_and_attach_domain_dependencies(@ph, parsed_frame.css('add'))
|
||||
handle_errors(@domain) and return unless @domain.parse_and_detach_domain_dependencies(parsed_frame.css('rem'))
|
||||
handle_errors(@domain) and return unless @domain.parse_and_update_domain_dependencies(parsed_frame.css('chg'))
|
||||
handle_errors(@domain) and return unless @domain.parse_and_update_domain_attributes(parsed_frame.css('chg'))
|
||||
handle_errors(@domain) and return unless @domain.save
|
||||
|
||||
render '/epp/domains/success'
|
||||
render '/epp/domains/success'
|
||||
end
|
||||
end
|
||||
|
||||
### HELPER METHODS ###
|
||||
|
|
|
@ -105,13 +105,13 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
return unless owner_contact
|
||||
|
||||
attach_contact(DomainContact::TECH, owner_contact) if tech_contacts.empty?
|
||||
attach_contact(DomainContact::ADMIN, owner_contact) if admin_contacts.empty? if owner_contact.citizen?
|
||||
attach_contact(DomainContact::TECH, owner_contact) if tech_contacts_count.zero?
|
||||
attach_contact(DomainContact::ADMIN, owner_contact) if admin_contacts_count.zero? && owner_contact.citizen?
|
||||
end
|
||||
|
||||
def attach_contact(type, contact)
|
||||
tech_contacts << contact if type.to_sym == :tech
|
||||
admin_contacts << contact if type.to_sym == :admin
|
||||
domain_contacts.build(contact: contact, contact_type: DomainContact::TECH) if type.to_sym == :tech
|
||||
domain_contacts.build(contact: contact, contact_type: DomainContact::ADMIN) if type.to_sym == :admin
|
||||
end
|
||||
|
||||
def attach_nameservers(ns_list)
|
||||
|
@ -137,9 +137,9 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
def detach_contacts(contact_list)
|
||||
to_delete = []
|
||||
contact_list.each do |_k, v|
|
||||
contact_list.each do |k, v|
|
||||
v.each do |x|
|
||||
contact = domain_contacts.joins(:contact).where(contacts: { code: x[:contact] })
|
||||
contact = domain_contacts.joins(:contact).where(contacts: { code: x[:contact] }, contact_type: k.to_s)
|
||||
if contact.blank?
|
||||
add_epp_error('2303', 'contact', x[:contact], [:domain_contacts, :not_found])
|
||||
else
|
||||
|
@ -205,7 +205,7 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def validate_admin_contacts_count
|
||||
errors.add(:admin_contacts, :blank) if admin_contacts.empty?
|
||||
errors.add(:admin_contacts, :out_of_range) if admin_contacts_count.zero?
|
||||
end
|
||||
|
||||
def validate_period
|
||||
|
@ -236,7 +236,7 @@ class Domain < ActiveRecord::Base
|
|||
],
|
||||
'2306' => [ # Parameter policy error
|
||||
[:owner_contact, :blank],
|
||||
[:admin_contacts, :blank]
|
||||
[:admin_contacts, :out_of_range]
|
||||
],
|
||||
'2004' => [ # Parameter value range error
|
||||
[:nameservers, :out_of_range,
|
||||
|
@ -261,6 +261,14 @@ class Domain < ActiveRecord::Base
|
|||
errors.empty?
|
||||
end
|
||||
|
||||
def tech_contacts_count
|
||||
domain_contacts.select { |x| x.contact_type == DomainContact::TECH }.count
|
||||
end
|
||||
|
||||
def admin_contacts_count
|
||||
domain_contacts.select { |x| x.contact_type == DomainContact::ADMIN }.count
|
||||
end
|
||||
|
||||
class << self
|
||||
def convert_period_to_time(period, unit)
|
||||
return period.to_i.days if unit == 'd'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue