mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
Create domain works with nested attributes
This commit is contained in:
parent
037cb57e00
commit
27d19ad237
4 changed files with 124 additions and 6 deletions
|
@ -1,9 +1,8 @@
|
||||||
class Epp::DomainsController < EppController
|
class Epp::DomainsController < EppController
|
||||||
def create
|
def create
|
||||||
@domain = Epp::EppDomain.new(domain_create_params)
|
@domain = Epp::EppDomain.new(domain_create_params)
|
||||||
|
# @domain.parse_and_attach_domain_dependencies(params[:parsed_frame])
|
||||||
@domain.parse_and_attach_domain_dependencies(params[:parsed_frame])
|
# @domain.parse_and_attach_ds_data(params[:parsed_frame].css('extension create'))
|
||||||
@domain.parse_and_attach_ds_data(params[:parsed_frame].css('extension create'))
|
|
||||||
|
|
||||||
if @domain.errors.any? || !@domain.save
|
if @domain.errors.any? || !@domain.save
|
||||||
handle_errors(@domain)
|
handle_errors(@domain)
|
||||||
|
@ -171,18 +170,118 @@ class Epp::DomainsController < EppController
|
||||||
end
|
end
|
||||||
|
|
||||||
def domain_create_params
|
def domain_create_params
|
||||||
name = params[:parsed_frame].css('name').text
|
|
||||||
period = params[:parsed_frame].css('period').text
|
period = params[:parsed_frame].css('period').text
|
||||||
|
|
||||||
|
# registrant = parse_registrant(params)
|
||||||
|
# domain_contacts = parse_domain_contacts_from_epp(params)
|
||||||
|
|
||||||
|
registrant_code = params[:parsed_frame].css('registrant').text
|
||||||
|
owner_contact = Contact.find_by(code: registrant_code)
|
||||||
|
|
||||||
|
unless owner_contact
|
||||||
|
epp_errors << {
|
||||||
|
code: '2303',
|
||||||
|
msg: I18n.t('registrant_not_found'),
|
||||||
|
value: { obj: 'registrant', val: registrant_code }
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
{
|
{
|
||||||
name: name,
|
name: params[:parsed_frame].css('name').text,
|
||||||
registrar_id: current_user.registrar.try(:id),
|
registrar_id: current_user.registrar.try(:id),
|
||||||
registered_at: Time.now,
|
registered_at: Time.now,
|
||||||
period: (period.to_i == 0) ? 1 : period.to_i,
|
period: (period.to_i == 0) ? 1 : period.to_i,
|
||||||
period_unit: Epp::EppDomain.parse_period_unit_from_frame(params[:parsed_frame]) || 'y'
|
period_unit: Epp::EppDomain.parse_period_unit_from_frame(params[:parsed_frame]) || 'y',
|
||||||
|
owner_contact_id: owner_contact.try(:id),
|
||||||
|
nameservers_attributes: Epp::EppDomain.parse_nameservers_from_frame(params[:parsed_frame]),
|
||||||
|
domain_contacts_attributes: parse_domain_contacts_from_epp,
|
||||||
|
dnskeys_attributes: parse_dnskeys_from_frame(params[:parsed_frame].css('extension create')),
|
||||||
|
legal_documents_attributes: parse_legal_document_from_frame(params[:parsed_frame])
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parse_domain_contacts_from_epp
|
||||||
|
res = []
|
||||||
|
params[:parsed_frame].css('contact').each do |x|
|
||||||
|
c = Contact.find_by(code: x.text).try(:id)
|
||||||
|
|
||||||
|
unless c
|
||||||
|
epp_errors << {
|
||||||
|
code: '2303',
|
||||||
|
msg: I18n.t('contact_not_found'),
|
||||||
|
value: { obj: 'contact', val: x.text }
|
||||||
|
}
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
res << {
|
||||||
|
contact_id: Contact.find_by(code: x.text).try(:id),
|
||||||
|
contact_type: x['type'],
|
||||||
|
contact_code_cache: x.text
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
res
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_dnskeys_from_frame(parsed_frame)
|
||||||
|
res = []
|
||||||
|
# res = { ds_data: [], key_data: [] }
|
||||||
|
|
||||||
|
# res[:max_sig_life] = parsed_frame.css('maxSigLife').first.try(:text)
|
||||||
|
|
||||||
|
res = parse_ds_data_from_frame(parsed_frame, res)
|
||||||
|
parse_key_data_from_frame(parsed_frame, res)
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_key_data_from_frame(parsed_frame, res)
|
||||||
|
parsed_frame.xpath('keyData').each do |x|
|
||||||
|
res << {
|
||||||
|
flags: x.css('flags').first.try(:text),
|
||||||
|
protocol: x.css('protocol').first.try(:text),
|
||||||
|
alg: x.css('alg').first.try(:text),
|
||||||
|
public_key: x.css('pubKey').first.try(:text),
|
||||||
|
ds_alg: 3,
|
||||||
|
ds_digest_type: Setting.ds_algorithm
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
res
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_ds_data_from_frame(parsed_frame, res)
|
||||||
|
parsed_frame.css('dsData').each do |x|
|
||||||
|
data = {
|
||||||
|
ds_key_tag: x.css('keyTag').first.try(:text),
|
||||||
|
ds_alg: x.css('alg').first.try(:text),
|
||||||
|
ds_digest_type: x.css('digestType').first.try(:text),
|
||||||
|
ds_digest: x.css('digest').first.try(:text)
|
||||||
|
}
|
||||||
|
|
||||||
|
kd = x.css('keyData').first
|
||||||
|
data.merge!({
|
||||||
|
flags: kd.css('flags').first.try(:text),
|
||||||
|
protocol: kd.css('protocol').first.try(:text),
|
||||||
|
alg: kd.css('alg').first.try(:text),
|
||||||
|
public_key: kd.css('pubKey').first.try(:text)
|
||||||
|
}) if kd
|
||||||
|
|
||||||
|
res << data
|
||||||
|
end
|
||||||
|
|
||||||
|
res
|
||||||
|
end
|
||||||
|
|
||||||
|
def parse_legal_document_from_frame(parsed_frame)
|
||||||
|
ld = parsed_frame.css('legalDocument').first
|
||||||
|
return [] unless ld
|
||||||
|
|
||||||
|
[{
|
||||||
|
body: ld.text,
|
||||||
|
document_type: ld['type']
|
||||||
|
}]
|
||||||
|
end
|
||||||
|
|
||||||
def domain_transfer_params
|
def domain_transfer_params
|
||||||
res = {}
|
res = {}
|
||||||
res[:pw] = params[:parsed_frame].css('pw').first.try(:text)
|
res[:pw] = params[:parsed_frame].css('pw').first.try(:text)
|
||||||
|
|
|
@ -41,6 +41,7 @@ class Domain < ActiveRecord::Base
|
||||||
reject_if: proc { |attrs| attrs[:public_key].blank? }
|
reject_if: proc { |attrs| attrs[:public_key].blank? }
|
||||||
|
|
||||||
has_many :legal_documents, as: :documentable
|
has_many :legal_documents, as: :documentable
|
||||||
|
accepts_nested_attributes_for :legal_documents, reject_if: proc { |attrs| attrs[:body].blank? }
|
||||||
|
|
||||||
delegate :code, to: :owner_contact, prefix: true
|
delegate :code, to: :owner_contact, prefix: true
|
||||||
delegate :email, to: :owner_contact, prefix: true
|
delegate :email, to: :owner_contact, prefix: true
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
class Epp::EppDomain < Domain
|
class Epp::EppDomain < Domain
|
||||||
include EppErrors
|
include EppErrors
|
||||||
|
|
||||||
|
accepts_nested_attributes_for :nameservers
|
||||||
|
|
||||||
def epp_code_map # rubocop:disable Metrics/MethodLength
|
def epp_code_map # rubocop:disable Metrics/MethodLength
|
||||||
{
|
{
|
||||||
'2002' => [
|
'2002' => [
|
||||||
|
@ -58,6 +60,21 @@ class Epp::EppDomain < Domain
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.new_from_epp(domain_params)
|
||||||
|
new(domain_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def parse_and_attach_domain_dependencies(parsed_frame)
|
def parse_and_attach_domain_dependencies(parsed_frame)
|
||||||
attach_owner_contact(self.class.parse_owner_contact_from_frame(parsed_frame))
|
attach_owner_contact(self.class.parse_owner_contact_from_frame(parsed_frame))
|
||||||
attach_contacts(self.class.parse_contacts_from_frame(parsed_frame))
|
attach_contacts(self.class.parse_contacts_from_frame(parsed_frame))
|
||||||
|
|
|
@ -501,3 +501,4 @@ en:
|
||||||
address_help: 'Street name, house no - apartment no, city, county, country, zip'
|
address_help: 'Street name, house no - apartment no, city, county, country, zip'
|
||||||
download: 'Download'
|
download: 'Download'
|
||||||
failed_to_create_certificate: 'Failed to create certificate!'
|
failed_to_create_certificate: 'Failed to create certificate!'
|
||||||
|
registrant_not_found: 'Registrant not found'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue