This commit is contained in:
Martin Lensment 2015-06-15 16:35:26 +03:00
parent 50346c80c8
commit 6229d6cb35
5 changed files with 48 additions and 65 deletions

View file

@ -122,6 +122,13 @@ class Domain < ActiveRecord::Base
validate :validate_nameserver_ips
validate :statuses_uniqueness
def statuses_uniqueness
return if statuses.uniq == statuses
errors.add(:statuses, :taken)
end
attr_accessor :registrant_typeahead, :update_me, :deliver_emails,
:epp_pending_update, :epp_pending_delete
@ -245,13 +252,13 @@ class Domain < ActiveRecord::Base
def expirable?
return false if valid_to > Time.zone.now
domain_statuses.where(value: DomainStatus::EXPIRED).empty?
!statuses.include?(DomainStatus::EXPIRED)
end
def server_holdable?
return false if outzone_at > Time.zone.now
return false if domain_statuses.where(value: DomainStatus::SERVER_HOLD).any?
return false if domain_statuses.where(value: DomainStatus::SERVER_MANUAL_INZONE).any?
return false if statuses.include?(DomainStatus::SERVER_HOLD)
return false if statuses.include?(DomainStatus::SERVER_MANUAL_INZONE)
true
end

View file

@ -110,10 +110,12 @@ class Epp::Domain < Domain
at[:period_unit] = Epp::Domain.parse_period_unit_from_frame(frame) || 'y'
# at[:statuses] = domain_statuses_attrs(frame, action)
# binding.pry
at[:nameservers_attributes] = nameservers_attrs(frame, action)
at[:admin_domain_contacts_attributes] = admin_domain_contacts_attrs(frame, action)
at[:tech_domain_contacts_attributes] = tech_domain_contacts_attrs(frame, action)
at[:domain_statuses_attributes] = domain_statuses_attrs(frame, action)
# at[:domain_statuses_attributes] = domain_statuses_attrs(frame, action)
if new_record?
dnskey_frame = frame.css('extension create')
@ -235,24 +237,6 @@ class Epp::Domain < Domain
attrs
end
def domain_status_list_from(frame)
status_list = []
frame.css('status').each do |x|
unless DomainStatus::CLIENT_STATUSES.include?(x['s'])
add_epp_error('2303', 'status', x['s'], [:domain_statuses, :not_found])
next
end
status_list << {
value: x['s'],
description: x.text
}
end
status_list
end
# rubocop: disable Metrics/PerceivedComplexity
# rubocop: disable Metrics/CyclomaticComplexity
def dnskeys_attrs(frame, action)
@ -336,14 +320,10 @@ class Epp::Domain < Domain
if action == 'rem'
to_destroy = []
status_list.each do |x|
status = domain_statuses.find_by(value: x[:value])
if status.blank?
add_epp_error('2303', 'status', x[:value], [:domain_statuses, :not_found])
if statuses.include?(x)
to_destroy << x
else
to_destroy << {
id: status.id,
_destroy: 1
}
add_epp_error('2303', 'status', x, [:domain_statuses, :not_found])
end
end
@ -362,10 +342,7 @@ class Epp::Domain < Domain
next
end
status_list << {
value: x['s'],
description: x.text
}
status_list << x['s']
end
status_list
@ -392,13 +369,13 @@ class Epp::Domain < Domain
at[:admin_domain_contacts_attributes] += at_add[:admin_domain_contacts_attributes]
at[:tech_domain_contacts_attributes] += at_add[:tech_domain_contacts_attributes]
at[:dnskeys_attributes] += at_add[:dnskeys_attributes]
at[:domain_statuses_attributes] += at_add[:domain_statuses_attributes]
at[:statuses] = statuses - domain_statuses_attrs(frame.css('rem'), 'rem') + domain_statuses_attrs(frame.css('add'), 'add')
# at[:statuses] += at_add[:domain_statuses_attributes]
if frame.css('registrant').present? && frame.css('registrant').attr('verified').to_s.downcase != 'yes'
registrant_verification_asked!
end
self.deliver_emails = true # turn on email delivery for epp
errors.empty? && super(at)
end

View file

