BigW Consortium Gitlab

Move a user's abuse reports to the ghost user

... when the user is destroyed. To clarify, this regards abuse reports that the to-be-deleted user has _reported_.
parent 6a065074
......@@ -11,7 +11,7 @@ module Users::MigrateToGhostUser
def move_associated_records_to_ghost_user(user)
# Block the user before moving records to prevent a data race.
# For example, if the user creates an issue after `move_issues_to_ghost_user`
# For example, if the user creates an issue after `migrate_issues`
# runs and before the user is destroyed, the destroy will fail with
# an exception.
user.block
......@@ -19,9 +19,10 @@ module Users::MigrateToGhostUser
user.transaction do
@ghost_user = User.ghost
move_issues_to_ghost_user(user)
move_merge_requests_to_ghost_user(user)
move_notes_to_ghost_user(user)
migrate_issues(user)
migrate_merge_requests(user)
migrate_notes(user)
migrate_abuse_reports(user)
end
user.reload
......@@ -29,15 +30,19 @@ module Users::MigrateToGhostUser
private
def move_issues_to_ghost_user(user)
def migrate_issues(user)
user.issues.update_all(author_id: ghost_user.id)
end
def move_merge_requests_to_ghost_user(user)
def migrate_merge_requests(user)
user.merge_requests.update_all(author_id: ghost_user.id)
end
def move_notes_to_ghost_user(user)
def migrate_notes(user)
user.notes.update_all(author_id: ghost_user.id)
end
def migrate_abuse_reports(user)
AbuseReport.where(reporter_id: user.id).update_all(reporter_id: ghost_user.id)
end
end
......@@ -162,6 +162,13 @@ describe Users::DestroyService, services: true do
let(:created_record) { create(:note, project: project, author: user) }
end
end
context 'abuse reports' do
include_examples "migrating a deleted user's associated records to the ghost user", AbuseReport, { skip_assignee_specs: true } do
let(:created_record) { create(:abuse_report, reporter: user, user: create(:user)) }
let(:author_method) { :reporter }
end
end
end
end
end
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