Skip to content

Commit 031fa7c

Browse files
committed
REW-2045 - adds download_link method for dragonfly adapter and use this method on import table, this method can then be overwritten in file processor model's so custom logic can be added.
1 parent c170ac0 commit 031fa7c

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

app/models/concerns/csv2db/active_storage_adapter.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ def file=(file)
2828
self.file_name = filename
2929
end
3030

31-
def download_link(expires_in: LINK_MAX_EXPIRY)
32-
return unless file_attachment.present?
31+
def download_link
32+
return unless file_attachment.present? && file_attachment.attached?
3333

3434
set_current_host
3535

36-
file_attachment.service_url(expires_in: expires_in.to_i, disposition: 'attachment')
36+
file_attachment.service_url(
37+
expires_in: LINK_MAX_EXPIRY.to_i,
38+
disposition: 'attachment'
39+
)
3740
end
3841

3942
private

app/models/concerns/csv2db/dragonfly_adapter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ module Csv2db::DragonflyAdapter
1111
validate :check_file_extension
1212
end
1313

14+
def download_link
15+
file.url
16+
end
17+
1418
private
1519

1620
def check_file_extension

app/views/csv2db/_csv_import_table.html.haml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
%tr
1616
%td= import.id
1717
%td= import.created_at
18-
- if Csv2db.config.storage_adapter.active_storage?
19-
%td= link_to import.file_name, import.download_link
20-
- else
21-
%td= link_to import.file.name, import.file.url, target: '_blank'
18+
%td= link_to(import.file_name, import.download_link)
2219
%td
2320
.badge{ class: "badge-upload-#{import.status}" }= import.status
2421
%td

0 commit comments

Comments
 (0)