Commit 987be4a5 authored by Mark Chao's avatar Mark Chao

Merge branch 'id-cleanup-deprecated-code-for-approvers' into 'master'

Cleanup code related to approvers API update

See merge request gitlab-org/gitlab!58057
parents 18ab952d dbb38ee8
# frozen_string_literal: true
# Concern that encapsulates logic to remove all
# approvers in a project that were not added during
# the current transaction
module CleanupApprovers
extend ActiveSupport::Concern
private
# rubocop: disable CodeReuse/ActiveRecord
def cleanup_approvers(target, reload: false)
target.approvers.where.not(user_id: params[:approver_ids]).destroy_all # rubocop: disable Cop/DestroyAll
target.approver_groups.where.not(group_id: params[:approver_group_ids]).destroy_all # rubocop: disable Cop/DestroyAll
# If the target already has `approvers` and/or `approver_groups` loaded then we need to
# force a reload in order to not return stale information after the destroys above
if reload
target.approvers.reset
target.approver_groups.reset
end
target
end
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -5,12 +5,9 @@ module EE
module UpdateService
extend ::Gitlab::Utils::Override
include CleanupApprovers
override :execute
def execute(merge_request)
unless update_task_event?
should_remove_old_approvers = params.delete(:remove_old_approvers)
old_approvers = merge_request.overall_approvers(exclude_code_owners: true)
end
......@@ -18,8 +15,6 @@ module EE
merge_request = super(merge_request)
cleanup_approvers(merge_request, reload: true) if should_remove_old_approvers && merge_request.valid?
merge_request.reset_approval_cache!
return merge_request if update_task_event?
......
......@@ -4,7 +4,6 @@ module EE
module Projects
module UpdateService
extend ::Gitlab::Utils::Override
include CleanupApprovers
PULL_MIRROR_ATTRIBUTES = %i[
mirror
......@@ -19,7 +18,6 @@ module EE
override :execute
def execute
should_remove_old_approvers = params.delete(:remove_old_approvers)
limit = params.delete(:repository_size_limit)
wiki_was_enabled = project.wiki_enabled?
......@@ -33,7 +31,6 @@ module EE
end
if result[:status] == :success
cleanup_approvers(project) if should_remove_old_approvers
refresh_merge_trains(project)
log_audit_events
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment