From 94b5b4a425792af8252f9c6fb71fdd039966749e Mon Sep 17 00:00:00 2001 From: Alex Kriuchykhin Date: Mon, 20 Feb 2023 13:00:13 +0100 Subject: [PATCH] Add rake task for resseting user assignments on inventories (#4931) --- lib/tasks/data.rake | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/tasks/data.rake b/lib/tasks/data.rake index f075ff335..98d3a9450 100644 --- a/lib/tasks/data.rake +++ b/lib/tasks/data.rake @@ -176,4 +176,22 @@ namespace :data do end end end + + desc 'Reset repositories user assignments' + task reset_repositories_user_assignments: :environment do + ActiveRecord::Base.transaction do + Team.all.find_each do |team| + team.user_assignments.find_each do |team_user_assignment| + team.repositories.find_each do |repository| + new_user_assignment = + repository.automatic_user_assignments.find_or_initialize_by(user: team_user_assignment.user, team: team) + new_user_assignment.user_role = team_user_assignment.user_role + new_user_assignment.assigned_by = team_user_assignment.assigned_by + new_user_assignment.assigned = :automatically + new_user_assignment.save! + end + end + end + end + end end