2020-01-13 22:20:26 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
|
|
|
class MassAwardBadge < ::Jobs::Base
|
|
|
|
def execute(args)
|
2020-02-18 21:53:12 +08:00
|
|
|
return unless mode = args[:mode]
|
2020-01-13 22:20:26 +08:00
|
|
|
badge = Badge.find_by(id: args[:badge_id])
|
2020-02-18 21:53:12 +08:00
|
|
|
|
|
|
|
users = User.select(:id, :username, :locale)
|
|
|
|
|
|
|
|
if mode == 'email'
|
|
|
|
users = users.with_email(args[:users_batch])
|
|
|
|
else
|
|
|
|
users = users.where(username_lower: args[:users_batch].map!(&:downcase))
|
|
|
|
end
|
2020-01-13 22:20:26 +08:00
|
|
|
|
|
|
|
return if users.empty? || badge.nil?
|
|
|
|
|
|
|
|
BadgeGranter.mass_grant(badge, users)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|