From 965f9113b05695236bb682dd7ff7cdb5a5232281 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 31 Aug 2018 14:57:37 -0700 Subject: [PATCH] Fix importers not assigning a new default group The Bitbucket Server as well as other importers pass in a group name to be created (assuming the user has permission) and attempt to dedupe that with an existing group. However, the group *name* is not guaranteed to be unique, but the *path* is. Closes #50110 --- app/helpers/namespaces_helper.rb | 2 +- changelogs/unreleased/sh-fix-dedupe-group-importer.yml | 5 +++++ spec/helpers/namespaces_helper_spec.rb | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/sh-fix-dedupe-group-importer.yml diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb index 30585cb403d..6535afb6425 100644 --- a/app/helpers/namespaces_helper.rb +++ b/app/helpers/namespaces_helper.rb @@ -55,7 +55,7 @@ module NamespacesHelper # group if one exists by that name to prevent duplicates. def dedup_extra_group(extra_group) unless extra_group.persisted? - existing_group = Group.find_by(name: extra_group.name) + existing_group = Group.find_by(path: extra_group.path) extra_group = existing_group if existing_group&.persisted? end diff --git a/changelogs/unreleased/sh-fix-dedupe-group-importer.yml b/changelogs/unreleased/sh-fix-dedupe-group-importer.yml new file mode 100644 index 00000000000..1b874c64718 --- /dev/null +++ b/changelogs/unreleased/sh-fix-dedupe-group-importer.yml @@ -0,0 +1,5 @@ +--- +title: Fix importers not assigning a new default group +merge_request: 21456 +author: +type: fixed diff --git a/spec/helpers/namespaces_helper_spec.rb b/spec/helpers/namespaces_helper_spec.rb index 234690e742b..7ccbdcd1332 100644 --- a/spec/helpers/namespaces_helper_spec.rb +++ b/spec/helpers/namespaces_helper_spec.rb @@ -50,9 +50,12 @@ describe NamespacesHelper do end it 'selects the new group by default' do + # Ensure we don't select a group with the same name + create(:group, name: 'new-group', path: 'another-path') + allow(helper).to receive(:current_user).and_return(user) - options = helper.namespaces_options(:extra_group, display_path: true, extra_group: build(:group, name: 'new-group')) + options = helper.namespaces_options(:extra_group, display_path: true, extra_group: build(:group, name: 'new-group', path: 'new-group')) expect(options).to include(user_group.name) expect(options).not_to include(admin_group.name)