Commit 1528df0f authored by Stan Hu's avatar Stan Hu

Default to importing to the current project key

parent 852b5613
......@@ -9,6 +9,7 @@ module NamespacesHelper
.includes(:route)
.order('routes.path')
users = [current_user.namespace]
selected_option = nil
unless extra_group.nil? || extra_group.is_a?(Group)
extra_group = Group.find(extra_group) if Namespace.find(extra_group).kind == 'group'
......@@ -18,7 +19,11 @@ module NamespacesHelper
# Avoid duplicate groups if one already exists by that name
existing_group = Group.find_by(name: extra_group.name)
extra_group = existing_group if existing_group
groups |= [extra_group] if Ability.allowed?(current_user, :read_group, extra_group)
if Ability.allowed?(current_user, :read_group, extra_group)
groups |= [extra_group]
selected_option = extra_group.id if selected == :extra_group
end
end
options = []
......@@ -27,12 +32,12 @@ module NamespacesHelper
unless groups_only
options << options_for_group(users, display_path: display_path, type: 'user')
if selected == :current_user && current_user.namespace
selected = current_user.namespace.id
if (selected == :current_user || selected_option.nil?) && current_user.namespace
selected_option = current_user.namespace.id
end
end
grouped_options_for_select(options, selected)
grouped_options_for_select(options, selected_option)
end
def namespace_icon(namespace, size = 40)
......
......@@ -58,7 +58,7 @@
.input-group
.project-path.input-group-prepend
- if current_user.can_select_namespace?
- selected = params[:namespace_id] || :current_user
- selected = params[:namespace_id] || :extra_group
- opts = current_user.can_create_group? ? { extra_group: Group.new(name: repo.project_key, path: repo.project_key) } : {}
= select_tag :namespace_id, namespaces_options(selected, opts.merge({ display_path: true })), { class: 'input-group-text select2 js-select-namespace', tabindex: 1 }
- else
......
......@@ -40,6 +40,25 @@ describe NamespacesHelper do
expect(options).to include(admin_group.name)
end
it 'selects extra_group' do
allow(helper).to receive(:current_user).and_return(admin)
options = helper.namespaces_options(:extra_group, display_path: true, extra_group: user_group)
expect(options).to include("selected=\"selected\" value=\"#{user_group.id}\"")
expect(options).to include(admin_group.name)
end
it 'falls back to current user selection' do
allow(helper).to receive(:current_user).and_return(user)
options = helper.namespaces_options(:extra_group, display_path: true, extra_group: build(:group, name: admin_group.name))
expect(options).to include(user_group.name)
expect(options).not_to include(admin_group.name)
expect(options).to include("selected=\"selected\" value=\"#{user.namespace.id}\"")
end
it 'returns only groups if groups_only option is true' do
allow(helper).to receive(:current_user).and_return(user)
......
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