Reuse identical contacts

#746
This commit is contained in:
Artur Beljajev 2018-03-05 10:59:14 +02:00
parent 84bc0f8914
commit 53a34ee2d6
9 changed files with 94 additions and 12 deletions

View file

@ -0,0 +1,18 @@
module Concerns::Contact::Identical
extend ActiveSupport::Concern
ATTRIBUTE_FILTER = %w[
name
ident
ident_type
ident_country_code
phone
email
]
private_constant :ATTRIBUTE_FILTER
def identical(registrar)
self.class.where(attributes.slice(*ATTRIBUTE_FILTER)).where(registrar: registrar)
.where.not(id: id).take
end
end

View file

@ -7,6 +7,8 @@ module Concerns::Contact::Transferable
end
def transfer(new_registrar)
return identical(new_registrar) if identical(new_registrar)
new_contact = self.dup
new_contact.registrar = new_registrar
new_contact.original = self

View file

@ -52,7 +52,7 @@ module Concerns::Domain::Transferable
def transfer_registrant(new_registrar)
return if registrant.registrar == new_registrar
self.registrant = registrant.transfer(new_registrar)
self.registrant = registrant.transfer(new_registrar).becomes(Registrant)
end
def transfer_domain_contacts(new_registrar)

View file

@ -3,6 +3,7 @@ class Contact < ActiveRecord::Base
include EppErrors
include UserEvents
include Concerns::Contact::Transferable
include Concerns::Contact::Identical
belongs_to :original, class_name: self.name
belongs_to :registrar, required: true