Commit dbb38ee8 authored by Igor Drozdov's avatar Igor Drozdov

Cleanup code related to approvers API update

Since the API endpoints have been deprecated
and removed, we can clean up the code that they
used
parent 7a19c4a6
# 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 ...@@ -5,12 +5,9 @@ module EE
module UpdateService module UpdateService
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
include CleanupApprovers
override :execute override :execute
def execute(merge_request) def execute(merge_request)
unless update_task_event? unless update_task_event?
should_remove_old_approvers = params.delete(:remove_old_approvers)
old_approvers = merge_request.overall_approvers(exclude_code_owners: true) old_approvers = merge_request.overall_approvers(exclude_code_owners: true)
end end
...@@ -18,8 +15,6 @@ module EE ...@@ -18,8 +15,6 @@ module EE
merge_request = super(merge_request) merge_request = super(merge_request)
cleanup_approvers(merge_request, reload: true) if should_remove_old_approvers && merge_request.valid?
merge_request.reset_approval_cache! merge_request.reset_approval_cache!
return merge_request if update_task_event? return merge_request if update_task_event?
......
...@@ -4,7 +4,6 @@ module EE ...@@ -4,7 +4,6 @@ module EE
module Projects module Projects
module UpdateService module UpdateService
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
include CleanupApprovers
PULL_MIRROR_ATTRIBUTES = %i[ PULL_MIRROR_ATTRIBUTES = %i[
mirror mirror
...@@ -19,7 +18,6 @@ module EE ...@@ -19,7 +18,6 @@ module EE
override :execute override :execute
def execute def execute
should_remove_old_approvers = params.delete(:remove_old_approvers)
limit = params.delete(:repository_size_limit) limit = params.delete(:repository_size_limit)
wiki_was_enabled = project.wiki_enabled? wiki_was_enabled = project.wiki_enabled?
...@@ -33,7 +31,6 @@ module EE ...@@ -33,7 +31,6 @@ module EE
end end
if result[:status] == :success if result[:status] == :success
cleanup_approvers(project) if should_remove_old_approvers
refresh_merge_trains(project) refresh_merge_trains(project)
log_audit_events 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