2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-01-23 12:25:43 -05:00
|
|
|
module Jobs
|
2019-10-02 00:01:53 -04:00
|
|
|
class AutomaticGroupMembership < ::Jobs::Base
|
2015-01-23 12:25:43 -05:00
|
|
|
def execute(args)
|
|
|
|
group_id = args[:group_id]
|
|
|
|
raise Discourse::InvalidParameters.new(:group_id) if group_id.blank?
|
|
|
|
|
2018-05-14 19:48:30 -04:00
|
|
|
group = Group.find_by(id: group_id)
|
|
|
|
raise Discourse::InvalidParameters.new(:group_id) if group.nil?
|
2015-01-23 12:25:43 -05:00
|
|
|
|
2020-04-22 12:37:39 -04:00
|
|
|
domains = group.automatic_membership_email_domains
|
|
|
|
return if domains.blank?
|
2015-01-23 12:25:43 -05:00
|
|
|
|
2020-04-22 12:37:39 -04:00
|
|
|
Group
|
|
|
|
.automatic_membership_users(domains)
|
|
|
|
.find_each do |user|
|
2017-06-14 13:20:18 -04:00
|
|
|
next unless user.email_confirmed?
|
2019-09-10 12:58:08 -04:00
|
|
|
group.add(user, automatic: true)
|
2017-06-14 13:20:18 -04:00
|
|
|
GroupActionLogger.new(Discourse.system_user, group).log_add_user_to_group(user)
|
2015-01-23 12:25:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|