mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 10:42:45 +08:00
Move badge grant_count updating to the UserBadge model callbacks.
This commit is contained in:
parent
a68b47cb9f
commit
b3f403952b
|
@ -8,6 +8,14 @@ class UserBadge < ActiveRecord::Base
|
|||
validates :user_id, presence: true
|
||||
validates :granted_at, presence: true
|
||||
validates :granted_by, presence: true
|
||||
|
||||
after_create do
|
||||
Badge.increment_counter 'grant_count', self.badge_id
|
||||
end
|
||||
|
||||
after_destroy do
|
||||
Badge.decrement_counter 'grant_count', self.badge_id
|
||||
end
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
|
|
@ -19,7 +19,6 @@ class BadgeGranter
|
|||
user_badge = UserBadge.create!(badge: @badge, user: @user,
|
||||
granted_by: @granted_by, granted_at: Time.now)
|
||||
|
||||
Badge.increment_counter 'grant_count', @badge.id
|
||||
if @granted_by != Discourse.system_user
|
||||
StaffActionLogger.new(@granted_by).log_badge_grant(user_badge)
|
||||
end
|
||||
|
@ -37,7 +36,6 @@ class BadgeGranter
|
|||
def self.revoke(user_badge, options={})
|
||||
UserBadge.transaction do
|
||||
user_badge.destroy!
|
||||
Badge.decrement_counter 'grant_count', user_badge.badge_id
|
||||
if options[:revoked_by]
|
||||
StaffActionLogger.new(options[:revoked_by]).log_badge_revoke(user_badge)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user