@ -8,9 +8,8 @@ xml.epp_head do
xml.tag!('domain:infData', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
xml.tag!('domain:name', @domain.name)
xml.tag!('domain:roid', @domain.roid)
@domain.domain_statuses.each do |ds|
xml.tag!('domain:status', ds.description, 's' => ds.value) unless ds.description.blank?
xml.tag!('domain:status', 's' => ds.value) if ds.description.blank?
@domain.statuses.each do |s|
xml.tag!('domain:status', 's' => s)
end
xml.tag!('domain:registrant', @domain.registrant_code)

View file

@ -100,6 +100,8 @@ en:
invalid: 'Statuses are invalid'
not_found: 'Status was not found'
taken: 'Status already exists on this domain'
statuses:
taken: 'Status already exists on this domain'
registrar:
blank: 'Registrar is missing'
dnskeys:

View file

@ -1592,11 +1592,10 @@ describe 'EPP Domain', epp: true do
new_contact = d.tech_contacts.find_by(code: 'FIXED:MAK21')
new_contact.should be_truthy
d.domain_statuses.count.should == 2
d.domain_statuses.first.description.should == 'Payment overdue.'
d.domain_statuses.first.value.should == 'clientHold'
d.statuses.count.should == 2
d.statuses.include?('clientHold').should == true
d.statuses.include?('clientUpdateProhibited').should == true
d.domain_statuses.last.value.should == 'clientUpdateProhibited'
d.dnskeys.count.should == 2
response = epp_plain_request(xml)
@ -1621,39 +1620,39 @@ describe 'EPP Domain', epp: true do
response[:results][2][:msg].should == 'Contact already exists on this domain [contact_code_cache]'
response[:results][2][:value].should == 'FIXED:MAK21'
response[:results][3][:msg].should == 'Status already exists on this domain [value]'
if response[:results][3][:value] == 'clientHold'
response[:results][3][:value].should == 'clientHold'
else
response[:results][3][:value].should == 'clientUpdateProhibited'
end
# response[:results][3][:msg].should == 'Status already exists on this domain [value]'
# if response[:results][3][:value] == 'clientHold'
# response[:results][3][:value].should == 'clientHold'
# else
# response[:results][3][:value].should == 'clientUpdateProhibited'
# end
response[:results][4][:msg].should == 'Status already exists on this domain [value]'
if response[:results][4][:value] == 'clientHold'
response[:results][4][:value].should == 'clientHold'
else
response[:results][4][:value].should == 'clientUpdateProhibited'
end
# response[:results][4][:msg].should == 'Status already exists on this domain [value]'
# if response[:results][4][:value] == 'clientHold'
# response[:results][4][:value].should == 'clientHold'
# else
# response[:results][4][:value].should == 'clientUpdateProhibited'
# end
response[:results][5][:msg].should == 'Public key already exists [public_key]'
if response[:results][5][:value] == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f'
response[:results][5][:value].should ==
response[:results][3][:msg].should == 'Public key already exists [public_key]'
if response[:results][3][:value] == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f'
response[:results][3][:value].should ==
'700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f'
else
response[:results][5][:value].should ==
response[:results][3][:value].should ==
'841936717ae427ace63c28d04918569a841936717ae427ace63c28d0'
end
response[:results][6][:msg].should == 'Public key already exists [public_key]'
if response[:results][6][:value] == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f'
response[:results][6][:value].should ==
response[:results][4][:msg].should == 'Public key already exists [public_key]'
if response[:results][4][:value] == '700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f'
response[:results][4][:value].should ==
'700b97b591ed27ec2590d19f06f88bba700b97b591ed27ec2590d19f'
else
response[:results][6][:value].should ==
response[:results][4][:value].should ==
'841936717ae427ace63c28d04918569a841936717ae427ace63c28d0'
end
d.domain_statuses.count.should == 2
d.statuses.count.should == 2
end
it 'updates domain with registrant change what triggers action pending' do
@ -2124,7 +2123,7 @@ describe 'EPP Domain', epp: true do
### INFO ###
it 'returns domain info' do
domain.domain_statuses.build(value: DomainStatus::CLIENT_HOLD, description: 'Payment overdue.')
domain.statuses << DomainStatus::CLIENT_HOLD
domain.nameservers.build(hostname: 'ns1.example.com', ipv4: '192.168.1.1', ipv6: '1080:0:0:0:8:800:200C:417A')
domain.dnskeys.build(
@ -2159,7 +2158,6 @@ describe 'EPP Domain', epp: true do
inf_data = response[:parsed].css('resData infData')
inf_data.css('name').text.should == domain.name
inf_data.css('status').text.should == 'Payment overdue.'
inf_data.css('status').first[:s].should == 'clientHold'
inf_data.css('registrant').text.should == domain.registrant_code
inf_data.css('roid').text.should == domain.roid