discourse-subscriptions/app/services/discourse_donations/rewards.rb

30 lines
604 B
Ruby
Raw Normal View History

module DiscourseDonations
class Rewards
2017-04-23 22:49:36 -04:00
attr_reader :user
def initialize(user)
@user = user
end
def add_to_group(name)
2017-04-23 21:44:55 -04:00
grp = ::Group.find_by_name(name)
return if grp.nil?
2017-04-23 22:49:36 -04:00
log_group_add(grp)
grp.add(user)
2017-04-23 21:44:55 -04:00
end
def grant_badge(name)
return unless SiteSetting.enable_badges
2017-04-23 21:44:55 -04:00
badge = ::Badge.find_by_name(name)
return if badge.nil?
2017-04-23 22:49:36 -04:00
BadgeGranter.grant(badge, user)
end
def log_group_add(grp)
system_user = User.find(-1)
GroupActionLogger.new(system_user, grp).log_add_user_to_group(user)
end
end
end