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:
Roman Rizzi 2020-01-23 14:04:06 -03:00 committed by GitHub
parent 821e920711
commit db5373a87c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -44,11 +44,13 @@ class Admin::BadgesController < Admin::AdminController
raise Discourse::InvalidParameters if csv_file.try(:tempfile).nil? || badge.nil?
batch_number = 1
line_number = 1
batch = []
File.open(csv_file) do |csv|
csv.each_line do |email_line|
batch.concat CSV.parse_line(email_line)
line_number += 1
# Split the emails in batches of 200 elements.
full_batch = csv.lineno % (BadgeGranter::MAX_ITEMS_FOR_DELTA * batch_number) == 0
@ -64,7 +66,7 @@ class Admin::BadgesController < Admin::AdminController
head :ok
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
def badge_types

View File

@ -4134,7 +4134,7 @@ en:
badges:
mass_award:
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:
name: Editor
description: First post edit