Fix admin domains CSV output

This commit is contained in:
Thiago Youssef 2022-03-11 14:37:46 +02:00
parent 9fb4a6d7e6
commit 6263ded68f
5 changed files with 43 additions and 21 deletions

View file

@ -12,7 +12,7 @@ class Version::DomainVersion < PaperTrail::Version
[
domain.name,
registrant_name(domain),
domain.registrant_name,
domain.registrar,
event,
created_at.to_formatted_s(:db)
@ -59,21 +59,4 @@ class Version::DomainVersion < PaperTrail::Version
def self.csv_header
['Name', 'Registrant', 'Registrar', 'Action', 'Created at'].freeze
end
private
def registrant_name(domain)
return domain.registrant.name if domain.registrant
ver = Version::ContactVersion.where(item_id: domain.registrant_id).last
contact = Contact.all_versions_for([domain.registrant_id], created_at).first
if contact.nil? && ver
merged_obj = ver.object_changes.to_h.transform_values(&:last)
result = ver.object.to_h.merge(merged_obj)&.slice(*Contact&.column_names)
contact = Contact.new(result)
end
contact.try(:name) || 'Deleted'
end
end