-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: migration to fix invalid task upload filenames
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |