Commit aaf1e00b authored by Mark Chao's avatar Mark Chao

Fix duplicated approvers scenario

Prevents duplicated record.
parent 6864c1f2
......@@ -92,7 +92,7 @@ module EE
rule = approval_rules.code_owner.first
rule ||= approval_rules.code_owner.create!(name: ApprovalMergeRequestRule::DEFAULT_NAME_FOR_CODE_OWNER)
rule.users = code_owners
rule.users = code_owners.uniq
end
else
approval_rules.code_owner.delete_all
......
......@@ -56,11 +56,11 @@ module Gitlab
has_many :approval_rules, class_name: 'ApprovalMergeRequestRule'
def approver_ids
@approver_ids ||= Approver.where(target_type: 'MergeRequest', target_id: id).pluck(:user_id)
@approver_ids ||= Approver.where(target_type: 'MergeRequest', target_id: id).pluck('distinct user_id')
end
def approver_group_ids
@approver_group_ids ||= ApproverGroup.where(target_type: 'MergeRequest', target_id: id).pluck(:group_id)
@approver_group_ids ||= ApproverGroup.where(target_type: 'MergeRequest', target_id: id).pluck('distinct group_id')
end
def sync_code_owners_with_approvers
......@@ -78,11 +78,11 @@ module Gitlab
has_many :approval_rules, class_name: 'ApprovalProjectRule'
def approver_ids
@approver_ids ||= Approver.where(target_type: 'Project', target_id: id).pluck(:user_id)
@approver_ids ||= Approver.where(target_type: 'Project', target_id: id).pluck('distinct user_id')
end
def approver_group_ids
@approver_group_ids ||= ApproverGroup.where(target_type: 'Project', target_id: id).pluck(:group_id)
@approver_group_ids ||= ApproverGroup.where(target_type: 'Project', target_id: id).pluck('distinct group_id')
end
end
......
......@@ -86,8 +86,10 @@ describe Gitlab::BackgroundMigration::MigrateApproverToApprovalRules do
context 'when project rule is present' do
let!(:project_rule) { create(:approval_project_rule, project: target.target_project) }
it "sets MR rule's source to project rule" do
create_member_in(create(:user), :old_schema)
it "sets MR rule's source to project rule without duplication" do
user = create(:user)
create_member_in(user, :old_schema)
create_member_in(user, :old_schema)
described_class.new.perform(target_type, target.id)
......
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