mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:50:00 +08:00
FIX: Check for user presence before granting badge (#11745)
This commit is contained in:
parent
670b438ca5
commit
b547b8415d
|
@ -45,6 +45,7 @@ class BadgeGranter
|
|||
def grant
|
||||
return if @granted_by && !Guardian.new(@granted_by).can_grant_badges?(@user)
|
||||
return unless @badge.present? && @badge.enabled?
|
||||
return if @user.blank?
|
||||
return if @badge.badge_grouping_id == BadgeGrouping::GettingStarted && @badge.id != Badge::NewUserOfTheMonth && @user.user_option.skip_new_user_tips
|
||||
|
||||
find_by = { badge_id: @badge.id, user_id: @user.id }
|
||||
|
|
|
@ -280,6 +280,11 @@ describe BadgeGranter do
|
|||
expect(user.notifications.find_by(notification_type: Notification.types[:granted_badge]).data_hash["badge_id"]).to eq(badge.id)
|
||||
end
|
||||
|
||||
it 'does not fail when user is missing' do
|
||||
BadgeGranter.grant(badge, nil)
|
||||
expect(badge.reload.grant_count).to eq(0)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
describe 'revoke' do
|
||||
|
|
Loading…
Reference in New Issue
Block a user