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-10 21:27:42 +08:00
|
|
|
@user_role = user_role
|
|
|
|
end
|
|
|
|
|
|
|
|
def call
|
|
|
|
update_repositories_assignments
|
|
|
|
update_reports_assignments
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def update_repositories_assignments
|
|
|
|
@team.repositories
|
|
|
|
.joins(:automatic_user_assignments)
|
|
|
|
.preload(:automatic_user_assignments)
|
|
|
|
.where(automatic_user_assignments: { user: @user, team: @team })
|
|
|
|
.find_each do |repository|
|
|
|
|
repository.automatic_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
|
|
|
|
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
|