mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
Refactor domain create
This commit is contained in:
parent
08fb2966d4
commit
050e251a58
4 changed files with 134 additions and 22 deletions
|
@ -17,7 +17,7 @@ class Admin::DomainsController < AdminController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
add_prefix_to_statuses
|
add_prefix_to_statuses
|
||||||
|
binding.pry
|
||||||
if @domain.update(domain_params)
|
if @domain.update(domain_params)
|
||||||
flash[:notice] = I18n.t('domain_updated')
|
flash[:notice] = I18n.t('domain_updated')
|
||||||
redirect_to [:admin, @domain]
|
redirect_to [:admin, @domain]
|
||||||
|
|
|
@ -2,7 +2,7 @@ class Epp::DomainsController < EppController
|
||||||
skip_authorization_check # TODO: remove it
|
skip_authorization_check # TODO: remove it
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@domain = Epp::EppDomain.new(domain_create_params)
|
@domain = Epp::EppDomain.new(params[:parsed_frame], current_user)
|
||||||
# @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'))
|
||||||
|
|
||||||
|
@ -51,15 +51,13 @@ class Epp::DomainsController < EppController
|
||||||
# @domain.parse_and_update_domain_dependencies(params[:parsed_frame].css('chg'))
|
# @domain.parse_and_update_domain_dependencies(params[:parsed_frame].css('chg'))
|
||||||
# @domain.attach_legal_document(Epp::EppDomain.parse_legal_document_from_frame(params[:parsed_frame]))
|
# @domain.attach_legal_document(Epp::EppDomain.parse_legal_document_from_frame(params[:parsed_frame]))
|
||||||
|
|
||||||
@domain.update_attributes(domain_rem_params)
|
# binding.pry
|
||||||
|
|
||||||
binding.pry
|
# if @domain.update(parsed_frame)
|
||||||
|
# handle_errors(@domain)
|
||||||
if @domain.errors.any? || !@domain.save
|
# else
|
||||||
handle_errors(@domain)
|
# render_epp_response '/epp/domains/success'
|
||||||
else
|
# end
|
||||||
render_epp_response '/epp/domains/success'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# rubocop: disable Metrics/PerceivedComplexity
|
# rubocop: disable Metrics/PerceivedComplexity
|
||||||
|
|
|
@ -68,10 +68,10 @@ class Domain < ActiveRecord::Base
|
||||||
|
|
||||||
validate :validate_period
|
validate :validate_period
|
||||||
|
|
||||||
validates :nameservers, object_count: {
|
# validates :nameservers, object_count: {
|
||||||
min: -> { Setting.ns_min_count },
|
# min: -> { Setting.ns_min_count },
|
||||||
max: -> { Setting.ns_max_count }
|
# max: -> { Setting.ns_max_count }
|
||||||
}
|
# }
|
||||||
|
|
||||||
validates :dnskeys, object_count: {
|
validates :dnskeys, object_count: {
|
||||||
min: -> { Setting.dnskeys_min_count },
|
min: -> { Setting.dnskeys_min_count },
|
||||||
|
@ -90,9 +90,9 @@ class Domain < ActiveRecord::Base
|
||||||
max: -> { Setting.tech_contacts_max_count }
|
max: -> { Setting.tech_contacts_max_count }
|
||||||
}
|
}
|
||||||
|
|
||||||
validates :nameservers, uniqueness_multi: {
|
# validates :nameservers, uniqueness_multi: {
|
||||||
attribute: 'hostname'
|
# attribute: 'hostname'
|
||||||
}
|
# }
|
||||||
|
|
||||||
validates :tech_domain_contacts, uniqueness_multi: {
|
validates :tech_domain_contacts, uniqueness_multi: {
|
||||||
association: 'domain_contacts',
|
association: 'domain_contacts',
|
||||||
|
@ -112,7 +112,7 @@ class Domain < ActiveRecord::Base
|
||||||
attribute: 'public_key'
|
attribute: 'public_key'
|
||||||
}
|
}
|
||||||
|
|
||||||
validate :validate_nameserver_ips
|
# validate :validate_nameserver_ips
|
||||||
|
|
||||||
attr_accessor :owner_contact_typeahead, :update_me
|
attr_accessor :owner_contact_typeahead, :update_me
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
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' => [
|
||||||
|
@ -60,11 +58,127 @@ class Epp::EppDomain < Domain
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.new_from_epp(domain_params)
|
# def self.new_from_epp(domain_params)
|
||||||
new(domain_params)
|
# new(domain_params)
|
||||||
|
# end
|
||||||
|
|
||||||
|
def initialize(frame, current_user)
|
||||||
|
super(attrs_from(frame, current_user))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def attrs_from(frame, current_user)
|
||||||
|
at = {}.with_indifferent_access
|
||||||
|
|
||||||
|
code = frame.css('registrant').first.try(:text)
|
||||||
|
oc = Contact.find_by(code: code).try(:id)
|
||||||
|
|
||||||
|
if oc
|
||||||
|
at[:owner_contact_id] = oc
|
||||||
|
else
|
||||||
|
add_epp_error('2303', 'registrant', code, [:owner_contact, :not_found])
|
||||||
|
end
|
||||||
|
|
||||||
|
at[:name] = frame.css('name').text
|
||||||
|
at[:registrar_id] = current_user.registrar.try(:id)
|
||||||
|
at[:registered_at] = Time.now if new_record?
|
||||||
|
|
||||||
|
period = frame.css('period').text
|
||||||
|
at[:period] = (period.to_i == 0) ? 1 : period.to_i
|
||||||
|
|
||||||
|
at[:period_unit] = Epp::EppDomain.parse_period_unit_from_frame(frame) || 'y'
|
||||||
|
at[:nameservers_attributes] = Epp::EppDomain.parse_nameservers_from_frame(frame)
|
||||||
|
at[:domain_contacts_attributes] = domain_contacts_from(frame)
|
||||||
|
at[:dnskeys_attributes] = dnskeys_from(frame.css('extension create'))
|
||||||
|
at[:legal_documents_attributes] = legal_document_from(frame)
|
||||||
|
|
||||||
|
at
|
||||||
|
end
|
||||||
|
|
||||||
|
def domain_contacts_from(frame)
|
||||||
|
res = []
|
||||||
|
frame.css('contact').each do |x|
|
||||||
|
c = Contact.find_by(code: x.text).try(:id)
|
||||||
|
|
||||||
|
unless c
|
||||||
|
add_epp_error('2303', 'contact', x.text, msg: I18n.t('contact_not_found'))
|
||||||
|
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 dnskeys_from(frame)
|
||||||
|
res = []
|
||||||
|
# res = { ds_data: [], key_data: [] }
|
||||||
|
|
||||||
|
# res[:max_sig_life] = frame.css('maxSigLife').first.try(:text)
|
||||||
|
|
||||||
|
res = ds_data_from(frame, res)
|
||||||
|
key_data_from(frame, res)
|
||||||
|
end
|
||||||
|
|
||||||
|
def key_data_from(frame, res)
|
||||||
|
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 ds_data_from(frame, res)
|
||||||
|
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 legal_document_from(frame)
|
||||||
|
ld = frame.css('legalDocument').first
|
||||||
|
return [] unless ld
|
||||||
|
|
||||||
|
[{
|
||||||
|
body: ld.text,
|
||||||
|
document_type: ld['type']
|
||||||
|
}]
|
||||||
|
end
|
||||||
|
|
||||||
|
# def update(frame)
|
||||||
|
# return super if frame.blank?
|
||||||
|
# at = {}.with_indifferent_access
|
||||||
|
# at.deep_merge!(self.class.attrs_from(frame.css('chg')))
|
||||||
|
# # legal_frame = frame.css('legalDocument').first
|
||||||
|
# # at[:legal_documents_attributes] = self.class.legal_document_attrs(legal_frame)
|
||||||
|
# end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue