Migrate project snippets to the ghost user when the user is deleted

Closes #205772
parent 35b18fe2
Pipeline #133019651 failed with stages
in 36 minutes and 54 seconds
......@@ -101,6 +101,10 @@ class Snippet < ApplicationRecord
where(project_id: nil)
end
def self.only_project_snippets
where.not(project_id: nil)
end
def self.only_include_projects_visible_to(current_user = nil)
levels = Gitlab::VisibilityLevel.levels_for_user(current_user)
......
......@@ -52,6 +52,7 @@ module Users
migrate_notes
migrate_abuse_reports
migrate_award_emoji
migrate_snippets
end
# rubocop: disable CodeReuse/ActiveRecord
......@@ -79,6 +80,10 @@ module Users
def migrate_award_emoji
user.award_emoji.update_all(user_id: ghost_user.id)
end
def migrate_snippets
user.snippets.only_project_snippets.update_all(author_id: ghost_user.id)
end
end
end
......
---
title: Migrate project snippets to the ghost user when the user is deleted
merge_request: 28870
author: George Thomas @thegeorgeous
type: added
......@@ -76,6 +76,12 @@ describe Users::MigrateToGhostUserService do
end
end
end
context 'snippets' do
include_examples "migrating a deleted user's associated records to the ghost user", Snippet do
let(:created_record) { create(:snippet, project: project, author: user) }
end
end
end
context "when record migration fails with a rollback exception" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment