FIX: Show a proper error message when trying to bulk award a disabled badge. (#12384)
This commit is contained in:
parent
e7ac906f21
commit
9a779ca99a
|
@ -43,6 +43,14 @@ class Admin::BadgesController < Admin::AdminController
|
|||
badge = Badge.find_by(id: params[:badge_id])
|
||||
raise Discourse::InvalidParameters if csv_file.try(:tempfile).nil? || badge.nil?
|
||||
|
||||
if !badge.enabled?
|
||||
render_json_error(
|
||||
I18n.t('badges.mass_award.errors.badge_disabled', badge_name: badge.display_name),
|
||||
status: 422
|
||||
)
|
||||
return
|
||||
end
|
||||
|
||||
replace_badge_owners = params[:replace_badge_owners] == 'true'
|
||||
BadgeGranter.revoke_all(badge) if replace_badge_owners
|
||||
|
||||
|
|
|
@ -4391,6 +4391,7 @@ en:
|
|||
mass_award:
|
||||
errors:
|
||||
invalid_csv: We encountered an error on line %{line_number}. Please confirm the CSV has one email per line.
|
||||
badge_disabled: Please enable the %{badge_name} badge first.
|
||||
editor:
|
||||
name: Editor
|
||||
description: First post edit
|
||||
|
|
|
@ -229,6 +229,16 @@ describe Admin::BadgesController do
|
|||
|
||||
expect(UserBadge.exists?(user: @user, badge: badge)).to eq(true)
|
||||
end
|
||||
|
||||
it 'fails when the badge is disabled' do
|
||||
badge.update!(enabled: false)
|
||||
|
||||
file = file_from_fixtures('usernames_with_nil_values.csv', 'csv')
|
||||
|
||||
post "/admin/badges/award/#{badge.id}.json", params: { file: fixture_file_upload(file) }
|
||||
|
||||
expect(response.status).to eq(422)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue