Skip to content

Commit

Permalink
fix: migration to fix invalid task upload filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
macite committed Sep 21, 2024
1 parent 166690f commit ac80fec
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions db/migrate/20240920052508_convert_task_def_filenames.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class ConvertTaskDefFilenames < ActiveRecord::Migration[7.1]

# Check filenames in the upload requirements for each task definition
# and replace any invalid characters using sanitize filename
def change
TaskDefinition.find_in_batches do |group|
group.each do |task_def|
next if task_def.valid?

upload_req = task_def.upload_requirements

change = false
upload_req.each do |req|
unless req['name'].match?(/^[a-zA-Z0-9_\- \.]+$/)
req['name'] = FileHelper.sanitized_filename(req['name'])
change = true
end

if req['name'].blank?
req['name'] = 'file'
change = true
end
end

unless change && task_def.valid? && task_def.save
puts "Remaining issue with task definition #{task_def.id}"
end
puts '.'
end
end
end
end

0 comments on commit ac80fec

Please sign in to comment.