mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 11:20:57 -06:00
FIX: handle badge grant for deleted badge (#11558)
This commit is contained in:
parent
e113ddc73c
commit
c9381beb9c
@ -44,7 +44,7 @@ class BadgeGranter
|
|||||||
|
|
||||||
def grant
|
def grant
|
||||||
return if @granted_by && !Guardian.new(@granted_by).can_grant_badges?(@user)
|
return if @granted_by && !Guardian.new(@granted_by).can_grant_badges?(@user)
|
||||||
return unless @badge.enabled?
|
return unless @badge.present? && @badge.enabled?
|
||||||
return if @badge.badge_grouping_id == BadgeGrouping::GettingStarted && @badge.id != Badge::NewUserOfTheMonth && @user.user_option.skip_new_user_tips
|
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 }
|
find_by = { badge_id: @badge.id, user_id: @user.id }
|
||||||
|
@ -208,6 +208,12 @@ describe BadgeGranter do
|
|||||||
expect(Notification.where(user_id: user.id).count).to eq(0)
|
expect(Notification.where(user_id: user.id).count).to eq(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "handles deleted badge" do
|
||||||
|
freeze_time
|
||||||
|
user_badge = BadgeGranter.grant(nil, user, created_at: 1.year.ago)
|
||||||
|
expect(user_badge).to eq(nil)
|
||||||
|
end
|
||||||
|
|
||||||
it "doesn't grant disabled badges" do
|
it "doesn't grant disabled badges" do
|
||||||
freeze_time
|
freeze_time
|
||||||
badge = Fabricate(:badge, badge_type_id: BadgeType::Bronze, enabled: false)
|
badge = Fabricate(:badge, badge_type_id: BadgeType::Bronze, enabled: false)
|
||||||
|
Loading…
Reference in New Issue
Block a user