Clear contact address fields if address processing turned off

This commit is contained in:
Karl Erik Õunapuu 2020-08-10 12:47:02 +03:00
parent 8688de3248
commit 3b53e12284

View file

@ -62,6 +62,7 @@ class Contact < ApplicationRecord
mapping: [%w[ident code], %w[ident_type type], %w[ident_country_code country_code]]
after_save :update_related_whois_records
before_save :clear_address_modifications, if: -> { !self.class.address_processing? }
self.ignored_columns = %w[legacy_id legacy_history_id]
@ -507,6 +508,21 @@ class Contact < ApplicationRecord
]).present?
end
def clear_address_modifications
return unless modifies_address?
addr_fields = %i[city street zip state country_code]
addr_fields.each { |field| self[field] = nil }
end
def modifies_address?
addr_fields = %i[city street zip state country_code]
modified = false
addr_fields.each { |field| modified = true if changes.key?(field) }
modified
end
def update_related_whois_records
# not doing anything if no real changes
ignored_columns = %w[updated_at created_at statuses status_notes]