mirror of
https://github.com/internetee/registry.git
synced 2025-08-04 00:42:04 +02:00
Address depricated, new contact requires, domain_contacts refactor
This commit is contained in:
parent
0e252b0b6b
commit
5fd73b037a
38 changed files with 402 additions and 501 deletions
|
@ -89,8 +89,8 @@ class Epp::ContactsController < EppController
|
|||
def validate_create
|
||||
@prefix = 'create > create >'
|
||||
requires(
|
||||
'postalInfo > name', 'postalInfo > addr > city',
|
||||
'postalInfo > addr > cc', 'voice', 'email'
|
||||
'postalInfo > name', 'postalInfo > addr > street', 'postalInfo > addr > city',
|
||||
'postalInfo > addr > pc', 'postalInfo > addr > cc', 'voice', 'email'
|
||||
)
|
||||
ident = params[:parsed_frame].css('ident')
|
||||
if ident.present? && ident.text != 'birthday' && ident.attr('cc').blank?
|
||||
|
|
|
@ -4,17 +4,6 @@ class Epp::DomainsController < EppController
|
|||
before_action :find_domain, only: [:info, :renew, :update, :transfer, :delete]
|
||||
before_action :find_password, only: [:info, :update, :transfer, :delete]
|
||||
|
||||
def create
|
||||
authorize! :create, Epp::Domain
|
||||
@domain = Epp::Domain.new_from_epp(params[:parsed_frame], current_user)
|
||||
|
||||
if @domain.errors.any? || !@domain.save
|
||||
handle_errors(@domain)
|
||||
else
|
||||
render_epp_response '/epp/domains/create'
|
||||
end
|
||||
end
|
||||
|
||||
def info
|
||||
authorize! :info, @domain, @password
|
||||
@hosts = params[:parsed_frame].css('name').first['hosts'] || 'all'
|
||||
|
@ -31,6 +20,44 @@ class Epp::DomainsController < EppController
|
|||
render_epp_response '/epp/domains/info'
|
||||
end
|
||||
|
||||
def create
|
||||
authorize! :create, Epp::Domain
|
||||
@domain = Epp::Domain.new_from_epp(params[:parsed_frame], current_user)
|
||||
|
||||
if @domain.errors.any? || !@domain.save
|
||||
handle_errors(@domain)
|
||||
else
|
||||
render_epp_response '/epp/domains/create'
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def update
|
||||
authorize! :update, @domain, @password
|
||||
|
||||
if @domain.update(params[:parsed_frame], current_user)
|
||||
render_epp_response '/epp/domains/success'
|
||||
else
|
||||
handle_errors(@domain)
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def delete
|
||||
# all includes for bullet
|
||||
@domain = Epp::Domain.where(id: @domain.id).includes(nameservers: :versions).first
|
||||
|
||||
handle_errors(@domain) and return unless @domain.can_be_deleted?
|
||||
|
||||
@domain.attach_legal_document(Epp::Domain.parse_legal_document_from_frame(params[:parsed_frame]))
|
||||
@domain.save(validate: false)
|
||||
|
||||
handle_errors(@domain) and return unless @domain.destroy
|
||||
|
||||
render_epp_response '/epp/domains/success'
|
||||
end
|
||||
# rubocop:enbale Metrics/CyclomaticComplexity
|
||||
|
||||
def check
|
||||
authorize! :check, Epp::Domain
|
||||
|
||||
|
@ -51,20 +78,8 @@ class Epp::DomainsController < EppController
|
|||
render_epp_response '/epp/domains/renew'
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
def update
|
||||
authorize! :update, @domain, @password
|
||||
|
||||
if @domain.update(params[:parsed_frame], current_user)
|
||||
render_epp_response '/epp/domains/success'
|
||||
else
|
||||
handle_errors(@domain)
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop: disable Metrics/PerceivedComplexity
|
||||
# rubocop: disable Metrics/MethodLength
|
||||
|
||||
def transfer
|
||||
authorize! :transfer, @domain, @password
|
||||
action = params[:parsed_frame].css('transfer').first[:op]
|
||||
|
@ -77,22 +92,8 @@ class Epp::DomainsController < EppController
|
|||
handle_errors(@domain)
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop: enable Metrics/MethodLength
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
# rubocop:disable Metrics/CyclomaticComplexity
|
||||
|
||||
def delete
|
||||
handle_errors(@domain) and return unless @domain.can_be_deleted?
|
||||
|
||||
@domain.attach_legal_document(Epp::Domain.parse_legal_document_from_frame(params[:parsed_frame]))
|
||||
@domain.save(validate: false)
|
||||
|
||||
handle_errors(@domain) and return unless @domain.destroy
|
||||
|
||||
render_epp_response '/epp/domains/success'
|
||||
end
|
||||
# rubocop:enbale Metrics/CyclomaticComplexity
|
||||
|
||||
private
|
||||
|
||||
|
@ -102,11 +103,6 @@ class Epp::DomainsController < EppController
|
|||
optional_attribute 'name', 'hosts', values: %(all, sub, del, none)
|
||||
end
|
||||
|
||||
def validate_check
|
||||
@prefix = 'check > check >'
|
||||
requires('name')
|
||||
end
|
||||
|
||||
def validate_create
|
||||
@prefix = 'create > create >'
|
||||
requires 'name', 'ns', 'registrant', 'ns > hostAttr'
|
||||
|
@ -120,11 +116,6 @@ class Epp::DomainsController < EppController
|
|||
status_editing_disabled
|
||||
end
|
||||
|
||||
def validate_renew
|
||||
@prefix = 'renew > renew >'
|
||||
requires 'name', 'curExpDate', 'period'
|
||||
end
|
||||
|
||||
def validate_update
|
||||
if element_count('update > chg > registrant') > 0
|
||||
requires 'extension > extdata > legalDocument'
|
||||
|
@ -136,7 +127,23 @@ class Epp::DomainsController < EppController
|
|||
status_editing_disabled
|
||||
end
|
||||
|
||||
## TRANSFER
|
||||
def validate_delete
|
||||
requires 'extension > extdata > legalDocument'
|
||||
|
||||
@prefix = 'delete > delete >'
|
||||
requires 'name'
|
||||
end
|
||||
|
||||
def validate_check
|
||||
@prefix = 'check > check >'
|
||||
requires('name')
|
||||
end
|
||||
|
||||
def validate_renew
|
||||
@prefix = 'renew > renew >'
|
||||
requires 'name', 'curExpDate', 'period'
|
||||
end
|
||||
|
||||
def validate_transfer
|
||||
requires 'transfer > transfer'
|
||||
|
||||
|
@ -147,14 +154,6 @@ class Epp::DomainsController < EppController
|
|||
requires_attribute 'transfer', 'op', values: %(approve, query, reject)
|
||||
end
|
||||
|
||||
## DELETE
|
||||
def validate_delete
|
||||
requires 'extension > extdata > legalDocument'
|
||||
|
||||
@prefix = 'delete > delete >'
|
||||
requires 'name'
|
||||
end
|
||||
|
||||
def find_domain
|
||||
domain_name = params[:parsed_frame].css('name').text.strip.downcase
|
||||
@domain = Epp::Domain.where(name: domain_name).first
|
||||
|
|
|
@ -56,10 +56,15 @@ class EppController < ApplicationController
|
|||
end
|
||||
|
||||
# for debugging
|
||||
@errors << {
|
||||
code: '1',
|
||||
msg: 'handle_errors was executed when there were actually no errors'
|
||||
} if @errors.blank?
|
||||
if @errors.blank?
|
||||
@errors << {
|
||||
code: '1',
|
||||
msg: 'handle_errors was executed when there were actually no errors'
|
||||
}
|
||||
# rubocop:disable Rails/Output
|
||||
puts obj.errors.full_messages if Rails.env.test?
|
||||
# rubocop: enable Rails/Output
|
||||
end
|
||||
|
||||
@errors.uniq!
|
||||
|
||||
|
|
2
app/models/admin_domain_contact.rb
Normal file
2
app/models/admin_domain_contact.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class AdminDomainContact < DomainContact
|
||||
end
|
|
@ -1,23 +1,20 @@
|
|||
class Contact < ActiveRecord::Base
|
||||
include Versions # version/contact_version.rb
|
||||
|
||||
has_one :address, dependent: :destroy
|
||||
has_one :disclosure, class_name: 'ContactDisclosure', dependent: :destroy
|
||||
|
||||
belongs_to :registrar
|
||||
has_many :domain_contacts
|
||||
has_many :domains, through: :domain_contacts
|
||||
has_many :statuses, class_name: 'ContactStatus'
|
||||
has_many :statuses, class_name: 'ContactStatus', dependent: :destroy
|
||||
has_many :legal_documents, as: :documentable
|
||||
|
||||
belongs_to :registrar
|
||||
|
||||
accepts_nested_attributes_for :address, :disclosure, :legal_documents
|
||||
accepts_nested_attributes_for :legal_documents
|
||||
|
||||
attr_accessor :code_overwrite_allowed
|
||||
|
||||
validates :name, :phone, :email, :ident, :address, :registrar, :ident_type, presence: true
|
||||
validates :name, :phone, :email, :ident, :ident_type,
|
||||
:street, :city, :zip, :country_code, :registrar, presence: true
|
||||
|
||||
# # Phone nr validation is very minimam in order to support legacy requirements
|
||||
# Phone nr validation is very minimam in order to support legacy requirements
|
||||
validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/
|
||||
validates :email, format: /@/
|
||||
validates :ident,
|
||||
|
@ -28,20 +25,11 @@ class Contact < ActiveRecord::Base
|
|||
uniqueness: { message: :epp_id_taken },
|
||||
format: { with: /\A[\w\-\:]*\Z/i },
|
||||
length: { maximum: 100 }
|
||||
|
||||
validate :ident_valid_format?
|
||||
|
||||
delegate :street, to: :address
|
||||
delegate :city, to: :address
|
||||
delegate :zip, to: :address
|
||||
delegate :state, to: :address
|
||||
delegate :country_code, to: :address
|
||||
delegate :country, to: :address
|
||||
|
||||
before_validation :set_ident_country_code
|
||||
before_create :generate_code
|
||||
before_create :generate_auth_info
|
||||
after_create :ensure_disclosure
|
||||
after_save :manage_statuses
|
||||
def manage_statuses
|
||||
ContactStatus.manage(statuses, self)
|
||||
|
@ -50,17 +38,13 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
scope :current_registrars, ->(id) { where(registrar_id: id) }
|
||||
|
||||
IDENT_TYPE_BIC = 'bic'
|
||||
BIC = 'bic'
|
||||
IDENT_TYPES = [
|
||||
IDENT_TYPE_BIC, # Company registry code (or similar)
|
||||
BIC, # Company registry code (or similar)
|
||||
'priv', # National idendtification number
|
||||
'birthday' # Birthday date
|
||||
]
|
||||
|
||||
CONTACT_TYPE_TECH = 'tech'
|
||||
CONTACT_TYPE_ADMIN = 'admin'
|
||||
CONTACT_TYPES = [CONTACT_TYPE_TECH, CONTACT_TYPE_ADMIN]
|
||||
|
||||
class << self
|
||||
def search_by_query(query)
|
||||
res = search(code_cont: query).result
|
||||
|
@ -81,6 +65,22 @@ class Contact < ActiveRecord::Base
|
|||
|
||||
res
|
||||
end
|
||||
|
||||
def find_orphans
|
||||
Contact.where('
|
||||
NOT EXISTS(
|
||||
select 1 from domains d where d.owner_contact_id = contacts.id
|
||||
) AND NOT EXISTS(
|
||||
select 1 from domain_contacts dc where dc.contact_id = contacts.id
|
||||
)
|
||||
')
|
||||
end
|
||||
|
||||
def destroy_orphans
|
||||
logger.info "#{Time.now.utc} - Destroying orphaned contacts\n"
|
||||
count = find_orphans.destroy_all.count
|
||||
logger.info "#{Time.now.utc} - Successfully destroyed #{count} orphaned contacts\n"
|
||||
end
|
||||
end
|
||||
|
||||
def to_s
|
||||
|
@ -98,16 +98,12 @@ class Contact < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def ensure_disclosure
|
||||
create_disclosure! unless disclosure
|
||||
end
|
||||
|
||||
def bic?
|
||||
ident_type == IDENT_TYPE_BIC
|
||||
ident_type == BIC
|
||||
end
|
||||
|
||||
def priv?
|
||||
ident_type != IDENT_TYPE_BIC
|
||||
ident_type != BIC
|
||||
end
|
||||
|
||||
def generate_code
|
||||
|
@ -131,6 +127,10 @@ class Contact < ActiveRecord::Base
|
|||
self[:code] = code if new_record? || code_overwrite_allowed
|
||||
end
|
||||
|
||||
def country
|
||||
Country.new(country_code)
|
||||
end
|
||||
|
||||
# Find a way to use self.domains with contact
|
||||
def domains_owned
|
||||
Domain.where(owner_contact_id: id)
|
||||
|
@ -161,22 +161,4 @@ class Contact < ActiveRecord::Base
|
|||
errors.add(:ident_country_code, 'is not following ISO_3166-1 alpha 2 format')
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
def find_orphans
|
||||
Contact.where('
|
||||
NOT EXISTS(
|
||||
select 1 from domains d where d.owner_contact_id = contacts.id
|
||||
) AND NOT EXISTS(
|
||||
select 1 from domain_contacts dc where dc.contact_id = contacts.id
|
||||
)
|
||||
')
|
||||
end
|
||||
|
||||
def destroy_orphans
|
||||
logger.info "#{Time.now.utc} - Destroying orphaned contacts\n"
|
||||
count = find_orphans.destroy_all.count
|
||||
logger.info "#{Time.now.utc} - Successfully destroyed #{count} orphaned contacts\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
class ContactDisclosure < ActiveRecord::Base
|
||||
include Versions # version/contact_disclosure_version.rb
|
||||
belongs_to :contact
|
||||
|
||||
def attributes_with_flag
|
||||
attrs, policy = { name: name, email: email, phone: phone, address: address, org_name: org_name, fax: fax }, {}
|
||||
policy[0] = attrs.map { |k, v| k if v == false }.compact
|
||||
policy[1] = attrs.map { |k, v| k if v }.compact
|
||||
policy
|
||||
end
|
||||
|
||||
def as_hash
|
||||
{
|
||||
name: name,
|
||||
org_name: org_name,
|
||||
phone: phone,
|
||||
fax: fax,
|
||||
email: email,
|
||||
address: address
|
||||
}
|
||||
end
|
||||
|
||||
# value is true or false depending on disclosure flag
|
||||
# rules are the contents of disclose element
|
||||
class << self
|
||||
def default_values
|
||||
@dc = {
|
||||
name: Setting.disclosure_name,
|
||||
org_name: Setting.disclosure_org_name,
|
||||
phone: Setting.disclosure_phone,
|
||||
fax: Setting.disclosure_fax,
|
||||
email: Setting.disclosure_email,
|
||||
address: Setting.disclosure_address
|
||||
}
|
||||
@dc
|
||||
end
|
||||
|
||||
def extract_attributes(parsed_frame)
|
||||
disclosure_hash = {}
|
||||
rules = parsed_frame.css('disclose').first
|
||||
return disclosure_hash unless rules.present?
|
||||
value = rules.attributes['flag'].value
|
||||
disclosure_hash = parse_disclose_xml(rules)
|
||||
|
||||
disclosure_hash.each do |k, _v| # provides a correct flag to disclosure elements
|
||||
disclosure_hash[k] = value
|
||||
end
|
||||
disclosure_hash
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Returns list of disclosure elements present.
|
||||
def parse_disclose_xml(rules)
|
||||
{ name: parse_element_attributes_for('name', rules.children),
|
||||
org_name: parse_element_attributes_for('org_name', rules.children),
|
||||
address: parse_element_attributes_for('addr', rules.children),
|
||||
phone: rules.css('voice').present?,
|
||||
email: rules.css('email').present?,
|
||||
fax: rules.css('fax').present?
|
||||
}.delete_if { |_k, v| v.nil? || v == false }
|
||||
end
|
||||
|
||||
def parse_element_attributes_for(el, rules)
|
||||
return true if rules.css(el).present?
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,31 +9,28 @@ class Domain < ActiveRecord::Base
|
|||
belongs_to :registrar
|
||||
belongs_to :owner_contact, class_name: 'Contact'
|
||||
|
||||
has_many :domain_contacts, dependent: :delete_all
|
||||
accepts_nested_attributes_for :domain_contacts, allow_destroy: true
|
||||
|
||||
has_many :tech_contacts,
|
||||
-> { where(domain_contacts: { contact_type: DomainContact::TECH }) },
|
||||
through: :domain_contacts, source: :contact
|
||||
|
||||
has_many :admin_contacts,
|
||||
-> { where(domain_contacts: { contact_type: DomainContact::ADMIN }) },
|
||||
through: :domain_contacts, source: :contact
|
||||
has_many :domain_contacts, dependent: :destroy
|
||||
has_many :admin_domain_contacts
|
||||
accepts_nested_attributes_for :admin_domain_contacts, allow_destroy: true
|
||||
has_many :tech_domain_contacts
|
||||
accepts_nested_attributes_for :tech_domain_contacts, allow_destroy: true
|
||||
|
||||
has_many :contacts, through: :domain_contacts, source: :contact
|
||||
has_many :admin_contacts, through: :admin_domain_contacts, source: :contact
|
||||
has_many :tech_contacts, through: :tech_domain_contacts, source: :contact
|
||||
|
||||
has_many :nameservers, dependent: :delete_all
|
||||
has_many :nameservers, dependent: :destroy
|
||||
|
||||
accepts_nested_attributes_for :nameservers, allow_destroy: true,
|
||||
reject_if: proc { |attrs| attrs[:hostname].blank? }
|
||||
|
||||
has_many :domain_statuses, dependent: :delete_all
|
||||
has_many :domain_statuses, dependent: :destroy
|
||||
accepts_nested_attributes_for :domain_statuses, allow_destroy: true,
|
||||
reject_if: proc { |attrs| attrs[:value].blank? }
|
||||
|
||||
has_many :domain_transfers, dependent: :delete_all
|
||||
has_many :domain_transfers, dependent: :destroy
|
||||
|
||||
has_many :dnskeys, dependent: :delete_all
|
||||
has_many :dnskeys, dependent: :destroy
|
||||
|
||||
has_many :keyrelays
|
||||
|
||||
|
@ -55,12 +52,12 @@ class Domain < ActiveRecord::Base
|
|||
self.updated_at = Time.now
|
||||
end
|
||||
before_save :update_whois_body
|
||||
after_save :manage_automatic_statuses
|
||||
after_save :delay_whois_server_update
|
||||
def delay_whois_server_update
|
||||
return if whois_body.blank?
|
||||
delay.whois_server_update(name, whois_body)
|
||||
end
|
||||
after_save :manage_automatic_statuses
|
||||
|
||||
validates :name_dirty, domain_name: true, uniqueness: true
|
||||
validates :period, numericality: { only_integer: true }
|
||||
|
@ -79,13 +76,11 @@ class Domain < ActiveRecord::Base
|
|||
}
|
||||
|
||||
validates :admin_domain_contacts, object_count: {
|
||||
association: 'admin_contacts',
|
||||
min: -> { Setting.admin_contacts_min_count },
|
||||
max: -> { Setting.admin_contacts_max_count }
|
||||
}
|
||||
|
||||
validates :tech_domain_contacts, object_count: {
|
||||
association: 'tech_contacts',
|
||||
min: -> { Setting.tech_contacts_min_count },
|
||||
max: -> { Setting.tech_contacts_max_count }
|
||||
}
|
||||
|
@ -95,12 +90,10 @@ class Domain < ActiveRecord::Base
|
|||
}
|
||||
|
||||
validates :tech_domain_contacts, uniqueness_multi: {
|
||||
association: 'domain_contacts',
|
||||
attribute: 'contact_code_cache'
|
||||
}
|
||||
|
||||
validates :admin_domain_contacts, uniqueness_multi: {
|
||||
association: 'domain_contacts',
|
||||
attribute: 'contact_code_cache'
|
||||
}
|
||||
|
||||
|
@ -116,14 +109,6 @@ class Domain < ActiveRecord::Base
|
|||
|
||||
attr_accessor :owner_contact_typeahead, :update_me
|
||||
|
||||
def tech_domain_contacts
|
||||
domain_contacts.select { |x| x.contact_type == DomainContact::TECH }
|
||||
end
|
||||
|
||||
def admin_domain_contacts
|
||||
domain_contacts.select { |x| x.contact_type == DomainContact::ADMIN }
|
||||
end
|
||||
|
||||
def subordinate_nameservers
|
||||
nameservers.select { |x| x.hostname.end_with?(name) }
|
||||
end
|
||||
|
@ -227,6 +212,8 @@ class Domain < ActiveRecord::Base
|
|||
elsif domain_statuses.length > 1 || !valid?
|
||||
domain_statuses.find_by(value: DomainStatus::OK).try(:destroy)
|
||||
end
|
||||
|
||||
# contacts.includes(:address).each(&:manage_statuses)
|
||||
end
|
||||
|
||||
def children_log
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
class DomainContact < ActiveRecord::Base
|
||||
# STI: tech_domain_contact
|
||||
# STI: admin_domain_contact
|
||||
include Versions # version/domain_contact_version.rb
|
||||
include EppErrors
|
||||
belongs_to :contact
|
||||
belongs_to :domain
|
||||
|
||||
# TODO: remove old
|
||||
# after_create :domain_snapshot
|
||||
# after_destroy :domain_snapshot
|
||||
# after_save :domain_snapshot
|
||||
|
||||
attr_accessor :value_typeahead
|
||||
|
||||
def epp_code_map
|
||||
|
@ -19,32 +16,19 @@ class DomainContact < ActiveRecord::Base
|
|||
}
|
||||
end
|
||||
|
||||
TECH = 'tech'
|
||||
ADMIN = 'admin'
|
||||
TYPES = [TECH, ADMIN]
|
||||
|
||||
validates :contact, presence: true
|
||||
|
||||
scope :admin, -> { where(contact_type: ADMIN) }
|
||||
scope :tech, -> { where(contact_type: TECH) }
|
||||
|
||||
def admin?
|
||||
contact_type == ADMIN
|
||||
before_save :update_contact_code_cache
|
||||
def update_contact_code_cache
|
||||
self.contact_code_cache = contact.code
|
||||
end
|
||||
|
||||
def tech?
|
||||
contact_type == TECH
|
||||
after_destroy :update_contact
|
||||
def update_contact
|
||||
Contact.find(contact_id).save
|
||||
end
|
||||
|
||||
def value_typeahead
|
||||
@value_typeahead || contact.try(:name) || nil
|
||||
end
|
||||
|
||||
# TODO: remove old
|
||||
# def domain_snapshot
|
||||
# return true if domain.nil?
|
||||
# return true if domain.versions.count == 0 # avoid snapshot on creation
|
||||
# domain.create_version
|
||||
# true
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -17,15 +17,12 @@ class Epp::Contact < Contact
|
|||
at[:email] = f.css('email').text if f.css('email').present?
|
||||
at[:fax] = f.css('fax').text if f.css('fax').present?
|
||||
at[:phone] = f.css('voice').text if f.css('voice').present?
|
||||
at[:city] = f.css('postalInfo addr city').text if f.css('postalInfo addr city').present?
|
||||
at[:zip] = f.css('postalInfo addr pc').text if f.css('postalInfo addr pc').present?
|
||||
at[:street] = f.css('postalInfo addr street').text if f.css('postalInfo addr street').present?
|
||||
at[:state] = f.css('postalInfo addr sp').text if f.css('postalInfo addr sp').present?
|
||||
at[:country_code] = f.css('postalInfo addr cc').text if f.css('postalInfo addr cc').present?
|
||||
at[:auth_info] = f.css('authInfo pw').text if f.css('authInfo pw').present?
|
||||
at[:address_attributes] = {}.with_indifferent_access
|
||||
sat = at[:address_attributes]
|
||||
sat[:city] = f.css('postalInfo addr city').text if f.css('postalInfo addr city').present?
|
||||
sat[:zip] = f.css('postalInfo addr pc').text if f.css('postalInfo addr pc').present?
|
||||
sat[:street] = f.css('postalInfo addr street').text if f.css('postalInfo addr street').present?
|
||||
sat[:state] = f.css('postalInfo addr sp').text if f.css('postalInfo addr sp').present?
|
||||
sat[:country_code] = f.css('postalInfo addr cc').text if f.css('postalInfo addr cc').present?
|
||||
at.delete(:address_attributes) if at[:address_attributes].blank?
|
||||
|
||||
legal_frame = f.css('legalDocument').first
|
||||
if legal_frame.present?
|
||||
|
|
|
@ -2,6 +2,15 @@
|
|||
class Epp::Domain < Domain
|
||||
include EppErrors
|
||||
|
||||
class << self
|
||||
def new_from_epp(frame, current_user)
|
||||
domain = Epp::Domain.new
|
||||
domain.attributes = domain.attrs_from(frame, current_user)
|
||||
domain.attach_default_contacts
|
||||
domain
|
||||
end
|
||||
end
|
||||
|
||||
def epp_code_map # rubocop:disable Metrics/MethodLength
|
||||
{
|
||||
'2002' => [
|
||||
|
@ -58,30 +67,12 @@ class Epp::Domain < Domain
|
|||
}
|
||||
end
|
||||
|
||||
def self.new_from_epp(frame, current_user)
|
||||
domain = Epp::Domain.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
|
||||
# for bullet, owner contact validates registrar and triggers bullet
|
||||
owner_contact_included = Contact.where(id: owner_contact.id).includes(:registrar).first
|
||||
|
||||
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
|
||||
tech_contacts << owner_contact_included if tech_contacts.blank?
|
||||
admin_contacts << owner_contact_included if admin_contacts.blank? && owner_contact.priv?
|
||||
end
|
||||
|
||||
# rubocop: disable Metrics/PerceivedComplexity
|
||||
|
@ -111,7 +102,8 @@ class Epp::Domain < Domain
|
|||
at[:period_unit] = Epp::Domain.parse_period_unit_from_frame(frame) || 'y'
|
||||
|
||||
at[:nameservers_attributes] = nameservers_attrs(frame, action)
|
||||
at[:domain_contacts_attributes] = domain_contacts_attrs(frame, action)
|
||||
at[:admin_domain_contacts_attributes] = admin_domain_contacts_attrs(frame, action)
|
||||
at[:tech_domain_contacts_attributes] = tech_domain_contacts_attrs(frame, action)
|
||||
at[:domain_statuses_attributes] = domain_statuses_attrs(frame, action)
|
||||
|
||||
if new_record?
|
||||
|
@ -167,39 +159,53 @@ class Epp::Domain < Domain
|
|||
res
|
||||
end
|
||||
|
||||
def domain_contacts_attrs(frame, action)
|
||||
contact_list = domain_contact_list_from(frame, action)
|
||||
def admin_domain_contacts_attrs(frame, action)
|
||||
admin_attrs = domain_contact_attrs_from(frame, action, 'admin')
|
||||
|
||||
if action == 'rem'
|
||||
to_destroy = []
|
||||
contact_list.each do |dc|
|
||||
domain_contact_id = domain_contacts.find_by(
|
||||
contact_id: dc[:contact_id],
|
||||
contact_type: dc[:contact_type]
|
||||
).try(:id)
|
||||
|
||||
unless domain_contact_id
|
||||
add_epp_error('2303', 'contact', dc[:contact_code_cache], [:domain_contacts, :not_found])
|
||||
next
|
||||
end
|
||||
|
||||
to_destroy << {
|
||||
id: domain_contact_id,
|
||||
_destroy: 1
|
||||
}
|
||||
end
|
||||
|
||||
return to_destroy
|
||||
case action
|
||||
when 'rem'
|
||||
return destroy_attrs(admin_attrs, admin_domain_contacts)
|
||||
else
|
||||
return contact_list
|
||||
return admin_attrs
|
||||
end
|
||||
end
|
||||
|
||||
def domain_contact_list_from(frame, action)
|
||||
res = []
|
||||
frame.css('contact').each do |x|
|
||||
c = Contact.find_by(code: x.text)
|
||||
def tech_domain_contacts_attrs(frame, action)
|
||||
tech_attrs = domain_contact_attrs_from(frame, action, 'tech')
|
||||
|
||||
case action
|
||||
when 'rem'
|
||||
return destroy_attrs(tech_attrs, tech_domain_contacts)
|
||||
else
|
||||
return tech_attrs
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_attrs(attrs, dcontacts)
|
||||
destroy_attrs = []
|
||||
attrs.each do |at|
|
||||
domain_contact_id = dcontacts.find_by(contact_id: at[:contact_id]).try(:id)
|
||||
|
||||
unless domain_contact_id
|
||||
add_epp_error('2303', 'contact', at[:contact_code_cache], [:domain_contacts, :not_found])
|
||||
next
|
||||
end
|
||||
|
||||
destroy_attrs << {
|
||||
id: domain_contact_id,
|
||||
_destroy: 1
|
||||
}
|
||||
end
|
||||
|
||||
destroy_attrs
|
||||
end
|
||||
|
||||
def domain_contact_attrs_from(frame, action, type)
|
||||
attrs = []
|
||||
frame.css('contact').each do |x|
|
||||
next if x['type'] != type
|
||||
|
||||
c = Contact.find_by(code: x.text)
|
||||
unless c
|
||||
add_epp_error('2303', 'contact', x.text, [:domain_contacts, :not_found])
|
||||
next
|
||||
|
@ -212,14 +218,31 @@ class Epp::Domain < Domain
|
|||
end
|
||||
end
|
||||
|
||||
res << {
|
||||
contact_id: Contact.find_by(code: x.text).try(:id),
|
||||
contact_type: x['type'],
|
||||
contact_code_cache: x.text
|
||||
attrs << {
|
||||
contact_id: c.id,
|
||||
contact_code_cache: c.code
|
||||
}
|
||||
end
|
||||
|
||||
res
|
||||
attrs
|
||||
end
|
||||
|
||||
def domain_status_list_from(frame)
|
||||
status_list = []
|
||||
|
||||
frame.css('status').each do |x|
|
||||
unless DomainStatus::CLIENT_STATUSES.include?(x['s'])
|
||||
add_epp_error('2303', 'status', x['s'], [:domain_statuses, :not_found])
|
||||
next
|
||||
end
|
||||
|
||||
status_list << {
|
||||
value: x['s'],
|
||||
description: x.text
|
||||
}
|
||||
end
|
||||
|
||||
status_list
|
||||
end
|
||||
|
||||
# rubocop: disable Metrics/PerceivedComplexity
|
||||
|
@ -358,7 +381,8 @@ class Epp::Domain < Domain
|
|||
|
||||
at_add = attrs_from(frame.css('add'), current_user)
|
||||
at[:nameservers_attributes] += at_add[:nameservers_attributes]
|
||||
at[:domain_contacts_attributes] += at_add[:domain_contacts_attributes]
|
||||
at[:admin_domain_contacts_attributes] += at_add[:admin_domain_contacts_attributes]
|
||||
at[:tech_domain_contacts_attributes] += at_add[:tech_domain_contacts_attributes]
|
||||
at[:dnskeys_attributes] += at_add[:dnskeys_attributes]
|
||||
at[:domain_statuses_attributes] += at_add[:domain_statuses_attributes]
|
||||
|
||||
|
@ -414,7 +438,7 @@ class Epp::Domain < Domain
|
|||
|
||||
def copy_and_transfer_contact(contact_id, registrar_id)
|
||||
c = Contact.find(contact_id) # n+1 workaround
|
||||
oc = c.deep_clone include: [:statuses, :address]
|
||||
oc = c.deep_clone include: [:statuses]
|
||||
oc.code = nil
|
||||
oc.registrar_id = registrar_id
|
||||
oc.save!
|
||||
|
|
2
app/models/tech_domain_contact.rb
Normal file
2
app/models/tech_domain_contact.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class TechDomainContact < DomainContact
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
class ContactDisclosureVersion < PaperTrail::Version
|
||||
include VersionSession
|
||||
self.table_name = :log_contact_disclosures
|
||||
self.sequence_name = :log_contact_disclosures_id_seq
|
||||
end
|
|
@ -5,39 +5,6 @@ class DomainVersion < PaperTrail::Version
|
|||
self.sequence_name = :log_domains_id_seq
|
||||
|
||||
include UserEvents
|
||||
# TODO: remove old
|
||||
# include DomainVersionObserver if Setting.whois_enabled # unless Setting.whois_enabled
|
||||
|
||||
scope :deleted, -> { where(event: 'destroy') }
|
||||
|
||||
# TODO: remove old
|
||||
# def load_snapshot
|
||||
# snapshot ? YAML.load(snapshot) : {}
|
||||
# end
|
||||
|
||||
# TODO: remove old
|
||||
# def previous?
|
||||
# return true if previous
|
||||
# false
|
||||
# end
|
||||
|
||||
# TODO: remove old
|
||||
# def name
|
||||
# name = reify.try(:name)
|
||||
# name = load_snapshot[:domain].try(:[], :name) unless name
|
||||
# name
|
||||
# end
|
||||
|
||||
# TODO: remove old
|
||||
# def changed_elements
|
||||
# return [] unless previous?
|
||||
# @changes = []
|
||||
# @previous_snap = previous.load_snapshot
|
||||
# @snap = load_snapshot
|
||||
# [:owner_contact, :tech_contacts, :admin_contacts, :nameservers, :domain].each do |key|
|
||||
# @changes << key unless @snap[key] == @previous_snap[key]
|
||||
# end
|
||||
|
||||
# @changes
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -2,23 +2,22 @@
|
|||
.panel-heading
|
||||
%h3.panel-title= t(:address)
|
||||
.panel-body
|
||||
- unless @contact.address.nil?
|
||||
%dl.dl-horizontal
|
||||
- if @contact.org_name.present?
|
||||
%dt= t(:org_name)
|
||||
%dd= @contact.org_name
|
||||
%dl.dl-horizontal
|
||||
- if @contact.org_name.present?
|
||||
%dt= t(:org_name)
|
||||
%dd= @contact.org_name
|
||||
|
||||
%dt= t(:street)
|
||||
%dd= @contact.street
|
||||
%dt= t(:street)
|
||||
%dd= @contact.street
|
||||
|
||||
%dt= t(:city)
|
||||
%dd= @contact.city
|
||||
%dt= t(:city)
|
||||
%dd= @contact.city
|
||||
|
||||
%dt= t(:zip)
|
||||
%dd= @contact.zip
|
||||
%dt= t(:zip)
|
||||
%dd= @contact.zip
|
||||
|
||||
%dt= t(:state)
|
||||
%dd= @contact.state
|
||||
%dt= t(:state)
|
||||
%dd= @contact.state
|
||||
|
||||
%dt= t(:country)
|
||||
%dd= @contact.country
|
||||
%dt= t(:country)
|
||||
%dd= @contact.country
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
- panel_class = @domain.errors.messages[:admin_contacts] ? 'panel-danger' : 'panel-default'
|
||||
.panel{class: panel_class}
|
||||
.panel-heading.clearfix
|
||||
= t('admin_contacts')
|
||||
= t(:admin_contacts)
|
||||
.table-responsive
|
||||
%table.table.table-hover.table-bordered.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th{class: 'col-xs-4'}= t('name')
|
||||
%th{class: 'col-xs-4'}= t('code')
|
||||
%th{class: 'col-xs-4'}= t('email')
|
||||
%th{class: 'col-xs-4'}= t(:name)
|
||||
%th{class: 'col-xs-4'}= t(:code)
|
||||
%th{class: 'col-xs-4'}= t(:email)
|
||||
%tbody
|
||||
- @domain.domain_contacts.admin.each do |x|
|
||||
- @domain.admin_contacts.each do |ac|
|
||||
%tr
|
||||
%td= link_to(x.contact, admin_contact_path(x.contact))
|
||||
%td= x.contact.code
|
||||
%td= x.contact.email
|
||||
%td= link_to(ac, admin_contact_path(ac))
|
||||
%td= ac.code
|
||||
%td= ac.email
|
||||
- if @domain.errors.messages[:admin_contacts]
|
||||
%tfoot
|
||||
- @domain.errors.messages[:admin_contacts].each do |x|
|
||||
|
|
|
@ -10,11 +10,11 @@
|
|||
%th{class: 'col-xs-4'}= t('code')
|
||||
%th{class: 'col-xs-4'}= t('email')
|
||||
%tbody
|
||||
- @domain.domain_contacts.tech.each do |x|
|
||||
- @domain.tech_contacts.each do |tc|
|
||||
%tr
|
||||
%td= link_to(x.contact, admin_contact_path(x.contact))
|
||||
%td= x.contact.code
|
||||
%td= x.contact.email
|
||||
%td= link_to(tc, admin_contact_path(tc))
|
||||
%td= tc.code
|
||||
%td= tc.email
|
||||
- if @domain.errors.messages[:tech_contacts]
|
||||
%tfoot
|
||||
- @domain.errors.messages[:tech_contacts].each do |x|
|
||||
|
|
|
@ -7,19 +7,19 @@ xml.epp_head do
|
|||
xml.resData do
|
||||
xml.tag!('domain:infData', 'xmlns:domain' => 'urn:ietf:params:xml:ns:domain-1.0') do
|
||||
xml.tag!('domain:name', @domain.name)
|
||||
@domain.domain_statuses.each do |x|
|
||||
xml.tag!('domain:status', x.description, 's' => x.value) unless x.description.blank?
|
||||
xml.tag!('domain:status', 's' => x.value) if x.description.blank?
|
||||
@domain.domain_statuses.each do |ds|
|
||||
xml.tag!('domain:status', ds.description, 's' => ds.value) unless ds.description.blank?
|
||||
xml.tag!('domain:status', 's' => ds.value) if ds.description.blank?
|
||||
end
|
||||
|
||||
xml.tag!('domain:registrant', @domain.owner_contact_code)
|
||||
|
||||
@domain.tech_contacts.each do |x|
|
||||
xml.tag!('domain:contact', x.code, 'type' => 'tech')
|
||||
@domain.tech_contacts.each do |tc|
|
||||
xml.tag!('domain:contact', tc.code, 'type' => 'tech')
|
||||
end
|
||||
|
||||
@domain.admin_contacts.each do |x|
|
||||
xml.tag!('domain:contact', x.code, 'type' => 'admin')
|
||||
@domain.admin_contacts.each do |ac|
|
||||
xml.tag!('domain:contact', ac.code, 'type' => 'admin')
|
||||
end
|
||||
|
||||
if @nameservers && @nameservers.any?
|
||||
|
@ -61,17 +61,17 @@ xml.epp_head do
|
|||
|
||||
xml.extension do
|
||||
xml.tag!('secDNS:infData', 'xmlns:secDNS' => 'urn:ietf:params:xml:ns:secDNS-1.1') do
|
||||
@domain.dnskeys.each do |x|
|
||||
@domain.dnskeys.each do |key|
|
||||
xml.tag!('secDNS:dsData') do
|
||||
xml.tag!('secDNS:keyTag', x.ds_key_tag)
|
||||
xml.tag!('secDNS:alg', x.ds_alg)
|
||||
xml.tag!('secDNS:digestType', x.ds_digest_type)
|
||||
xml.tag!('secDNS:digest', x.ds_digest)
|
||||
xml.tag!('secDNS:keyTag', key.ds_key_tag)
|
||||
xml.tag!('secDNS:alg', key.ds_alg)
|
||||
xml.tag!('secDNS:digestType', key.ds_digest_type)
|
||||
xml.tag!('secDNS:digest', key.ds_digest)
|
||||
xml.tag!('secDNS:keyData') do
|
||||
xml.tag!('secDNS:flags', x.flags)
|
||||
xml.tag!('secDNS:protocol', x.protocol)
|
||||
xml.tag!('secDNS:alg', x.alg)
|
||||
xml.tag!('secDNS:pubKey', x.public_key)
|
||||
xml.tag!('secDNS:flags', key.flags)
|
||||
xml.tag!('secDNS:protocol', key.protocol)
|
||||
xml.tag!('secDNS:alg', key.alg)
|
||||
xml.tag!('secDNS:pubKey', key.public_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue