From 3cccd102ba543e02725d247893729e5c73b38295 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 20 Apr 2022 10:00:54 +0000 Subject: Add latest changes from gitlab-org/gitlab@14-10-stable-ee --- app/services/users/destroy_service.rb | 4 ++++ .../users/migrate_to_ghost_user_service.rb | 4 ++-- app/services/users/registrations_build_service.rb | 2 ++ .../users/saved_replies/destroy_service.rb | 23 ++++++++++++++++++++++ app/services/users/saved_replies/update_service.rb | 5 ++--- 5 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 app/services/users/saved_replies/destroy_service.rb (limited to 'app/services/users') diff --git a/app/services/users/destroy_service.rb b/app/services/users/destroy_service.rb index 46eec082125..1ea65049dc2 100644 --- a/app/services/users/destroy_service.rb +++ b/app/services/users/destroy_service.rb @@ -64,6 +64,10 @@ module Users # This ensures we delete records in batches. user.destroy_dependent_associations_in_batches(exclude: [:snippets]) + if Feature.enabled?(:nullify_in_batches_on_user_deletion, default_enabled: :yaml) + user.nullify_dependent_associations_in_batches + end + # Destroy the namespace after destroying the user since certain methods may depend on the namespace existing user_data = user.destroy namespace.destroy diff --git a/app/services/users/migrate_to_ghost_user_service.rb b/app/services/users/migrate_to_ghost_user_service.rb index 604b83f621f..3eb220c0e40 100644 --- a/app/services/users/migrate_to_ghost_user_service.rb +++ b/app/services/users/migrate_to_ghost_user_service.rb @@ -100,9 +100,9 @@ module Users end # rubocop:disable CodeReuse/ActiveRecord - def batched_migrate(base_scope, column) + def batched_migrate(base_scope, column, batch_size: 50) loop do - update_count = base_scope.where(column => user.id).limit(100).update_all(column => ghost_user.id) + update_count = base_scope.where(column => user.id).limit(batch_size).update_all(column => ghost_user.id) break if update_count == 0 end end diff --git a/app/services/users/registrations_build_service.rb b/app/services/users/registrations_build_service.rb index 2d367e7b185..0065b49cc00 100644 --- a/app/services/users/registrations_build_service.rb +++ b/app/services/users/registrations_build_service.rb @@ -16,3 +16,5 @@ module Users end end end + +Users::RegistrationsBuildService.prepend_mod diff --git a/app/services/users/saved_replies/destroy_service.rb b/app/services/users/saved_replies/destroy_service.rb new file mode 100644 index 00000000000..ac08cddad0c --- /dev/null +++ b/app/services/users/saved_replies/destroy_service.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module Users + module SavedReplies + class DestroyService + def initialize(saved_reply:) + @saved_reply = saved_reply + end + + def execute + if saved_reply.destroy + ServiceResponse.success(payload: { saved_reply: saved_reply }) + else + ServiceResponse.error(message: saved_reply.errors.full_messages) + end + end + + private + + attr_reader :saved_reply + end + end +end diff --git a/app/services/users/saved_replies/update_service.rb b/app/services/users/saved_replies/update_service.rb index ab0a3eaf87d..80d3da8a0a3 100644 --- a/app/services/users/saved_replies/update_service.rb +++ b/app/services/users/saved_replies/update_service.rb @@ -3,8 +3,7 @@ module Users module SavedReplies class UpdateService - def initialize(current_user:, saved_reply:, name:, content:) - @current_user = current_user + def initialize(saved_reply:, name:, content:) @saved_reply = saved_reply @name = name @content = content @@ -20,7 +19,7 @@ module Users private - attr_reader :current_user, :saved_reply, :name, :content + attr_reader :saved_reply, :name, :content end end end -- cgit v1.2.1