From 72580f07af5a2c1e4df6bbc339ad804b5f5bb9ed Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Wed, 5 Apr 2017 12:50:53 +0530 Subject: Move a user's merge requests to the ghost user. 1. When the user is deleted. 2. Refactor out code relating to "migrating records to the ghost user" into a `MigrateToGhostUser` concern, which is tested using a shared example. --- app/services/users/destroy_service.rb | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) (limited to 'app/services/users/destroy_service.rb') diff --git a/app/services/users/destroy_service.rb b/app/services/users/destroy_service.rb index a3b32a71a64..e6608e316dc 100644 --- a/app/services/users/destroy_service.rb +++ b/app/services/users/destroy_service.rb @@ -1,5 +1,7 @@ module Users class DestroyService + include MigrateToGhostUser + attr_accessor :current_user def initialize(current_user) @@ -26,7 +28,7 @@ module Users ::Projects::DestroyService.new(project, current_user, skip_repo: true).execute end - move_issues_to_ghost_user(user) + move_associated_records_to_ghost_user(user) # Destroy the namespace after destroying the user since certain methods may depend on the namespace existing namespace = user.namespace @@ -35,22 +37,5 @@ module Users user_data end - - private - - def move_issues_to_ghost_user(user) - # Block the user before moving issues to prevent a data race. - # If the user creates an issue after `move_issues_to_ghost_user` - # runs and before the user is destroyed, the destroy will fail with - # an exception. We block the user so that issues can't be created - # after `move_issues_to_ghost_user` runs and before the destroy happens. - user.block - - ghost_user = User.ghost - - user.issues.update_all(author_id: ghost_user.id) - - user.reload - end end end -- cgit v1.2.1 From 1c42505b026d922df50c59d5f9e85073b5f5345f Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Thu, 6 Apr 2017 22:33:07 +0530 Subject: Implement review comments from @DouweM for !10467. 1. Have `MigrateToGhostUser` be a service rather than a mixed-in module, to keep things explicit. Specs testing the behavior of this class are moved into a separate service spec file. 2. Add a `user.reported_abuse_reports` association to make the `migrate_abuse_reports` method more consistent with the other `migrate_` methods. --- app/services/users/destroy_service.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'app/services/users/destroy_service.rb') diff --git a/app/services/users/destroy_service.rb b/app/services/users/destroy_service.rb index e6608e316dc..ba58b174cc0 100644 --- a/app/services/users/destroy_service.rb +++ b/app/services/users/destroy_service.rb @@ -1,7 +1,5 @@ module Users class DestroyService - include MigrateToGhostUser - attr_accessor :current_user def initialize(current_user) @@ -28,7 +26,7 @@ module Users ::Projects::DestroyService.new(project, current_user, skip_repo: true).execute end - move_associated_records_to_ghost_user(user) + MigrateToGhostUserService.new(user).execute # Destroy the namespace after destroying the user since certain methods may depend on the namespace existing namespace = user.namespace -- cgit v1.2.1