diff options
-rw-r--r-- | app/services/concerns/users/migrate_to_ghost_user.rb | 19 | ||||
-rw-r--r-- | spec/services/users/destroy_service_spec.rb | 7 |
2 files changed, 19 insertions, 7 deletions
diff --git a/app/services/concerns/users/migrate_to_ghost_user.rb b/app/services/concerns/users/migrate_to_ghost_user.rb index 0779d12cd3a..5d1f0ff57d1 100644 --- a/app/services/concerns/users/migrate_to_ghost_user.rb +++ b/app/services/concerns/users/migrate_to_ghost_user.rb @@ -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 diff --git a/spec/services/users/destroy_service_spec.rb b/spec/services/users/destroy_service_spec.rb index 3efa7c196dc..028de62e4ca 100644 --- a/spec/services/users/destroy_service_spec.rb +++ b/spec/services/users/destroy_service_spec.rb @@ -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 |