Update contact(s) name based on eIdentity data from Registrant API

This commit is contained in:
Karl Erik Õunapuu 2020-10-28 16:34:45 +02:00
parent 083be0d536
commit 7a6568c34a
No known key found for this signature in database
GPG key ID: C9DD647298A34764

View file

@ -2,6 +2,7 @@ class RegistrantUser < User
attr_accessor :idc_data
devise :trackable, :timeoutable
after_save :update_related_contacts
def ability
@ability ||= Ability.new(self)
@ -54,6 +55,12 @@ class RegistrantUser < User
username.split.second
end
def update_related_contacts
cc, idcode = registrant_ident.split('-')
contacts = Contact.where(ident: idcode, country_code: cc).where('name != ?', username)
contacts.each { |c| c.update(name: username) }
end
class << self
def find_or_create_by_api_data(user_data = {})
return false unless user_data[:ident]