mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 19:20:37 +02:00
Unit support for domain creating
This commit is contained in:
parent
2220846b9f
commit
cb2a5f0723
5 changed files with 49 additions and 9 deletions
|
@ -20,6 +20,10 @@ module Epp::Common
|
||||||
@params_hash ||= Hash.from_xml(params[:frame]).with_indifferent_access
|
@params_hash ||= Hash.from_xml(params[:frame]).with_indifferent_access
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parsed_frame
|
||||||
|
@parsed_frame ||= Nokogiri::XML(params[:frame]).remove_namespaces!
|
||||||
|
end
|
||||||
|
|
||||||
def epp_session
|
def epp_session
|
||||||
EppSession.find_or_initialize_by(session_id: cookies['session'])
|
EppSession.find_or_initialize_by(session_id: cookies['session'])
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ module Epp::DomainsHelper
|
||||||
Domain.transaction do
|
Domain.transaction do
|
||||||
@domain = Domain.new(domain_create_params)
|
@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
|
handle_errors(@domain) and return unless @domain.save
|
||||||
|
|
||||||
render '/epp/domains/create'
|
render '/epp/domains/create'
|
||||||
|
@ -40,7 +40,8 @@ module Epp::DomainsHelper
|
||||||
name: @ph[:name],
|
name: @ph[:name],
|
||||||
registrar_id: current_epp_user.registrar.try(:id),
|
registrar_id: current_epp_user.registrar.try(:id),
|
||||||
registered_at: Time.now,
|
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_from: Date.today,
|
||||||
valid_to: Date.today + @ph[:period].to_i.years,
|
valid_to: Date.today + @ph[:period].to_i.years,
|
||||||
auth_info: @ph[:authInfo][:pw]
|
auth_info: @ph[:authInfo][:pw]
|
||||||
|
|
|
@ -13,7 +13,8 @@ class Domain < ActiveRecord::Base
|
||||||
|
|
||||||
EPP_ATTR_MAP = {
|
EPP_ATTR_MAP = {
|
||||||
owner_contact: 'registrant',
|
owner_contact: 'registrant',
|
||||||
name_dirty: 'name'
|
name_dirty: 'name',
|
||||||
|
period: 'period'
|
||||||
}
|
}
|
||||||
|
|
||||||
belongs_to :registrar
|
belongs_to :registrar
|
||||||
|
@ -32,7 +33,7 @@ class Domain < ActiveRecord::Base
|
||||||
has_and_belongs_to_many :nameservers
|
has_and_belongs_to_many :nameservers
|
||||||
|
|
||||||
validates :name_dirty, domain_name: true, uniqueness: true
|
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 :name, :owner_contact, presence: true
|
||||||
|
|
||||||
validates_associated :nameservers
|
validates_associated :nameservers
|
||||||
|
@ -50,9 +51,9 @@ class Domain < ActiveRecord::Base
|
||||||
|
|
||||||
### CREATE ###
|
### CREATE ###
|
||||||
|
|
||||||
def attach_objects(ph, frame)
|
def attach_objects(ph, parsed_frame)
|
||||||
attach_owner_contact(ph[:registrant])
|
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]))
|
attach_nameservers(self.class.parse_nameservers_from_params(ph[:ns]))
|
||||||
|
|
||||||
errors.empty?
|
errors.empty?
|
||||||
|
@ -173,9 +174,7 @@ class Domain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def parse_contacts_from_frame(frame)
|
def parse_contacts_from_frame(parsed_frame)
|
||||||
parsed_frame = Nokogiri::XML(frame).remove_namespaces!
|
|
||||||
|
|
||||||
res = {}
|
res = {}
|
||||||
Contact::CONTACT_TYPES.each do |ct|
|
Contact::CONTACT_TYPES.each do |ct|
|
||||||
res[ct.to_sym] ||= []
|
res[ct.to_sym] ||= []
|
||||||
|
@ -194,6 +193,12 @@ class Domain < ActiveRecord::Base
|
||||||
[]
|
[]
|
||||||
end
|
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)
|
def check_availability(domains)
|
||||||
domains = [domains] if domains.is_a?(String)
|
domains = [domains] if domains.is_a?(String)
|
||||||
|
|
||||||
|
|
|
@ -101,6 +101,12 @@ describe 'EPP Domain', epp: true do
|
||||||
expect(response[:results][0][:result_code]).to eq '2005'
|
expect(response[:results][0][:result_code]).to eq '2005'
|
||||||
expect(response[:results][0][:msg]).to eq 'IP is invalid'
|
expect(response[:results][0][:msg]).to eq 'IP is invalid'
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'with juridical persion as an owner' do
|
context 'with juridical persion as an owner' do
|
||||||
|
|
24
spec/epp/requests/domains/create_w_period_in_days.xml
Normal file
24
spec/epp/requests/domains/create_w_period_in_days.xml
Normal 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>
|
Loading…
Add table
Add a link
Reference in a new issue