mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 18:59:38 +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
|
@ -9,8 +9,8 @@ group :red_green_refactor, halt_on_fail: true do
|
|||
# watch(%r{^(config|lib)/.*})
|
||||
# end
|
||||
|
||||
guard :rspec, cmd: 'spring rspec --fail-fast', notification: false do
|
||||
# guard :rspec, cmd: 'spring rspec', notification: false do
|
||||
# guard :rspec, cmd: 'spring rspec --fail-fast', notification: false do
|
||||
guard :rspec, cmd: 'spring rspec', notification: false do
|
||||
watch(%r{^spec/.+_spec\.rb$})
|
||||
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
||||
watch('spec/spec_helper.rb') { "spec" }
|
||||
|
|
|
@ -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
|
||||
if @errors.blank?
|
||||
@errors << {
|
||||
code: '1',
|
||||
msg: 'handle_errors was executed when there were actually no errors'
|
||||
} if @errors.blank?
|
||||
}
|
||||
# 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)
|
||||
case action
|
||||
when 'rem'
|
||||
return destroy_attrs(admin_attrs, admin_domain_contacts)
|
||||
else
|
||||
return admin_attrs
|
||||
end
|
||||
end
|
||||
|
||||
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', dc[:contact_code_cache], [:domain_contacts, :not_found])
|
||||
add_epp_error('2303', 'contact', at[:contact_code_cache], [:domain_contacts, :not_found])
|
||||
next
|
||||
end
|
||||
|
||||
to_destroy << {
|
||||
destroy_attrs << {
|
||||
id: domain_contact_id,
|
||||
_destroy: 1
|
||||
}
|
||||
end
|
||||
|
||||
return to_destroy
|
||||
else
|
||||
return contact_list
|
||||
end
|
||||
destroy_attrs
|
||||
end
|
||||
|
||||
def domain_contact_list_from(frame, action)
|
||||
res = []
|
||||
def domain_contact_attrs_from(frame, action, type)
|
||||
attrs = []
|
||||
frame.css('contact').each do |x|
|
||||
c = Contact.find_by(code: x.text)
|
||||
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,7 +2,6 @@
|
|||
.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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -44,5 +44,6 @@ Rails.application.configure do
|
|||
Bullet.console = true
|
||||
Bullet.rails_logger = true
|
||||
Bullet.add_footer = true
|
||||
Bullet.unused_eager_loading_enable = false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -49,6 +49,6 @@ Rails.application.configure do
|
|||
Bullet.enable = true
|
||||
Bullet.bullet_logger = true
|
||||
Bullet.raise = true # raise an error if n+1 query occurs
|
||||
# Bullet.unused_eager_loading_enable = false
|
||||
Bullet.unused_eager_loading_enable = false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,14 +6,6 @@ rescue ActiveRecord::NoDatabaseError => e
|
|||
end
|
||||
|
||||
if con.present? && con.table_exists?('settings')
|
||||
Setting.disclosure_name = true if Setting.disclosure_name.nil?
|
||||
Setting.disclosure_name = true if Setting.disclosure_name.nil?
|
||||
Setting.disclosure_org_name = true if Setting.disclosure_org_name.nil?
|
||||
Setting.disclosure_email = true if Setting.disclosure_email.nil?
|
||||
Setting.disclosure_phone = false if Setting.disclosure_phone.nil?
|
||||
Setting.disclosure_fax = false if Setting.disclosure_fax.nil?
|
||||
Setting.disclosure_address = false if Setting.disclosure_address.nil?
|
||||
|
||||
Setting.save_default(:admin_contacts_min_count, 1)
|
||||
Setting.save_default(:admin_contacts_max_count, 10)
|
||||
Setting.save_default(:tech_contacts_min_count, 1)
|
||||
|
|
|
@ -69,6 +69,8 @@ en:
|
|||
invalid: 'Contacts are invalid'
|
||||
not_found: 'Contact was not found'
|
||||
admin_contact_can_be_only_private_person: 'Admin contact can be private person only'
|
||||
admin_domain_contacts:
|
||||
out_of_range: 'Admin contacts count must be between %{min}-%{max}'
|
||||
admin_contacts:
|
||||
out_of_range: 'Admin contacts count must be between %{min}-%{max}'
|
||||
less_than_or_equal_to: 'Admin contacts count must be less than or equal to %{count}'
|
||||
|
|
5
db/migrate/20150318084300_add_domain_contact_type.rb
Normal file
5
db/migrate/20150318084300_add_domain_contact_type.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddDomainContactType < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :domain_contacts, :type, :string
|
||||
end
|
||||
end
|
17
db/migrate/20150318085110_update_domain_contact_data.rb
Normal file
17
db/migrate/20150318085110_update_domain_contact_data.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class UpdateDomainContactData < ActiveRecord::Migration
|
||||
def change
|
||||
DomainContact.all.each do |dc|
|
||||
case dc.contact_type
|
||||
when 'admin'
|
||||
dc.type = 'AdminDomainContact'
|
||||
when 'tech'
|
||||
dc.type = 'TechDomainContact'
|
||||
end
|
||||
if dc.changes.present?
|
||||
puts "Changed: #{dc.id}: #{dc.changes.inspect} #{dc.save}"
|
||||
else
|
||||
puts "No changes: #{dc.id}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
9
db/migrate/20150318114921_add_address_attributes.rb
Normal file
9
db/migrate/20150318114921_add_address_attributes.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
class AddAddressAttributes < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :contacts, :city, :string
|
||||
add_column :contacts, :street, :text
|
||||
add_column :contacts, :zip, :string
|
||||
add_column :contacts, :country_code, :string
|
||||
add_column :contacts, :state, :string
|
||||
end
|
||||
end
|
16
db/migrate/20150319125655_update_contact_data.rb
Normal file
16
db/migrate/20150319125655_update_contact_data.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
class UpdateContactData < ActiveRecord::Migration
|
||||
def change
|
||||
Address.all.each do |a|
|
||||
c = a.contact
|
||||
c.city = a.city
|
||||
c.street = ""
|
||||
c.street << a.street if a.street.present?
|
||||
c.street << "\n#{a.street2}" if a.street2.present?
|
||||
c.street << "\n#{a.street3}" if a.street3.present?
|
||||
c.zip = a.zip
|
||||
c.country_code = a.country_code
|
||||
c.state = a.state
|
||||
puts "#{c.id} changes: #{c.changes.inspect}; #{c.save(false)}"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class DepricateContactDisclouserTable < ActiveRecord::Migration
|
||||
def change
|
||||
drop_table :contact_disclosures
|
||||
drop_table :log_contact_disclosures
|
||||
end
|
||||
end
|
37
db/schema.rb
37
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20150320132023) do
|
||||
ActiveRecord::Schema.define(version: 20150330083700) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -63,20 +63,6 @@ ActiveRecord::Schema.define(version: 20150320132023) do
|
|||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "contact_disclosures", force: :cascade do |t|
|
||||
t.integer "contact_id"
|
||||
t.boolean "phone"
|
||||
t.boolean "fax"
|
||||
t.boolean "email"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.boolean "name"
|
||||
t.boolean "org_name"
|
||||
t.boolean "address"
|
||||
t.string "creator_str"
|
||||
t.string "updator_str"
|
||||
end
|
||||
|
||||
create_table "contact_statuses", force: :cascade do |t|
|
||||
t.string "value"
|
||||
t.string "description"
|
||||
|
@ -107,6 +93,11 @@ ActiveRecord::Schema.define(version: 20150320132023) do
|
|||
t.string "creator_str"
|
||||
t.string "updator_str"
|
||||
t.string "ident_country_code"
|
||||
t.string "city"
|
||||
t.text "street"
|
||||
t.string "zip"
|
||||
t.string "country_code"
|
||||
t.string "state"
|
||||
end
|
||||
|
||||
add_index "contacts", ["code"], name: "index_contacts_on_code", using: :btree
|
||||
|
@ -172,6 +163,7 @@ ActiveRecord::Schema.define(version: 20150320132023) do
|
|||
t.string "contact_code_cache"
|
||||
t.string "creator_str"
|
||||
t.string "updator_str"
|
||||
t.string "type"
|
||||
end
|
||||
|
||||
create_table "domain_statuses", force: :cascade do |t|
|
||||
|
@ -302,21 +294,6 @@ ActiveRecord::Schema.define(version: 20150320132023) do
|
|||
t.json "children"
|
||||
end
|
||||
|
||||
create_table "log_contact_disclosures", force: :cascade do |t|
|
||||
t.string "item_type", null: false
|
||||
t.integer "item_id", null: false
|
||||
t.string "event", null: false
|
||||
t.string "whodunnit"
|
||||
t.json "object"
|
||||
t.json "object_changes"
|
||||
t.datetime "created_at"
|
||||
t.string "session"
|
||||
t.json "children"
|
||||
end
|
||||
|
||||
add_index "log_contact_disclosures", ["item_type", "item_id"], name: "index_log_contact_disclosures_on_item_type_and_item_id", using: :btree
|
||||
add_index "log_contact_disclosures", ["whodunnit"], name: "index_log_contact_disclosures_on_whodunnit", using: :btree
|
||||
|
||||
create_table "log_contact_statuses", force: :cascade do |t|
|
||||
t.string "item_type", null: false
|
||||
t.integer "item_id", null: false
|
||||
|
|
|
@ -3,7 +3,6 @@ require 'rails_helper'
|
|||
describe 'EPP Contact', epp: true do
|
||||
before :all do
|
||||
create_settings
|
||||
create_disclosure_settings
|
||||
@registrar1 = Fabricate(:registrar1)
|
||||
@registrar2 = Fabricate(:registrar2)
|
||||
@epp_xml = EppXml::Contact.new(cl_trid: 'ABC-12345')
|
||||
|
@ -38,6 +37,7 @@ describe 'EPP Contact', epp: true do
|
|||
addr: {
|
||||
street: { value: '123 Example' },
|
||||
city: { value: 'Tallinn' },
|
||||
pc: { value: '123456' },
|
||||
cc: { value: 'EE' }
|
||||
}
|
||||
},
|
||||
|
@ -53,14 +53,18 @@ describe 'EPP Contact', epp: true do
|
|||
response[:results][0][:msg].should ==
|
||||
'Required parameter missing: create > create > postalInfo > name [name]'
|
||||
response[:results][1][:msg].should ==
|
||||
'Required parameter missing: create > create > postalInfo > addr > city [city]'
|
||||
'Required parameter missing: create > create > postalInfo > addr > street [street]'
|
||||
response[:results][2][:msg].should ==
|
||||
'Required parameter missing: create > create > postalInfo > addr > cc [cc]'
|
||||
'Required parameter missing: create > create > postalInfo > addr > city [city]'
|
||||
response[:results][3][:msg].should ==
|
||||
'Required parameter missing: create > create > voice [voice]'
|
||||
'Required parameter missing: create > create > postalInfo > addr > pc [pc]'
|
||||
response[:results][4][:msg].should ==
|
||||
'Required parameter missing: create > create > email [email]'
|
||||
'Required parameter missing: create > create > postalInfo > addr > cc [cc]'
|
||||
response[:results][5][:msg].should ==
|
||||
'Required parameter missing: create > create > voice [voice]'
|
||||
response[:results][6][:msg].should ==
|
||||
'Required parameter missing: create > create > email [email]'
|
||||
response[:results][7][:msg].should ==
|
||||
'Required parameter missing: extension > extdata > ident [ident]'
|
||||
|
||||
response[:results][0][:result_code].should == '2003'
|
||||
|
@ -69,8 +73,10 @@ describe 'EPP Contact', epp: true do
|
|||
response[:results][3][:result_code].should == '2003'
|
||||
response[:results][4][:result_code].should == '2003'
|
||||
response[:results][5][:result_code].should == '2003'
|
||||
response[:results][6][:result_code].should == '2003'
|
||||
response[:results][7][:result_code].should == '2003'
|
||||
|
||||
response[:results].count.should == 6
|
||||
response[:results].count.should == 8
|
||||
end
|
||||
|
||||
it 'successfully creates a contact' do
|
||||
|
@ -84,7 +90,7 @@ describe 'EPP Contact', epp: true do
|
|||
@contact.registrar.should == @registrar1
|
||||
@registrar1.api_users.should include(@contact.creator)
|
||||
@contact.ident.should == '37605030299'
|
||||
@contact.address.street.should == '123 Example'
|
||||
@contact.street.should == '123 Example'
|
||||
@contact.legal_documents.count.should == 1
|
||||
|
||||
log = ApiLog::EppLog.last
|
||||
|
@ -397,7 +403,7 @@ describe 'EPP Contact', epp: true do
|
|||
|
||||
it 'fails if contact has associated domain' do
|
||||
@domain = Fabricate(:domain, registrar: @registrar1, owner_contact: @contact)
|
||||
@domain.owner_contact.address.present?.should == true
|
||||
@domain.owner_contact.present?.should == true
|
||||
|
||||
response = delete_request
|
||||
response[:msg].should == 'Object association prohibits operation [domains]'
|
||||
|
@ -480,8 +486,7 @@ describe 'EPP Contact', epp: true do
|
|||
|
||||
it 'return info about contact' do
|
||||
@registrar1_contact = Fabricate(
|
||||
:contact, code: 'info-4444', registrar: @registrar1,
|
||||
name: 'Johnny Awesome', address: Fabricate(:address))
|
||||
:contact, code: 'info-4444', registrar: @registrar1, name: 'Johnny Awesome')
|
||||
|
||||
response = info_request({ id: { value: @registrar1_contact.code } })
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
|
@ -492,9 +497,8 @@ describe 'EPP Contact', epp: true do
|
|||
end
|
||||
|
||||
it 'should return ident in extension' do
|
||||
@registrar1_contact = Fabricate(
|
||||
:contact, code: 'info-ident', registrar: @registrar1,
|
||||
name: 'Johnny Awesome', address: Fabricate(:address))
|
||||
@registrar1_contact = Fabricate(:contact, code: 'info-ident',
|
||||
registrar: @registrar1, name: 'Johnny Awesome')
|
||||
|
||||
response = info_request({ id: { value: @registrar1_contact.code } })
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
|
|
|
@ -30,12 +30,12 @@ describe 'EPP Domain', epp: true do
|
|||
]
|
||||
}), :xml)
|
||||
|
||||
response[:results][0][:result_code].should == '2303'
|
||||
response[:results][0][:msg].should == 'Contact was not found'
|
||||
response[:results][0][:result_code].should == '2303'
|
||||
response[:results][0][:value].should == 'sh1111'
|
||||
|
||||
response[:results][1][:result_code].should == '2303'
|
||||
response[:results][1][:msg].should == 'Contact was not found'
|
||||
response[:results][1][:result_code].should == '2303'
|
||||
response[:results][1][:value].should == 'sh2222'
|
||||
|
||||
response[:clTRID].should == 'ABC-12345'
|
||||
|
@ -95,8 +95,8 @@ describe 'EPP Domain', epp: true do
|
|||
response[:clTRID].should == 'ABC-12345'
|
||||
|
||||
d.registrar.name.should == 'registrar1'
|
||||
d.tech_contacts.count.should == 2
|
||||
d.admin_contacts.count.should == 1
|
||||
d.tech_contacts.count.should == 3
|
||||
d.admin_contacts.count.should == 2
|
||||
|
||||
d.nameservers.count.should == 2
|
||||
d.auth_info.should_not be_empty
|
||||
|
@ -674,7 +674,7 @@ describe 'EPP Domain', epp: true do
|
|||
})
|
||||
|
||||
response = epp_plain_request(xml, :xml)
|
||||
response[:msg].should == 'Admin contacts count must be between 1-10 [admin_contacts]'
|
||||
response[:msg].should == 'Admin contacts count must be between 1-10 [admin_domain_contacts]'
|
||||
response[:result_code].should == '2004'
|
||||
response[:clTRID].should == 'ABC-12345'
|
||||
|
||||
|
@ -1355,6 +1355,7 @@ describe 'EPP Domain', epp: true do
|
|||
]
|
||||
}), :xml)
|
||||
|
||||
response[:results][0][:msg].should == 'Command completed successfully'
|
||||
response[:results][0][:result_code].should == '1000'
|
||||
|
||||
d = Domain.last
|
||||
|
@ -1525,7 +1526,10 @@ describe 'EPP Domain', epp: true do
|
|||
]
|
||||
})
|
||||
|
||||
epp_plain_request(xml, :xml)
|
||||
response = epp_plain_request(xml, :xml)
|
||||
response[:results][0][:msg].should == 'Command completed successfully'
|
||||
response[:results][0][:result_code].should == '1000'
|
||||
|
||||
d = Domain.last
|
||||
d.dnskeys.count.should == 2
|
||||
|
||||
|
@ -1555,7 +1559,9 @@ describe 'EPP Domain', epp: true do
|
|||
]
|
||||
})
|
||||
|
||||
epp_plain_request(xml, :xml)
|
||||
response = epp_plain_request(xml, :xml)
|
||||
response[:results][0][:msg].should == 'Command completed successfully'
|
||||
response[:results][0][:result_code].should == '1000'
|
||||
|
||||
d.dnskeys.count.should == 1
|
||||
|
||||
|
@ -1872,6 +1878,7 @@ describe 'EPP Domain', epp: true do
|
|||
]
|
||||
}), :xml)
|
||||
|
||||
response[:msg].should == 'Command completed successfully'
|
||||
response[:result_code].should == '1000'
|
||||
|
||||
Domain.find_by(name: domain.name).should == nil
|
||||
|
|
6
spec/fabricators/admin_domain_contact_fabricator.rb
Normal file
6
spec/fabricators/admin_domain_contact_fabricator.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
Fabricator(:admin_domain_contact) do
|
||||
contact { Fabricate(:contact) }
|
||||
after_build do |x|
|
||||
x.contact_code_cache = x.contact.code
|
||||
end
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
Fabricator(:contact_disclosure) do
|
||||
email true
|
||||
phone true
|
||||
fax true
|
||||
address true
|
||||
name true
|
||||
org_name true
|
||||
end
|
|
@ -1,15 +1,17 @@
|
|||
Fabricator(:contact) do
|
||||
registrar { Fabricate(:registrar) }
|
||||
code { sequence(:code) { |i| "sh#{Faker::Number.number(8)}#{i}" } }
|
||||
auth_info 'password'
|
||||
name { sequence(:name) { |i| "#{Faker::Name.name}#{i}" } }
|
||||
phone '+372.12345678'
|
||||
email Faker::Internet.email
|
||||
street 'Short street 11'
|
||||
city 'Tallinn'
|
||||
zip '11111'
|
||||
country_code 'EE'
|
||||
ident '37605030299'
|
||||
ident_type 'priv'
|
||||
ident_country_code 'EE'
|
||||
address
|
||||
registrar { Fabricate(:registrar) }
|
||||
disclosure { Fabricate(:contact_disclosure) }
|
||||
# rubocop: disable Style/SymbolProc
|
||||
after_validation { |c| c.disable_generate_auth_info! }
|
||||
# rubocop: enamble Style/SymbolProc
|
||||
|
|
|
@ -5,7 +5,7 @@ Fabricator(:domain) do
|
|||
period_unit 'y'
|
||||
owner_contact(fabricator: :contact)
|
||||
nameservers(count: 3)
|
||||
domain_contacts(count: 1) { Fabricate(:domain_contact, contact_type: 'admin') }
|
||||
admin_domain_contacts(count: 1) { Fabricate(:admin_domain_contact) }
|
||||
registrar
|
||||
auth_info '98oiewslkfkd'
|
||||
end
|
||||
|
|
6
spec/fabricators/tech_domain_contact_fabricator.rb
Normal file
6
spec/fabricators/tech_domain_contact_fabricator.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
Fabricator(:tech_domain_contact) do
|
||||
contact { Fabricate(:contact) }
|
||||
after_build do |x|
|
||||
x.contact_code_cache = x.contact.code
|
||||
end
|
||||
end
|
|
@ -2,12 +2,9 @@ require 'rails_helper'
|
|||
|
||||
describe Contact do
|
||||
before :all do
|
||||
create_disclosure_settings
|
||||
@api_user = Fabricate(:api_user)
|
||||
end
|
||||
|
||||
it { should have_one(:address) }
|
||||
|
||||
context 'about class' do
|
||||
it 'should have versioning enabled?' do
|
||||
Contact.paper_trail_enabled_for_model?.should == true
|
||||
|
@ -32,9 +29,12 @@ describe Contact do
|
|||
"Email Required parameter missing - email",
|
||||
"Email Email is invalid",
|
||||
"Ident Required parameter missing - ident",
|
||||
"Address is missing",
|
||||
"Registrar is missing",
|
||||
"Ident type is missing"
|
||||
"Ident type is missing",
|
||||
"City is missing",
|
||||
"Country code is missing",
|
||||
"Street is missing",
|
||||
"Zip is missing"
|
||||
])
|
||||
end
|
||||
|
||||
|
@ -101,7 +101,7 @@ describe Contact do
|
|||
|
||||
context 'with valid attributes' do
|
||||
before :all do
|
||||
@contact = Fabricate(:contact, disclosure: nil)
|
||||
@contact = Fabricate(:contact)
|
||||
end
|
||||
|
||||
it 'should be valid' do
|
||||
|
@ -169,11 +169,20 @@ describe Contact do
|
|||
|
||||
contact.statuses.map(&:value).should == %w(ok linked)
|
||||
|
||||
contact.domains.destroy_all
|
||||
contact.save
|
||||
contact.domains.first.destroy
|
||||
contact.reload
|
||||
contact.statuses.map(&:value).should == %w(ok)
|
||||
end
|
||||
|
||||
it 'should have linked status when domain is created' do
|
||||
# @admin_domain_contact = Fabricate(:admin_domain_contact)
|
||||
# @domain = Fabricate(:domain, admin_domain_contacts: [@admin_domain_contact])
|
||||
# puts @domain.contacts.size
|
||||
# contact = @domain.contacts.first
|
||||
|
||||
# contact.statuses.map(&:value).should == %w(ok linked)
|
||||
end
|
||||
|
||||
context 'as birthday' do
|
||||
before :all do
|
||||
@contact.ident_type = 'birthday'
|
||||
|
@ -199,25 +208,6 @@ describe Contact do
|
|||
end
|
||||
end
|
||||
|
||||
it 'should have empty disclosure' do
|
||||
@contact.disclosure.name.should == nil
|
||||
@contact.disclosure.org_name.should == nil
|
||||
@contact.disclosure.email.should == nil
|
||||
@contact.disclosure.phone.should == nil
|
||||
@contact.disclosure.fax.should == nil
|
||||
@contact.disclosure.address.should == nil
|
||||
end
|
||||
|
||||
it 'should have custom disclosure' do
|
||||
@contact = Fabricate(:contact, disclosure: Fabricate(:contact_disclosure))
|
||||
@contact.disclosure.name.should == true
|
||||
@contact.disclosure.org_name.should == true
|
||||
@contact.disclosure.email.should == true
|
||||
@contact.disclosure.phone.should == true
|
||||
@contact.disclosure.fax.should == true
|
||||
@contact.disclosure.address.should == true
|
||||
end
|
||||
|
||||
context 'with callbacks' do
|
||||
before :all do
|
||||
# Ensure callbacks are not taken out from other specs
|
||||
|
|
|
@ -22,7 +22,7 @@ describe Domain do
|
|||
it 'should not be valid' do
|
||||
@domain.valid?
|
||||
@domain.errors.full_messages.should match_array([
|
||||
"Admin contacts Admin contacts count must be between 1-10",
|
||||
"Admin domain contacts Admin contacts count must be between 1-10",
|
||||
"Nameservers Nameservers count must be between 2-11",
|
||||
"Period Period is not a number",
|
||||
"Registrant Registrant is missing",
|
||||
|
@ -56,6 +56,24 @@ describe Domain do
|
|||
@domain.errors.full_messages.should match_array([])
|
||||
end
|
||||
|
||||
it 'should validate uniqueness of tech contacts' do
|
||||
same_contact = Fabricate(:contact, code: 'same_contact')
|
||||
domain = Fabricate(:domain)
|
||||
domain.tech_contacts << same_contact
|
||||
domain.tech_contacts << same_contact
|
||||
domain.valid?
|
||||
domain.errors.full_messages.should match_array(["Tech domain contacts is invalid"])
|
||||
end
|
||||
|
||||
it 'should validate uniqueness of tech contacts' do
|
||||
same_contact = Fabricate(:contact, code: 'same_contact')
|
||||
domain = Fabricate(:domain)
|
||||
domain.admin_contacts << same_contact
|
||||
domain.admin_contacts << same_contact
|
||||
domain.valid?
|
||||
domain.errors.full_messages.should match_array(["Admin domain contacts is invalid"])
|
||||
end
|
||||
|
||||
it 'should have whois_body' do
|
||||
@domain.whois_body.present?.should == true
|
||||
end
|
||||
|
@ -102,20 +120,6 @@ describe Domain do
|
|||
@domain.creator.should_not == @api_user
|
||||
end
|
||||
end
|
||||
|
||||
it 'should not find api creator when created by user' do
|
||||
with_versioning do
|
||||
# @api_user = Fabricate(:api_user)
|
||||
# @api_user.id.should == 1
|
||||
# ::PaperTrail.whodunnit = '1-testuser'
|
||||
|
||||
# @domain = Fabricate(:domain)
|
||||
# @domain.creator_str.should == '1-testuser'
|
||||
|
||||
# @domain.api_creator.should == nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -19,15 +19,6 @@ module General
|
|||
|
||||
Setting.client_side_status_editing_enabled = true
|
||||
end
|
||||
|
||||
def create_disclosure_settings
|
||||
Setting.disclosure_name = true
|
||||
Setting.disclosure_org_name = true
|
||||
Setting.disclosure_email = true
|
||||
Setting.disclosure_phone = false
|
||||
Setting.disclosure_fax = false
|
||||
Setting.disclosure_address = false
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.configure do |c|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue