2015-01-24 01:25:43 +08:00
|
|
|
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(group_id)
|
|
|
|
|
|
|
|
return unless group.automatic_membership_retroactive
|
|
|
|
|
|
|
|
domains = group.automatic_membership_email_domains.gsub('.', '\.')
|
|
|
|
|
2015-01-27 06:17:29 +08:00
|
|
|
User.where("email ~* '@(#{domains})$'").find_each do |user|
|
2015-06-17 21:38:45 +08:00
|
|
|
group.add(user) rescue ActiveRecord::RecordNotUnique, PG::UniqueViolation
|
2015-01-24 01:25:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|