From 326ded80102ae0759d6e42cb1e79d57607eb8caa Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 25 Jan 2018 12:29:08 +0200 Subject: [PATCH] Extract contact transferable module #660 --- app/models/concerns/contact/transferable.rb | 10 ++++++++++ app/models/contact.rb | 7 ------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/models/concerns/contact/transferable.rb b/app/models/concerns/contact/transferable.rb index 3805287ac..4124bc7c1 100644 --- a/app/models/concerns/contact/transferable.rb +++ b/app/models/concerns/contact/transferable.rb @@ -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 diff --git a/app/models/contact.rb b/app/models/contact.rb index 85687cb6f..c0c4c00ee 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -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