diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-14 22:45:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-14 22:45:29 +0300 |
commit | b9fe665d2539f53fb86771383e18f9045db52414 (patch) | |
tree | 7e55fcd9b4dc27f3cb13651ce1c03146c592e483 /app/services | |
parent | dd22031c62b54a03909b7be829f85032e556a031 (diff) |
Add latest changes from gitlab-org/gitlab@14-8-stable-ee
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/users/destroy_service.rb | 2 | ||||
-rw-r--r-- | app/services/users/migrate_to_ghost_user_service.rb | 13 |
2 files changed, 12 insertions, 3 deletions
diff --git a/app/services/users/destroy_service.rb b/app/services/users/destroy_service.rb index 4ec875098fa..46eec082125 100644 --- a/app/services/users/destroy_service.rb +++ b/app/services/users/destroy_service.rb @@ -54,7 +54,7 @@ module Users yield(user) if block_given? - MigrateToGhostUserService.new(user).execute unless options[:hard_delete] + MigrateToGhostUserService.new(user).execute(hard_delete: options[:hard_delete]) response = Snippets::BulkDestroyService.new(current_user, user.snippets).execute(options) raise DestroyError, response.message if response.error? diff --git a/app/services/users/migrate_to_ghost_user_service.rb b/app/services/users/migrate_to_ghost_user_service.rb index 515d7821416..575614e8743 100644 --- a/app/services/users/migrate_to_ghost_user_service.rb +++ b/app/services/users/migrate_to_ghost_user_service.rb @@ -10,14 +10,21 @@ module Users class MigrateToGhostUserService extend ActiveSupport::Concern - attr_reader :ghost_user, :user + attr_reader :ghost_user, :user, :hard_delete def initialize(user) @user = user @ghost_user = User.ghost end - def execute + # If an admin attempts to hard delete a user, in some cases associated + # records may have a NOT NULL constraint on the user ID that prevent that record + # from being destroyed. In such situations we must assign the record to the ghost user. + # Passing in `hard_delete: true` will ensure these records get assigned to + # the ghost user before the user is destroyed. Other associated records will be destroyed. + # letting the other associated records be destroyed. + def execute(hard_delete: false) + @hard_delete = hard_delete transition = user.block_transition # Block the user before moving records to prevent a data race. @@ -46,6 +53,8 @@ module Users private def migrate_records + return if hard_delete + migrate_issues migrate_merge_requests migrate_notes |