mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 20:51:50 +08:00
25 lines
717 B
Ruby
25 lines
717 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class AutomaticGroupMembership < ::Jobs::Base
|
|
def execute(args)
|
|
group_id = args[:group_id]
|
|
raise Discourse::InvalidParameters.new(:group_id) if group_id.blank?
|
|
|
|
group = Group.find_by(id: group_id)
|
|
raise Discourse::InvalidParameters.new(:group_id) if group.nil?
|
|
|
|
domains = group.automatic_membership_email_domains
|
|
return if domains.blank?
|
|
|
|
Group
|
|
.automatic_membership_users(domains)
|
|
.find_each do |user|
|
|
next unless user.email_confirmed?
|
|
group.add(user, automatic: true)
|
|
GroupActionLogger.new(Discourse.system_user, group).log_add_user_to_group(user)
|
|
end
|
|
end
|
|
end
|
|
end
|