Commit 237a3597 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

More reliable manifest parser and group-only selector

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 1885a301
...@@ -3,7 +3,7 @@ module NamespacesHelper ...@@ -3,7 +3,7 @@ module NamespacesHelper
params.dig(:project, :namespace_id) || params[:namespace_id] params.dig(:project, :namespace_id) || params[:namespace_id]
end end
def namespaces_options(selected = :current_user, display_path: false, extra_group: nil) def namespaces_options(selected = :current_user, display_path: false, extra_group: nil, groups_only: false)
groups = current_user.manageable_groups groups = current_user.manageable_groups
.joins(:route) .joins(:route)
.includes(:route) .includes(:route)
...@@ -20,10 +20,13 @@ module NamespacesHelper ...@@ -20,10 +20,13 @@ module NamespacesHelper
options = [] options = []
options << options_for_group(groups, display_path: display_path, type: 'group') options << options_for_group(groups, display_path: display_path, type: 'group')
options << options_for_group(users, display_path: display_path, type: 'user')
if selected == :current_user && current_user.namespace unless groups_only
selected = current_user.namespace.id options << options_for_group(users, display_path: display_path, type: 'user')
if selected == :current_user && current_user.namespace
selected = current_user.namespace.id
end
end end
grouped_options_for_select(options, selected) grouped_options_for_select(options, selected)
......
= form_tag upload_import_manifest_path, multipart: true do = form_tag upload_import_manifest_path, multipart: true do
.form-group .form-group
= label_tag :manifest, class: 'label-light' do = label_tag :manifest, class: 'label-light' do
Manifest = _('Manifest')
= file_field_tag :manifest, class: 'form-control-file', required: true = file_field_tag :manifest, class: 'form-control-file', required: true
.form-text.text-muted .form-text.text-muted
Import multiple repositories by uploading a manifest file. = _('Import multiple repositories by uploading a manifest file.')
.form-group .form-group
= label_tag :group_id, nil, class: 'label-light' do = label_tag :group_id, nil, class: 'label-light' do
Namespace = _('Group')
.input-group .input-group
.input-group-prepend.has-tooltip{ title: root_url } .input-group-prepend.has-tooltip{ title: root_url }
.input-group-text .input-group-text
= root_url = root_url
= select_tag :group_id, namespaces_options(nil, display_path: true), { class: 'select2 js-select-namespace' } = select_tag :group_id, namespaces_options(nil, display_path: true, groups_only: true), { class: 'select2 js-select-namespace' }
.form-text.text-muted .form-text.text-muted
Choose the top-level namespace for your repository imports. = _('Choose the top-level group for your repository imports.')
.append-bottom-10 .append-bottom-10
= submit_tag 'Import projects', class: 'btn btn-success' = submit_tag 'Import projects', class: 'btn btn-success'
......
...@@ -66,7 +66,10 @@ module Gitlab ...@@ -66,7 +66,10 @@ module Gitlab
end end
def remote def remote
@remote ||= parsed_xml.css('manifest > remote').first['review'] return @remote if defined?(@remote)
remote_tag = parsed_xml.css('manifest > remote').first
@remote = remote_tag['review'] if remote_tag
end end
def raw_projects def raw_projects
......
...@@ -28,6 +28,16 @@ describe NamespacesHelper do ...@@ -28,6 +28,16 @@ describe NamespacesHelper do
expect(options).not_to include(admin_group.name) expect(options).not_to include(admin_group.name)
expect(options).to include(user_group.name) expect(options).to include(user_group.name)
expect(options).to include(user.name)
end
it 'returns only groups if groups_only option is true' do
allow(helper).to receive(:current_user).and_return(user)
options = helper.namespaces_options(nil, groups_only: true)
expect(options).not_to include(user.name)
expect(options).to include(user_group.name)
end end
context 'when nested groups are available', :nested_groups do context 'when nested groups are available', :nested_groups do
......
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