2021-06-27 19:22:19 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module UserAssignments
|
|
|
|
class GroupAssignmentJob < ApplicationJob
|
|
|
|
queue_as :high_priority
|
|
|
|
|
|
|
|
def perform(team, project, assigned_by)
|
|
|
|
@team = team
|
|
|
|
@assigned_by = assigned_by
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
2021-12-01 23:23:24 +08:00
|
|
|
team.users.where.not(id: assigned_by.id).find_each do |user|
|
|
|
|
user_assignment = UserAssignment.find_or_initialize_by(
|
2021-06-27 19:22:19 +08:00
|
|
|
user: user,
|
2021-12-01 23:23:24 +08:00
|
|
|
assignable: project
|
|
|
|
)
|
|
|
|
|
|
|
|
next if user_assignment.manually_assigned?
|
|
|
|
|
|
|
|
user_assignment.update!(
|
2021-11-10 16:52:37 +08:00
|
|
|
user_role: project.default_public_user_role,
|
2021-12-01 23:23:24 +08:00
|
|
|
assigned_by: @assigned_by
|
2021-06-27 19:22:19 +08:00
|
|
|
)
|
2021-12-01 23:23:24 +08:00
|
|
|
|
2021-06-27 19:22:19 +08:00
|
|
|
# make sure all related experiments and my modules are assigned
|
|
|
|
UserAssignments::PropagateAssignmentJob.perform_later(
|
|
|
|
project,
|
|
|
|
user,
|
2021-11-10 16:52:37 +08:00
|
|
|
project.default_public_user_role,
|
2021-06-27 19:22:19 +08:00
|
|
|
@assigned_by
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|