Unit support for domain creating

This commit is contained in:
Martin Lensment 2014-08-12 15:19:17 +03:00
parent 2220846b9f
commit cb2a5f0723
5 changed files with 49 additions and 9 deletions

View file

@ -20,6 +20,10 @@ module Epp::Common
@params_hash ||= Hash.from_xml(params[:frame]).with_indifferent_access
end
def parsed_frame
@parsed_frame ||= Nokogiri::XML(params[:frame]).remove_namespaces!
end
def epp_session
EppSession.find_or_initialize_by(session_id: cookies['session'])
end

View file

@ -3,7 +3,7 @@ module Epp::DomainsHelper
Domain.transaction do
@domain = Domain.new(domain_create_params)
handle_errors(@domain) and return unless @domain.attach_objects(@ph, params[:frame])
handle_errors(@domain) and return unless @domain.attach_objects(@ph, parsed_frame)
handle_errors(@domain) and return unless @domain.save
render '/epp/domains/create'
@ -40,7 +40,8 @@ module Epp::DomainsHelper
name: @ph[:name],
registrar_id: current_epp_user.registrar.try(:id),
registered_at: Time.now,
period: @ph[:period].to_i,
period: (@ph[:period].to_i == 0) ? 1 : @ph[:period].to_i,
period_unit: Domain.parse_period_unit_from_frame(parsed_frame) || 'y',
valid_from: Date.today,
valid_to: Date.today + @ph[:period].to_i.years,
auth_info: @ph[:authInfo][:pw]

View file

@ -13,7 +13,8 @@ class Domain < ActiveRecord::Base
EPP_ATTR_MAP = {
owner_contact: 'registrant',
name_dirty: 'name'
name_dirty: 'name',
period: 'period'
}
belongs_to :registrar
@ -32,7 +33,7 @@ class Domain < ActiveRecord::Base
has_and_belongs_to_many :nameservers
validates :name_dirty, domain_name: true, uniqueness: true
validates :period, numericality: { only_integer: true, greater_than: 0, less_than: 100 }
validates :period, numericality: { only_integer: true }
validates :name, :owner_contact, presence: true
validates_associated :nameservers
@ -50,9 +51,9 @@ class Domain < ActiveRecord::Base
### CREATE ###
def attach_objects(ph, frame)
def attach_objects(ph, parsed_frame)
attach_owner_contact(ph[:registrant])
attach_contacts(self.class.parse_contacts_from_frame(frame))
attach_contacts(self.class.parse_contacts_from_frame(parsed_frame))
attach_nameservers(self.class.parse_nameservers_from_params(ph[:ns]))
errors.empty?
@ -173,9 +174,7 @@ class Domain < ActiveRecord::Base
end
class << self
def parse_contacts_from_frame(frame)
parsed_frame = Nokogiri::XML(frame).remove_namespaces!
def parse_contacts_from_frame(parsed_frame)
res = {}
Contact::CONTACT_TYPES.each do |ct|
res[ct.to_sym] ||= []
@ -194,6 +193,12 @@ class Domain < ActiveRecord::Base
[]
end
def parse_period_unit_from_frame(parsed_frame)
p = parsed_frame.css('period').first
return nil unless p
p[:unit]
end
def check_availability(domains)
domains = [domains] if domains.is_a?(String)

View file

@ -101,6 +101,12 @@ describe 'EPP Domain', epp: true do
expect(response[:results][0][:result_code]).to eq '2005'
expect(response[:results][0][:msg]).to eq 'IP is invalid'
end
it 'creates a domain with period in days' do
response = epp_request('domains/create_w_period_in_days.xml')
expect(response[:result_code]).to eq('1000')
expect(response[:msg]).to eq('Command completed successfully')
end
end
context 'with juridical persion as an owner' do

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
<command>
<create>
<domain:create
xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">
<domain:name>example.ee</domain:name>
<domain:period unit="d">365</domain:period>
<domain:ns>
<domain:hostObj>ns1.example.net</domain:hostObj>
<domain:hostObj>ns2.example.net</domain:hostObj>
</domain:ns>
<domain:registrant>jd1234</domain:registrant>
<domain:contact type="admin">sh8013</domain:contact>
<domain:contact type="tech">sh8013</domain:contact>
<domain:contact type="tech">sh801333</domain:contact>
<domain:authInfo>
<domain:pw>2fooBAR</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<clTRID>ABC-12345</clTRID>
</command>
</epp>