Commit f36e3a3 1 parent e3819e8 commit f36e3a3 Copy full SHA for f36e3a3
File tree 1 file changed +23
-10
lines changed
1 file changed +23
-10
lines changed Original file line number Diff line number Diff line change @@ -58,22 +58,35 @@ def render_commercial
58
58
# EventID, Title, URL
59
59
def mass_upload
60
60
errors = Commercial . read_file ( params [ :file ] ) if params [ :file ]
61
-
61
+
62
62
if !params [ :file ]
63
63
flash [ :error ] = 'Empty file detected while adding materials to Event'
64
- elsif errors . all? { |_k , v | v . blank? }
65
- flash [ :notice ] = 'Successfully added materials.'
66
- else
67
- errors_text = ''
68
- errors_text += 'Unable to find event with ID: ' + errors [ :no_event ] . join ( ', ' ) + '. ' if errors [ :no_event ] . any?
69
- if errors [ :validation_errors ] . any?
70
- errors_text += 'There were some errors: ' + errors [ :validation_errors ] . join ( '. ' )
64
+ elsif errors . present?
65
+ errors_text = aggregate_errors ( errors )
66
+ if errors_text . length > 4000 # If the error string exceeds 4 KB
67
+ flash [ :error ] = 'There are too many errors to display. Please check your CSV file for issues.'
68
+ else
69
+ flash [ :error ] = errors_text
71
70
end
72
-
73
- flash [ :error ] = errors_text
71
+ else
72
+ flash [ :notice ] = 'Successfully added materials.'
74
73
end
75
74
redirect_back ( fallback_location : root_path )
76
75
end
76
+
77
+ private
78
+
79
+ # Aggregate errors and ensure that they do not exceed 4 KB in total size
80
+ def aggregate_errors ( errors )
81
+ errors_text = ''
82
+ if errors [ :no_event ] . any?
83
+ errors_text += 'Unable to find events with IDs: ' + errors [ :no_event ] . join ( ', ' ) + '. '
84
+ end
85
+ if errors [ :validation_errors ] . any?
86
+ errors_text += 'Validation errors: ' + errors [ :validation_errors ] . join ( '. ' )
87
+ end
88
+ errors_text
89
+ end
77
90
78
91
private
79
92
You can’t perform that action at this time.
0 commit comments