diff options
author | Tim Zallmann <tzallmann@gitlab.com> | 2018-08-06 20:32:12 +0300 |
---|---|---|
committer | Tim Zallmann <tzallmann@gitlab.com> | 2018-08-06 20:32:12 +0300 |
commit | d737abc537476bf2b500f550b0c733d22f338cf1 (patch) | |
tree | 4b865101f1e4eab3ceedd75973098de9f18ac4b6 /app/helpers | |
parent | 0ffd79319ffc06f9ab5dcfce4f20a4da2f739577 (diff) | |
parent | ee851e58490004f985f914f3cfa715b03cdf4982 (diff) |
Merge branch 'sh-support-bitbucket-server-import' into 'master'
Add support for Bitbucket Server imports
Closes #25393
See merge request gitlab-org/gitlab-ce!20164
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/namespaces_helper.rb | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb index 9008db1b300..66aaf055cf2 100644 --- a/app/helpers/namespaces_helper.rb +++ b/app/helpers/namespaces_helper.rb @@ -9,13 +9,23 @@ module NamespacesHelper .includes(:route) .order('routes.path') users = [current_user.namespace] + selected_id = selected unless extra_group.nil? || extra_group.is_a?(Group) extra_group = Group.find(extra_group) if Namespace.find(extra_group).kind == 'group' end - if extra_group && extra_group.is_a?(Group) && (!Group.exists?(name: extra_group.name) || Ability.allowed?(current_user, :read_group, extra_group)) - groups |= [extra_group] + if extra_group && extra_group.is_a?(Group) + extra_group = dedup_extra_group(extra_group) + + if Ability.allowed?(current_user, :read_group, extra_group) + # Assign the value to an invalid primary ID so that the select box works + extra_group.id = -1 unless extra_group.persisted? + selected_id = extra_group.id if selected == :extra_group + groups |= [extra_group] + else + selected_id = current_user.namespace.id + end end options = [] @@ -25,11 +35,11 @@ module NamespacesHelper options << options_for_group(users, display_path: display_path, type: 'user') if selected == :current_user && current_user.namespace - selected = current_user.namespace.id + selected_id = current_user.namespace.id end end - grouped_options_for_select(options, selected) + grouped_options_for_select(options, selected_id) end def namespace_icon(namespace, size = 40) @@ -42,6 +52,17 @@ module NamespacesHelper private + # Many importers create a temporary Group, so use the real + # 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) + extra_group = existing_group if existing_group&.persisted? + end + + extra_group + end + def options_for_group(namespaces, display_path:, type:) group_label = type.pluralize elements = namespaces.sort_by(&:human_name).map! do |n| |