Extract contact transferable module

#660
This commit is contained in:
Artur Beljajev 2018-01-25 12:29:08 +02:00
parent 4254fa0c94
commit 326ded8010
2 changed files with 10 additions and 7 deletions

View file

@ -1,6 +1,10 @@
module Concerns::Contact::Transferable
extend ActiveSupport::Concern
included do
after_initialize :generate_auth_info, if: :new_record?
end
def transfer(new_registrar)
new_contact = self.dup
new_contact.registrar = new_registrar
@ -10,4 +14,10 @@ module Concerns::Contact::Transferable
new_contact.save!
new_contact
end
def generate_auth_info
return if @generate_auth_info_disabled
return if auth_info.present?
self.auth_info = SecureRandom.hex(11)
end
end

View file

@ -45,7 +45,6 @@ class Contact < ActiveRecord::Base
before_validation :to_upcase_country_code
before_validation :strip_email
before_create :generate_auth_info
before_update :manage_emails
composed_of :identifier,
@ -314,12 +313,6 @@ class Contact < ActiveRecord::Base
!org?
end
def generate_auth_info
return if @generate_auth_info_disabled
return if auth_info.present?
self.auth_info = SecureRandom.hex(11)
end
# def auth_info=(pw)
# self[:auth_info] = pw if new_record?
# end