Merge branch 'master' of github.com:domify/registry

Conflicts:
	db/schema.rb
This commit is contained in:
Martin Lensment 2015-04-16 13:22:18 +03:00
commit ab4318c801
21 changed files with 135 additions and 819 deletions

View file

@ -74,7 +74,7 @@ class Contact < ActiveRecord::Base
def find_orphans
Contact.where('
NOT EXISTS(
select 1 from domains d where d.owner_contact_id = contacts.id
select 1 from domains d where d.registrant_id = contacts.id
) AND NOT EXISTS(
select 1 from domain_contacts dc where dc.contact_id = contacts.id
)
@ -138,7 +138,7 @@ class Contact < ActiveRecord::Base
# Find a way to use self.domains with contact
def domains_owned
Domain.where(owner_contact_id: id)
Domain.where(registrant_id: id)
end
def relations_with_domain?

View file

@ -7,7 +7,7 @@ class Domain < ActiveRecord::Base
paginates_per 10 # just for showoff
belongs_to :registrar
belongs_to :owner_contact, class_name: 'Contact'
belongs_to :registrant, class_name: 'Contact'
has_many :domain_contacts, dependent: :destroy
has_many :admin_domain_contacts
@ -39,10 +39,10 @@ class Domain < ActiveRecord::Base
has_many :legal_documents, as: :documentable
accepts_nested_attributes_for :legal_documents, reject_if: proc { |attrs| attrs[:body].blank? }
delegate :code, to: :owner_contact, prefix: true
delegate :email, to: :owner_contact, prefix: true
delegate :ident, to: :owner_contact, prefix: true
delegate :phone, to: :owner_contact, prefix: true
delegate :code, to: :registrant, prefix: true
delegate :email, to: :registrant, prefix: true
delegate :ident, to: :registrant, prefix: true
delegate :phone, to: :registrant, prefix: true
delegate :name, to: :registrar, prefix: true
before_create :generate_auth_info
@ -57,7 +57,7 @@ class Domain < ActiveRecord::Base
validates :name_dirty, domain_name: true, uniqueness: true
validates :period, numericality: { only_integer: true }
validates :owner_contact, :registrar, presence: true
validates :registrant, :registrar, presence: true
validate :validate_period
@ -103,7 +103,7 @@ class Domain < ActiveRecord::Base
validate :validate_nameserver_ips
attr_accessor :owner_contact_typeahead, :update_me
attr_accessor :registrant_typeahead, :update_me
def subordinate_nameservers
nameservers.select { |x| x.hostname.end_with?(name) }
@ -138,8 +138,8 @@ class Domain < ActiveRecord::Base
self[:name_dirty] = value
end
def owner_contact_typeahead
@owner_contact_typeahead || owner_contact.try(:name) || nil
def registrant_typeahead
@registrant_typeahead || registrant.try(:name) || nil
end
def pending_transfer
@ -234,22 +234,21 @@ class Domain < ActiveRecord::Base
log[:admin_contacts] = admin_contacts.map(&:attributes)
log[:tech_contacts] = tech_contacts.map(&:attributes)
log[:nameservers] = nameservers.map(&:attributes)
log[:owner_contact] = [owner_contact.try(:attributes)]
log[:registrant] = [registrant.try(:attributes)]
log
end
# rubocop:disable Metrics/MethodLength
def update_whois_body
self.whois_body = <<-EOS
This Whois Server contains information on
Estonian Top Level Domain ee TLD
Estonia .ee Top Level Domain WHOIS server
domain: #{name}
registrar: #{registrar}
status:
domain: #{name}
registrant: #{registrant.name}
status: #{domain_statuses.map(&:value).join(', ')}
registered: #{registered_at and registered_at.to_s(:db)}
changed: #{updated_at and updated_at.to_s(:db)}
expire:
changed: #{updated_at and updated_at.to_s(:db)}
expire: #{valid_to and valid_to.to_s(:db)}
outzone:
delete:
@ -263,6 +262,9 @@ class Domain < ActiveRecord::Base
address: #{registrar.address}
created: #{registrar.created_at.to_s(:db)}
changed: #{registrar.updated_at.to_s(:db)}
Estonia .ee Top Level Domain WHOIS server
More information at http://internet.ee
EOS
end
# rubocop:enable Metrics/MethodLength

View file

@ -24,7 +24,7 @@ class Epp::Domain < Domain
[:base, :domain_status_prohibits_operation]
],
'2306' => [ # Parameter policy error
[:owner_contact, :blank],
[:registrant, :blank],
[:base, :ds_data_with_key_not_allowed],
[:base, :ds_data_not_allowed],
[:base, :key_data_not_allowed],
@ -68,9 +68,9 @@ class Epp::Domain < Domain
end
def attach_default_contacts
return if owner_contact.blank?
tech_contacts << owner_contact if tech_contacts.blank?
admin_contacts << owner_contact if admin_contacts.blank? && owner_contact.priv?
return if registrant.blank?
tech_contacts << registrant if tech_contacts.blank?
admin_contacts << registrant if admin_contacts.blank? && registrant.priv?
end
# rubocop: disable Metrics/PerceivedComplexity
@ -84,9 +84,9 @@ class Epp::Domain < Domain
oc = Contact.find_by(code: code).try(:id)
if oc
at[:owner_contact_id] = oc
at[:registrant_id] = oc
else
add_epp_error('2303', 'registrant', code, [:owner_contact, :not_found])
add_epp_error('2303', 'registrant', code, [:registrant, :not_found])
end
end
@ -430,7 +430,7 @@ class Epp::Domain < Domain
# TODO: Eager load problems here. Investigate how it's possible not to query contact again
# Check if versioning works with update_column
def transfer_contacts(registrar_id)
transfer_owner_contact(registrar_id)
transfer_registrant(registrar_id)
transfer_domain_contacts(registrar_id)
end
@ -452,15 +452,15 @@ class Epp::Domain < Domain
oc
end
def transfer_owner_contact(registrar_id)
return if owner_contact.registrar_id == registrar_id
def transfer_registrant(registrar_id)
return if registrant.registrar_id == registrar_id
is_other_domains_contact = DomainContact.where('contact_id = ? AND domain_id != ?', owner_contact_id, id).count > 0
if owner_contact.domains_owned.count > 1 || is_other_domains_contact
oc = copy_and_transfer_contact(owner_contact_id, registrar_id)
self.owner_contact_id = oc.id
is_other_domains_contact = DomainContact.where('contact_id = ? AND domain_id != ?', registrant_id, id).count > 0
if registrant.domains_owned.count > 1 || is_other_domains_contact
oc = copy_and_transfer_contact(registrant_id, registrar_id)
self.registrant_id = oc.id
else
transfer_contact(owner_contact_id, registrar_id)
transfer_contact(registrant_id, registrar_id)
end
end
@ -471,11 +471,11 @@ class Epp::Domain < Domain
is_other_domains_contact = DomainContact.where('contact_id = ? AND domain_id != ?', c.id, id).count > 0
# if contact used to be owner contact but was copied, then contact must be transferred
# (owner_contact_id_was != c.id)
# (registrant_id_was != c.id)
if c.domains.count > 1 || is_other_domains_contact
# copy contact
if owner_contact_id_was == c.id # owner contact was copied previously, do not copy it again
oc = OpenStruct.new(id: owner_contact_id)
if registrant_id_was == c.id # owner contact was copied previously, do not copy it again
oc = OpenStruct.new(id: registrant_id)
else
oc = copy_and_transfer_contact(c.id, registrar_id)
end