From e5fe82a297d7d5627b9d3a3c3150dddc8af0abe7 Mon Sep 17 00:00:00 2001 From: Oleksii Kriuchykhin Date: Wed, 28 Jun 2023 10:22:26 +0200 Subject: [PATCH] Fix file name of inventory export, add archived columns to exports [SCI-8760] --- app/jobs/repositories_export_job.rb | 2 +- app/models/zip_export.rb | 5 +++-- app/services/repository_zip_export.rb | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/jobs/repositories_export_job.rb b/app/jobs/repositories_export_job.rb index 11eabf078..35bdcf601 100644 --- a/app/jobs/repositories_export_job.rb +++ b/app/jobs/repositories_export_job.rb @@ -47,7 +47,7 @@ class RepositoriesExportJob < ApplicationJob csv_file = FileUtils.touch("#{path}/#{repository_name}.csv").first # Define headers and columns IDs - col_ids = [-3, -4, -5, -6] + repository.repository_columns.map(&:id) + col_ids = [-3, -4, -5, -6, -7, -8] + repository.repository_columns.map(&:id) # Define callback function for file name assets = {} diff --git a/app/models/zip_export.rb b/app/models/zip_export.rb index 2558f4d94..292d8d413 100644 --- a/app/models/zip_export.rb +++ b/app/models/zip_export.rb @@ -49,11 +49,12 @@ class ZipExport < ApplicationRecord I18n.backend.date_format = user.settings[:date_format] || Constants::DEFAULT_DATE_FORMAT zip_input_dir = FileUtils.mkdir_p(File.join(Rails.root, "tmp/temp_zip_#{Time.now.to_i}")).first tmp_zip_dir = FileUtils.mkdir_p(File.join(Rails.root, 'tmp/zip-ready')).first - tmp_full_zip_name = File.join(tmp_zip_dir, "export_#{Time.now.strftime('%F %H-%M-%S_UTC')}.zip") + tmp_zip_name = "export_#{Time.now.strftime('%F %H-%M-%S_UTC')}.zip" + tmp_full_zip_name = File.join(tmp_zip_dir, tmp_zip_name) fill_content(zip_input_dir, data, type, options) zip!(zip_input_dir, tmp_full_zip_name) - zip_file.attach(io: File.open(tmp_full_zip_name), filename: tmp_full_zip_name) + zip_file.attach(io: File.open(tmp_full_zip_name), filename: tmp_zip_name) generate_notification(user) if save ensure FileUtils.rm_rf([zip_input_dir, tmp_full_zip_name], secure: true) diff --git a/app/services/repository_zip_export.rb b/app/services/repository_zip_export.rb index 83a609f30..9069f4a9c 100644 --- a/app/services/repository_zip_export.rb +++ b/app/services/repository_zip_export.rb @@ -80,9 +80,9 @@ module RepositoryZipExport when -6 I18n.l(row.created_at, format: :full) when -7 - row.archived_by.full_name + row.archived_by.present? ? row.archived_by.full_name : '' when -8 - I18n.l(row.archived_on, format: :full) + row.archived_on.present? ? I18n.l(row.archived_on, format: :full) : '' else cell = row.repository_cells .find_by(repository_column_id: c_id)