2022-10-10 21:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module UserAssignments
|
2022-10-20 21:35:43 +08:00
|
|
|
class RemoveTeamUserAssignmentsService
|
|
|
|
def initialize(team_user_assignment)
|
|
|
|
@user = team_user_assignment.user
|
|
|
|
@team = team_user_assignment.assignable
|
2022-10-10 21:27:42 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def call
|
|
|
|
@team.projects.find_each do |project|
|
|
|
|
UserAssignments::PropagateAssignmentJob
|
|
|
|
.perform_now(project, @user, nil, nil, destroy: true, remove_from_team: true)
|
|
|
|
end
|
|
|
|
remove_repositories_assignments
|
|
|
|
remove_protocols_assignments
|
|
|
|
remove_reports_assignments
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def remove_repositories_assignments
|
|
|
|
@team.repositories
|
|
|
|
.joins(:user_assignments)
|
|
|
|
.preload(:user_assignments)
|
|
|
|
.where(user_assignments: { user: @user, team: @team }).find_each do |repository|
|
|
|
|
repository.user_assignments
|
|
|
|
.select { |assignment| assignment.user_id == @user.id && assignment.team_id == @team.id }
|
|
|
|
.each(&:destroy!)
|
|
|
|
end
|
2022-10-20 21:35:43 +08:00
|
|
|
@team.repository_sharing_user_assignments.where(user: @user).find_each(&:destroy!)
|
2022-10-10 21:27:42 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove_protocols_assignments
|
|
|
|
@team.repository_protocols
|
|
|
|
.joins(:user_assignments)
|
|
|
|
.preload(:user_assignments)
|
|
|
|
.where(user_assignments: { user: @user }).find_each do |protocol|
|
|
|
|
protocol.user_assignments
|
|
|
|
.select { |assignment| assignment.user_id == @user.id }
|
|
|
|
.each(&:destroy!)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_reports_assignments
|
|
|
|
@team.reports
|
|
|
|
.joins(:user_assignments)
|
|
|
|
.preload(:user_assignments)
|
|
|
|
.where(user_assignments: { user: @user }).find_each do |report|
|
|
|
|
report.user_assignments
|
|
|
|
.select { |assignment| assignment.user_id == @user.id }
|
|
|
|
.each(&:destroy!)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|