mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 21:21:19 +08:00
UX: Invalid CSV error message now includes information about the malformed line (#8773)
* UX: Invalid CSV error message now includes information about the malformed line * Update config/locales/server.en.ym and use line_number instead of lineno Co-Authored-By: Robin Ward <robin.ward@gmail.com> Co-authored-by: Robin Ward <robin.ward@gmail.com>
This commit is contained in:
@ -44,11 +44,13 @@ class Admin::BadgesController < Admin::AdminController
|
|||||||
raise Discourse::InvalidParameters if csv_file.try(:tempfile).nil? || badge.nil?
|
raise Discourse::InvalidParameters if csv_file.try(:tempfile).nil? || badge.nil?
|
||||||
|
|
||||||
batch_number = 1
|
batch_number = 1
|
||||||
|
line_number = 1
|
||||||
batch = []
|
batch = []
|
||||||
|
|
||||||
File.open(csv_file) do |csv|
|
File.open(csv_file) do |csv|
|
||||||
csv.each_line do |email_line|
|
csv.each_line do |email_line|
|
||||||
batch.concat CSV.parse_line(email_line)
|
batch.concat CSV.parse_line(email_line)
|
||||||
|
line_number += 1
|
||||||
|
|
||||||
# Split the emails in batches of 200 elements.
|
# Split the emails in batches of 200 elements.
|
||||||
full_batch = csv.lineno % (BadgeGranter::MAX_ITEMS_FOR_DELTA * batch_number) == 0
|
full_batch = csv.lineno % (BadgeGranter::MAX_ITEMS_FOR_DELTA * batch_number) == 0
|
||||||
@ -64,7 +66,7 @@ class Admin::BadgesController < Admin::AdminController
|
|||||||
|
|
||||||
head :ok
|
head :ok
|
||||||
rescue CSV::MalformedCSVError
|
rescue CSV::MalformedCSVError
|
||||||
render_json_error I18n.t('badges.mass_award.errors.invalid_csv'), status: 400
|
render_json_error I18n.t('badges.mass_award.errors.invalid_csv', line_number: line_number), status: 400
|
||||||
end
|
end
|
||||||
|
|
||||||
def badge_types
|
def badge_types
|
||||||
|
@ -4134,7 +4134,7 @@ en:
|
|||||||
badges:
|
badges:
|
||||||
mass_award:
|
mass_award:
|
||||||
errors:
|
errors:
|
||||||
invalid_csv: We couldn't read that CSV file. Please confirm it has one email per line.
|
invalid_csv: We encountered an error on line %{line_number}. Please confirm the CSV has one email per line.
|
||||||
editor:
|
editor:
|
||||||
name: Editor
|
name: Editor
|
||||||
description: First post edit
|
description: First post edit
|
||||||
|
Reference in New Issue
Block a user