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