mirror of
https://github.com/internetee/registry.git
synced 2025-07-29 05:56:20 +02:00
Fix admin domains CSV output
This commit is contained in:
parent
9fb4a6d7e6
commit
6263ded68f
5 changed files with 43 additions and 21 deletions
|
@ -753,6 +753,35 @@ class Domain < ApplicationRecord
|
|||
contacts.select(&:email_verification_failed?)&.map(&:email)&.uniq
|
||||
end
|
||||
|
||||
def as_csv_row
|
||||
[
|
||||
name,
|
||||
registrant_name,
|
||||
valid_to.to_formatted_s(:db),
|
||||
registrar,
|
||||
created_at.to_formatted_s(:db),
|
||||
statuses,
|
||||
contacts.pluck(:code),
|
||||
force_delete_date,
|
||||
force_delete_data
|
||||
]
|
||||
end
|
||||
|
||||
def registrant_name
|
||||
return registrant.name if registrant
|
||||
|
||||
ver = Version::ContactVersion.where(item_id: registrant_id).last
|
||||
contact = Contact.all_versions_for([registrant_id], created_at).first
|
||||
|
||||
contact = ObjectVersionsParser.new(ver).parse if contact.nil? && ver
|
||||
|
||||
contact.try(:name) || 'Deleted'
|
||||
end
|
||||
|
||||
def self.csv_header
|
||||
['Domain', 'Registrant', 'Valid to', 'Registrar', 'Created at', 'Statuses', 'Contacts code', 'Force delete date', 'Force delete data'].freeze
|
||||
end
|
||||
|
||||
def self.pdf(html)
|
||||
kit = PDFKit.new(html)
|
||||
kit.to_pdf
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -12,6 +12,6 @@ class CsvGenerator
|
|||
private
|
||||
|
||||
def self.custom_csv(class_name)
|
||||
[Version::DomainVersion, Version::ContactVersion].include?(class_name)
|
||||
[Version::DomainVersion, Version::ContactVersion, Domain].include?(class_name)
|
||||
end
|
||||
end
|
||||
|
|
7
test/fixtures/files/domains.csv
vendored
7
test/fixtures/files/domains.csv
vendored
|
@ -1,2 +1,7 @@
|
|||
Domain,Registrant,Valid to,Registrar,Created at,Statuses,Contacts code,Force delete date,Force delete data
|
||||
hospital.test,Thiago,05/07/2010 03:00,Good Names,05/07/2009 03:00,[],[john-001, william-001, william-001],08/03/2022 00:00,
|
||||
shop.test,John,2010-07-04 21:00:00,Best Names,2010-07-05 07:30:00,"[""ok""]","[""william-001"", ""jane-001"", ""acme-ltd-001""]",2010-07-08,
|
||||
airport.test,John,2010-07-05 00:00:00,Best Names,2010-07-05 07:30:00,"[""ok""]","[""john-001"", ""william-001"", ""william-001""]",,
|
||||
library.test,Acme Ltd,2010-07-05 00:00:00,Best Names,2010-07-05 07:30:00,"[""inactive""]","[""john-001"", ""acme-ltd-001""]",,
|
||||
metro.test,Jack,2010-07-05 00:00:00,Good Names,2010-07-05 07:30:00,[],"[""jack-001"", ""jack-001""]",,
|
||||
hospital.test,John,2010-07-05 00:00:00,Good Names,2010-07-05 07:30:00,"[""inactive""]","[""john-001"", ""john-001""]",,
|
||||
invalid.test,any,2010-07-04 21:00:00,Best Names,2010-07-05 07:30:00,"[""inactive""]","[""invalid"", ""invalid""]",,
|
||||
|
|
|
|
@ -5,6 +5,11 @@ class AdminAreaCsvTest < ApplicationSystemTestCase
|
|||
|
||||
def test_downloads_domain_list_as_csv
|
||||
travel_to Time.zone.parse('2010-07-05 10:30')
|
||||
Domain.all.each do |domain|
|
||||
domain.created_at = Time.zone.now
|
||||
domain.save(:validate => false)
|
||||
end
|
||||
|
||||
visit admin_domains_url
|
||||
click_link('CSV')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue