From 31da660e766c66073375df1848c8e45b03675652 Mon Sep 17 00:00:00 2001 From: Rob Kaufman Date: Thu, 23 May 2024 22:25:12 -0700 Subject: [PATCH 1/2] add support for downloading the original file --- app/controllers/bulkrax/importers_controller.rb | 10 +++++++++- app/models/bulkrax/importer.rb | 8 ++++++++ app/views/bulkrax/importers/show.html.erb | 10 +++++----- config/routes.rb | 1 + 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/controllers/bulkrax/importers_controller.rb b/app/controllers/bulkrax/importers_controller.rb index 284caafe..2fe5c470 100644 --- a/app/controllers/bulkrax/importers_controller.rb +++ b/app/controllers/bulkrax/importers_controller.rb @@ -13,7 +13,7 @@ class ImportersController < ::Bulkrax::ApplicationController before_action :token_authenticate!, if: -> { api_request? }, only: [:create, :update, :delete] before_action :authenticate_user!, unless: -> { api_request? } before_action :check_permissions - before_action :set_importer, only: [:show, :entry_table, :edit, :update, :destroy] + before_action :set_importer, only: [:show, :entry_table, :edit, :update, :destroy, :original_file] with_themed_layout 'dashboard' if defined?(::Hyrax) # GET /importers @@ -201,6 +201,14 @@ def external_sets end end + def original_file + if @importer.original_file? + send_file @importer.original_file + else + redirect_to @importer, alert: 'Importer does not support file re-download or the imported file is not found on the server.' + end + end + # GET /importers/1/export_errors def export_errors @importer = Importer.find(params[:importer_id]) diff --git a/app/models/bulkrax/importer.rb b/app/models/bulkrax/importer.rb index ef60c080..f838eb77 100644 --- a/app/models/bulkrax/importer.rb +++ b/app/models/bulkrax/importer.rb @@ -149,6 +149,14 @@ def seen @seen ||= {} end + def original_file? + File.exists?(self.parser_fields['import_file_path']) + end + + def original_file + self.parser_fields['import_file_path'] if original_file? + end + def replace_files self.parser_fields['replace_files'] end diff --git a/app/views/bulkrax/importers/show.html.erb b/app/views/bulkrax/importers/show.html.erb index 26f38415..b1d1870a 100644 --- a/app/views/bulkrax/importers/show.html.erb +++ b/app/views/bulkrax/importers/show.html.erb @@ -1,12 +1,12 @@

Importer: <%= @importer.name %>

- - <% if @importer.failed_entries? %> -
+
+ <%= link_to 'Download Original File', importer_original_file_path(@importer.id), class: 'btn btn-primary', data: { turbolinks: false } if @importer.original_file %> + <% if @importer.failed_entries? %> <%= link_to 'Export Errored Entries', importer_export_errors_path(@importer.id), class: 'btn btn-primary', data: { turbolinks: false }%> <%= link_to 'Upload Corrected Entries', importer_upload_corrected_entries_path(@importer.id), class: 'btn btn-primary' if @importer.parser.is_a?(Bulkrax::CsvParser) %> -
- <% end %> + <% end %> +
diff --git a/config/routes.rb b/config/routes.rb index 40151149..c4dfc4c6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,6 +11,7 @@ end resources :importers do put :continue + get :original_file get :entry_table get :export_errors collection do From 018d33829553c2787dd676466d25b6a61b97cca4 Mon Sep 17 00:00:00 2001 From: Shana Moore Date: Thu, 30 May 2024 08:42:15 -0700 Subject: [PATCH 2/2] Update app/models/bulkrax/importer.rb Co-authored-by: Kiah Stroud <32469930+bkiahstroud@users.noreply.github.com> --- app/models/bulkrax/importer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/bulkrax/importer.rb b/app/models/bulkrax/importer.rb index f838eb77..649945a5 100644 --- a/app/models/bulkrax/importer.rb +++ b/app/models/bulkrax/importer.rb @@ -150,7 +150,7 @@ def seen end def original_file? - File.exists?(self.parser_fields['import_file_path']) + File.exist?(self.parser_fields['import_file_path']) end def original_file