Skip to content

Commit c2ba05c

Browse files
committed
REW-2045 - adds back in base check of file extension
1 parent 4a1a655 commit c2ba05c

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

app/models/concerns/csv2db/active_storage_adapter.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
module Csv2db::ActiveStorageAdapter
22
extend ActiveSupport::Concern
3-
43
FILE_TYPE = 'text/csv'.freeze
54

65
included do
76
has_one_attached :csv_upload
7+
8+
validate :check_file_extension
89
end
910

1011
def file=(file)
1112
# Override Dragonfly setter method
1213
csv_upload.attach(
1314
io: file.tempfile,
1415
filename: file.original_filename,
15-
content_type: FILE_TYPE
16+
content_type: file.content_type
1617
)
1718
end
1819

1920
private
2021

22+
def check_file_extension
23+
# very basic check of file extension
24+
errors.add(:file, I18n.t('shared.file_processor.incorrect_file_type')) unless csv_upload.blob.content_type == FILE_TYPE
25+
end
26+
2127
def file_data
2228
return @file_data if @file_data.present?
2329

app/models/concerns/csv2db/import.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ def set_default_values
194194
end
195195

196196
def str_to_utf8(str)
197-
198197
CharlockHolmes::Converter.convert(str, str_encoding(str), 'UTF-8')
199198
end
200199

0 commit comments

Comments
 (0)