mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 02:39:37 +02:00
Move some code to epp domain
This commit is contained in:
parent
f0268a635a
commit
fe7ca94863
2 changed files with 32 additions and 45 deletions
|
@ -48,7 +48,6 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
before_create :generate_auth_info
|
||||
before_create :set_validity_dates
|
||||
before_create :attach_default_contacts
|
||||
before_save :touch_always_version
|
||||
def touch_always_version
|
||||
self.updated_at = Time.now
|
||||
|
@ -206,25 +205,6 @@ class Domain < ActiveRecord::Base
|
|||
end
|
||||
# rubocop:enable Lint/Loop
|
||||
|
||||
def attach_default_contacts
|
||||
if tech_domain_contacts.count.zero?
|
||||
attach_contact(DomainContact::TECH, owner_contact)
|
||||
end
|
||||
|
||||
return unless admin_domain_contacts.count.zero? && owner_contact.priv?
|
||||
attach_contact(DomainContact::ADMIN, owner_contact)
|
||||
end
|
||||
|
||||
def attach_contact(type, contact)
|
||||
domain_contacts.build(
|
||||
contact: contact, contact_type: DomainContact::TECH, contact_code_cache: contact.code
|
||||
) if type.to_sym == :tech
|
||||
|
||||
domain_contacts.build(
|
||||
contact: contact, contact_type: DomainContact::ADMIN, contact_code_cache: contact.code
|
||||
) if type.to_sym == :admin
|
||||
end
|
||||
|
||||
def set_validity_dates
|
||||
self.registered_at = Time.zone.now
|
||||
self.valid_from = Date.today
|
||||
|
|
|
@ -61,9 +61,29 @@ class Epp::EppDomain < Domain
|
|||
def self.new_from_epp(frame, current_user)
|
||||
domain = Epp::EppDomain.new
|
||||
domain.attributes = domain.attrs_from(frame, current_user)
|
||||
domain.attach_default_contacts
|
||||
domain
|
||||
end
|
||||
|
||||
def attach_default_contacts
|
||||
if tech_domain_contacts.count.zero?
|
||||
attach_contact(DomainContact::TECH, owner_contact)
|
||||
end
|
||||
|
||||
return unless admin_domain_contacts.count.zero? && owner_contact.priv?
|
||||
attach_contact(DomainContact::ADMIN, owner_contact)
|
||||
end
|
||||
|
||||
def attach_contact(type, contact)
|
||||
domain_contacts.build(
|
||||
contact: contact, contact_type: DomainContact::TECH, contact_code_cache: contact.code
|
||||
) if type.to_sym == :tech
|
||||
|
||||
domain_contacts.build(
|
||||
contact: contact, contact_type: DomainContact::ADMIN, contact_code_cache: contact.code
|
||||
) if type.to_sym == :admin
|
||||
end
|
||||
|
||||
def attrs_from(frame, current_user, action = nil)
|
||||
at = {}.with_indifferent_access
|
||||
|
||||
|
@ -185,38 +205,24 @@ class Epp::EppDomain < Domain
|
|||
errors.add(:base, :key_data_not_allowed)
|
||||
end
|
||||
|
||||
res = []
|
||||
# res = { ds_data: [], key_data: [] }
|
||||
|
||||
# res[:max_sig_life] = frame.css('maxSigLife').first.try(:text)
|
||||
|
||||
res = ds_data_from(frame, res)
|
||||
res = ds_data_from(frame)
|
||||
dnskeys_list = key_data_from(frame, res)
|
||||
|
||||
if action == 'rem'
|
||||
to_destroy = []
|
||||
|
||||
# TODO: Remove dnskeys based on ds_key_tag
|
||||
# dnskeys_list[:ds_data].each do |x|
|
||||
# ds = dnskeys.where(ds_key_tag: x[:ds_key_tag])
|
||||
# if ds.blank?
|
||||
# add_epp_error('2303', 'keyTag', x[:key_tag], [:dnskeys, :not_found])
|
||||
# else
|
||||
# to_destroy << ds
|
||||
# end
|
||||
# end
|
||||
|
||||
dnskeys_list.each do |x|
|
||||
ds = dnskeys.find_by(public_key: x[:public_key])
|
||||
if ds.blank?
|
||||
dk = dnskeys.find_by(public_key: x[:public_key])
|
||||
|
||||
unless dk
|
||||
add_epp_error('2303', 'publicKey', x[:public_key], [:dnskeys, :not_found])
|
||||
else
|
||||
next
|
||||
end
|
||||
|
||||
to_destroy << {
|
||||
id: ds.id,
|
||||
id: dk.id,
|
||||
_destroy: 1
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
return to_destroy
|
||||
else
|
||||
|
@ -239,7 +245,8 @@ class Epp::EppDomain < Domain
|
|||
res
|
||||
end
|
||||
|
||||
def ds_data_from(frame, res)
|
||||
def ds_data_from(frame)
|
||||
res = []
|
||||
frame.css('dsData').each do |x|
|
||||
data = {
|
||||
ds_key_tag: x.css('keyTag').first.try(:text),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue