2022-10-10 21:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module UserAssignments
|
2022-10-20 21:35:43 +08:00
|
|
|
class UpdateTeamUserAssignmentsService
|
|
|
|
def initialize(team_user_assignment)
|
|
|
|
@user = team_user_assignment.user
|
|
|
|
@team = team_user_assignment.assignable
|
2022-10-21 20:04:33 +08:00
|
|
|
@user_role = team_user_assignment.user_role
|
2022-10-10 21:27:42 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def call
|
|
|
|
update_repositories_assignments
|
|
|
|
update_reports_assignments
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def update_repositories_assignments
|
|
|
|
@team.repositories
|
2023-09-06 17:06:22 +08:00
|
|
|
.joins(:user_assignments)
|
|
|
|
.preload(:user_assignments)
|
|
|
|
.where(user_assignments: { user: @user, team: @team })
|
2022-10-10 21:27:42 +08:00
|
|
|
.find_each do |repository|
|
2023-09-06 17:06:22 +08:00
|
|
|
repository.user_assignments
|
2022-10-18 16:43:51 +08:00
|
|
|
.select { |assignment| assignment[:user_id] == @user.id && assignment[:team_id] == @team.id }
|
2022-10-10 21:27:42 +08:00
|
|
|
.each { |assignment| assignment.update!(user_role: @user_role) }
|
|
|
|
end
|
2022-10-26 05:26:20 +08:00
|
|
|
@team.repository_sharing_user_assignments.where(user: @user).find_each do |assignment|
|
|
|
|
assignment.update!(user_role: @user_role)
|
|
|
|
end
|
2022-10-10 21:27:42 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def update_reports_assignments
|
|
|
|
@team.reports
|
|
|
|
.joins(:automatic_user_assignments)
|
|
|
|
.preload(:automatic_user_assignments)
|
|
|
|
.where(automatic_user_assignments: { user: @user })
|
|
|
|
.find_each do |report|
|
|
|
|
report.automatic_user_assignments
|
2022-10-20 21:35:43 +08:00
|
|
|
.select { |assignment| assignment.user_id == @user.id }
|
2022-10-10 21:27:42 +08:00
|
|
|
.each { |assignment| assignment.update!(user_role: @user_role) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|