2022-07-27 10:34:08 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
|
|
|
class PublishGroupMembershipUpdates < ::Jobs::Base
|
|
|
|
def execute(args)
|
2022-08-11 10:33:41 -04:00
|
|
|
available_types = [Group::AUTO_GROUPS_ADD, Group::AUTO_GROUPS_REMOVE]
|
|
|
|
raise Discourse::InvalidParameters.new(:type) if !available_types.include?(args[:type])
|
2022-07-27 10:34:08 -04:00
|
|
|
|
|
|
|
group = Group.find_by(id: args[:group_id])
|
|
|
|
return if !group
|
|
|
|
|
2022-08-11 10:33:41 -04:00
|
|
|
added_members = args[:type] == Group::AUTO_GROUPS_ADD
|
2022-07-27 10:34:08 -04:00
|
|
|
|
|
|
|
User
|
|
|
|
.human_users
|
|
|
|
.where(id: args[:user_ids])
|
|
|
|
.each do |user|
|
|
|
|
if added_members
|
|
|
|
group.trigger_user_added_event(user, group.automatic?)
|
|
|
|
else
|
|
|
|
group.trigger_user_removed_event(user)
|
2023-01-09 07:20:10 -05:00
|
|
|
end
|
2022-07-27 10:34:08 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|