Tweak badge granter not to try to double grant

This commit is contained in:
Sam 2014-04-14 15:58:27 +10:00
parent cfccf8b4ed
commit 0d114d7b17

View File

@ -12,15 +12,17 @@ class BadgeGranter
def grant def grant
return if @granted_by and !Guardian.new(@granted_by).can_grant_badges?(@user) return if @granted_by and !Guardian.new(@granted_by).can_grant_badges?(@user)
user_badge = nil user_badge = UserBadge.find_by(badge_id: @badge.id, user_id: @user.id)
UserBadge.transaction do unless user_badge
user_badge = UserBadge.create!(badge: @badge, user: @user, UserBadge.transaction do
granted_by: @granted_by, granted_at: Time.now) user_badge = UserBadge.create!(badge: @badge, user: @user,
granted_by: @granted_by, granted_at: Time.now)
Badge.increment_counter 'grant_count', @badge.id Badge.increment_counter 'grant_count', @badge.id
if @granted_by != Discourse.system_user if @granted_by != Discourse.system_user
StaffActionLogger.new(@granted_by).log_badge_grant(user_badge) StaffActionLogger.new(@granted_by).log_badge_grant(user_badge)
end
end end
end end