@@ -331,23 +331,22 @@ def perform_update!(study_file)
331
331
end
332
332
if safe_file_params [ :custom_color_updates ]
333
333
parsed_update = JSON . parse ( safe_file_params [ :custom_color_updates ] )
334
- safe_file_params [ 'cluster_file_info' ] = { custom_colors : ClusterFileInfo . merge_color_updates ( study_file , parsed_update ) }
335
- safe_file_params . delete ( :custom_color_updates )
334
+ safe_file_params [ :cluster_file_info_attributes ] = {
335
+ custom_colors : ClusterFileInfo . merge_color_updates ( study_file , parsed_update )
336
+ }
336
337
end
337
338
338
339
# manually check first if species/assembly was supplied by name
339
340
species_name = safe_file_params [ :species ]
340
- safe_file_params . delete ( :species )
341
341
assembly_name = safe_file_params [ :assembly ]
342
- safe_file_params . delete ( :assembly )
343
342
set_taxon_and_assembly_by_name ( { species : species_name , assembly : assembly_name } )
344
343
# clear the id so that it doesn't get overwritten -- this would be a security hole for existing files
345
344
# and for new files the id will have been set along with creation of the StudyFile object in the `create`
346
345
# method above
347
346
safe_file_params . delete ( :_id )
348
347
349
348
parse_on_upload = safe_file_params [ :parse_on_upload ]
350
- safe_file_params . delete ( :parse_on_upload )
349
+ cleaned_params = self . class . strip_undefined_params ( safe_file_params )
351
350
352
351
# check if the name of the file has changed as we won't be able to tell after we saved
353
352
name_changed = study_file . persisted? && study_file . name != safe_file_params [ :name ]
@@ -363,7 +362,7 @@ def perform_update!(study_file)
363
362
fileSize : study_file . upload_file_size
364
363
} , current_api_user )
365
364
366
- study_file . update! ( safe_file_params )
365
+ study_file . update! ( cleaned_params )
367
366
368
367
# invalidate caches first
369
368
study_file . delay . invalidate_cache_by_file_type
@@ -388,7 +387,7 @@ def perform_update!(study_file)
388
387
end
389
388
end
390
389
391
- if [ 'Expression Matrix' , 'MM Coordinate Matrix' ] . include? ( study_file . file_type ) && ! safe_file_params [ :y_axis_label ] . blank ?
390
+ if [ 'Expression Matrix' , 'MM Coordinate Matrix' ] . include? ( study_file . file_type ) && cleaned_params [ :y_axis_label ] . present ?
392
391
# if user is supplying an expression axis label, update default options hash
393
392
study . default_options [ :expression_label ] = safe_file_params [ :y_axis_label ]
394
393
study . save
@@ -400,8 +399,8 @@ def perform_update!(study_file)
400
399
end
401
400
end
402
401
403
- if safe_file_params [ :upload ] . present? && !is_chunked ||
404
- safe_file_params [ :remote_location ] . present? ||
402
+ if cleaned_params [ :upload ] . present? && !is_chunked ||
403
+ cleaned_params [ :remote_location ] . present? ||
405
404
study_file . needs_raw_counts_extraction?
406
405
complete_upload_process ( study_file , parse_on_upload )
407
406
end
@@ -705,6 +704,29 @@ def bundle
705
704
end
706
705
end
707
706
707
+ # remove any remaining parameters that aren't defined and can cause UnknownAttribute errors when saving
708
+ def self . strip_undefined_params ( parameters )
709
+ safe_params = { }
710
+ transform = parameters . is_a? ( ActionController ::Parameters ) ? :to_unsafe_hash : :with_indifferent_access
711
+ accessible_params = parameters . send ( transform )
712
+ StudyFile . nested_attributes . keys . map do |association |
713
+ classname = association . to_s . chomp ( '_attributes' ) . singularize . camelize
714
+ next unless Object . const_defined? ( classname ) && accessible_params [ association ] . present?
715
+
716
+ assoc_class = classname . constantize
717
+ safe_params [ association ] = { }
718
+ accessible_params [ association ] . each do |attribute , value |
719
+ safe_params [ association ] [ attribute ] = value if assoc_class . fields [ attribute . to_s ] . present?
720
+ end
721
+ end
722
+ accessible_params . each do |param , val |
723
+ next if param . to_s . ends_with? ( '_attributes' )
724
+
725
+ safe_params [ param ] = val if StudyFile . fields [ param . to_s ] . present?
726
+ end
727
+ safe_params
728
+ end
729
+
708
730
private
709
731
710
732
# manual check to see if user supplied taxon/assembly by name
0 commit comments