2017-04-20 20:26:43 -04:00
|
|
|
|
|
|
|
module DiscourseDonations
|
|
|
|
class Rewards
|
2017-04-23 22:49:36 -04:00
|
|
|
attr_reader :user
|
|
|
|
|
2017-04-20 20:26:43 -04:00
|
|
|
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)
|
2017-04-30 20:58:14 -04:00
|
|
|
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)
|
2017-04-20 20:26:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|