diff --git a/app/jobs/regular/update_badges.rb b/app/jobs/regular/update_badges.rb index 702d876ca..5895835ce 100644 --- a/app/jobs/regular/update_badges.rb +++ b/app/jobs/regular/update_badges.rb @@ -26,7 +26,7 @@ module Jobs user = post.user # Grant "Welcome" badge to the user if they do not already have it. - BadgeGranter.grant(Badge.find(5), user) + BadgeGranter.grant(Badge.find(Badge::Welcome), user) Badge.like_badge_counts.each do |badge_id, count| if post.like_count >= count diff --git a/app/services/badge_granter.rb b/app/services/badge_granter.rb index dfec5d9c9..33d01fc6b 100644 --- a/app/services/badge_granter.rb +++ b/app/services/badge_granter.rb @@ -13,7 +13,13 @@ class BadgeGranter def grant return if @granted_by and !Guardian.new(@granted_by).can_grant_badges?(@user) - user_badge = UserBadge.find_by(badge_id: @badge.id, user_id: @user.id, post_id: @post_id) + find_by = { badge_id: @badge.id, user_id: @user.id } + + if @badge.multiple_grant? + find_by[:post_id] = @post_id + end + + user_badge = UserBadge.find_by(find_by) if user_badge.nil? || (@badge.multiple_grant? && @post_id.nil?) UserBadge.transaction do