Merge branch 'master' of github.com:internetee/registry

This commit is contained in:
Andres Keskküla 2014-08-27 12:31:53 +03:00
commit 0f3f251df1
5 changed files with 48 additions and 18 deletions

View file

@ -45,6 +45,7 @@ module Epp::Common
# for debugging # for debugging
@errors << { code: '1', msg: 'handle_errors was executed when there were actually no errors' } if @errors.blank? @errors << { code: '1', msg: 'handle_errors was executed when there were actually no errors' } if @errors.blank?
render '/epp/error' render '/epp/error'
end end

View file

@ -35,16 +35,28 @@ module Epp::DomainsHelper
end end
def update_domain 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
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' @domain.parse_and_attach_domain_dependencies(@ph, parsed_frame.css('add'))
@domain.parse_and_detach_domain_dependencies(parsed_frame.css('rem'))
@domain.parse_and_update_domain_dependencies(parsed_frame.css('chg'))
@domain.parse_and_update_domain_attributes(parsed_frame.css('chg'))
if @domain.errors.any?
handle_errors(@domain)
raise ActiveRecord::Rollback and return
end
unless @domain.save
handle_errors(@domain)
raise ActiveRecord::Rollback and return
end
render '/epp/domains/success'
end
end end
### HELPER METHODS ### ### HELPER METHODS ###

View file

@ -105,13 +105,13 @@ class Domain < ActiveRecord::Base
return unless owner_contact return unless owner_contact
attach_contact(DomainContact::TECH, owner_contact) if tech_contacts.empty? attach_contact(DomainContact::TECH, owner_contact) if tech_contacts_count.zero?
attach_contact(DomainContact::ADMIN, owner_contact) if admin_contacts.empty? if owner_contact.citizen? attach_contact(DomainContact::ADMIN, owner_contact) if admin_contacts_count.zero? && owner_contact.citizen?
end end
def attach_contact(type, contact) def attach_contact(type, contact)
tech_contacts << contact if type.to_sym == :tech domain_contacts.build(contact: contact, contact_type: DomainContact::TECH) if type.to_sym == :tech
admin_contacts << contact if type.to_sym == :admin domain_contacts.build(contact: contact, contact_type: DomainContact::ADMIN) if type.to_sym == :admin
end end
def attach_nameservers(ns_list) def attach_nameservers(ns_list)
@ -127,7 +127,15 @@ class Domain < ActiveRecord::Base
def attach_statuses(status_list) def attach_statuses(status_list)
status_list.each do |x| status_list.each do |x|
existing = domain_statuses.select { |o| o.value == x[:value] }
if existing.any?
add_epp_error('2302', 'status', x[:value], [:domain_statuses, :taken])
next
end
setting = SettingGroup.domain_statuses.settings.find_by(value: x[:value]) setting = SettingGroup.domain_statuses.settings.find_by(value: x[:value])
domain_statuses.build( domain_statuses.build(
setting: setting, setting: setting,
description: x[:description] description: x[:description]
@ -137,9 +145,9 @@ class Domain < ActiveRecord::Base
def detach_contacts(contact_list) def detach_contacts(contact_list)
to_delete = [] to_delete = []
contact_list.each do |_k, v| contact_list.each do |k, v|
v.each do |x| 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? if contact.blank?
add_epp_error('2303', 'contact', x[:contact], [:domain_contacts, :not_found]) add_epp_error('2303', 'contact', x[:contact], [:domain_contacts, :not_found])
else else
@ -205,7 +213,7 @@ class Domain < ActiveRecord::Base
end end
def validate_admin_contacts_count 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 end
def validate_period def validate_period
@ -236,7 +244,7 @@ class Domain < ActiveRecord::Base
], ],
'2306' => [ # Parameter policy error '2306' => [ # Parameter policy error
[:owner_contact, :blank], [:owner_contact, :blank],
[:admin_contacts, :blank] [:admin_contacts, :out_of_range]
], ],
'2004' => [ # Parameter value range error '2004' => [ # Parameter value range error
[:nameservers, :out_of_range, [:nameservers, :out_of_range,
@ -261,6 +269,14 @@ class Domain < ActiveRecord::Base
errors.empty? errors.empty?
end 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 class << self
def convert_period_to_time(period, unit) def convert_period_to_time(period, unit)
return period.to_i.days if unit == 'd' return period.to_i.days if unit == 'd'

View file

@ -50,7 +50,7 @@ en:
domain_contacts: domain_contacts:
not_found: 'Contact was not found' not_found: 'Contact was not found'
admin_contacts: admin_contacts:
blank: 'Admin contact is missing' out_of_range: 'Admin contacts count must be between 1 - infinity'
nameservers: nameservers:
out_of_range: 'Nameservers count must be between %{min}-%{max}' out_of_range: 'Nameservers count must be between %{min}-%{max}'
not_found: 'Nameserver was not found' not_found: 'Nameserver was not found'
@ -61,6 +61,7 @@ en:
wrong_pw: 'Authentication error' wrong_pw: 'Authentication error'
domain_statuses: domain_statuses:
not_found: 'Status was not found' not_found: 'Status was not found'
taken: 'Status already exists on this domain'
nameserver: nameserver:
attributes: attributes:
hostname: hostname:

View file

@ -170,7 +170,7 @@ describe 'EPP Domain', epp: true do
response = epp_request(xml, :xml) response = epp_request(xml, :xml)
expect(response[:result_code]).to eq('2306') expect(response[:result_code]).to eq('2306')
expect(response[:msg]).to eq('Admin contact is missing') expect(response[:msg]).to eq('Admin contacts count must be between 1 - infinity')
expect(response[:clTRID]).to eq('ABC-12345') expect(response[:clTRID]).to eq('ABC-12345')
expect(Domain.count).to eq 0 expect(Domain.count).to eq 0