Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-11-11 09:27:43 +0300
committerTimothy Andrew <mail@timothyandrew.net>2017-02-24 14:20:19 +0300
commitff19bbd3b40621ae94632b9aa68fd12645b6ed41 (patch)
tree7c198e54f2f3f6db5a9272bf79425f0b385bc96b /app/services/users
parent29540d6f35da643b4f1894dc5ffd4c0a22f7cd3e (diff)
Deleting a user shouldn't delete associated issues.
- "Associated" issues are issues the user has created + issues that the user is assigned to. - Issues that a user owns are transferred to a "Ghost User" (just a regular user with `state = 'ghost'` that is created when `User.ghost` is called). - Issues that a user is assigned to are moved to the "Unassigned" state. - Fix a spec failure in `profile_spec` — a spec was asserting that when a user is deleted, `User.count` decreases by 1. After this change, deleting a user creates (potentially) a ghost user, causing `User.count` not to change. The spec has been updated to look for the relevant user in the assertion.
Diffstat (limited to 'app/services/users')
-rw-r--r--app/services/users/destroy_service.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/app/services/users/destroy_service.rb b/app/services/users/destroy_service.rb
index bc0653cb634..d88b81c04e2 100644
--- a/app/services/users/destroy_service.rb
+++ b/app/services/users/destroy_service.rb
@@ -26,6 +26,8 @@ module Users
::Projects::DestroyService.new(project, current_user, skip_repo: true).async_execute
end
+ move_issues_to_ghost_user(user)
+
# Destroy the namespace after destroying the user since certain methods may depend on the namespace existing
namespace = user.namespace
user_data = user.destroy
@@ -33,5 +35,17 @@ module Users
user_data
end
+
+ private
+
+ def move_issues_to_ghost_user(user)
+ ghost_user = User.ghost
+
+ Issue.transaction do
+ user.issues.each { |issue| issue.update!(author: ghost_user) }
+ end
+
+ user.reload
+ end
end
end