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