Resolve "Gitlab administrator cannot create projects in every group"

This commit is contained in:
George Andrinopoulos 2017-03-24 18:19:50 +00:00 committed by Rémy Coutable
parent c0ce9d0157
commit 2f9d50b72f
4 changed files with 45 additions and 2 deletions

View file

@ -6,7 +6,13 @@ module NamespacesHelper
def namespaces_options(selected = :current_user, display_path: false, extra_group: nil)
groups = current_user.owned_groups + current_user.masters_groups
groups << extra_group if extra_group && !Group.exists?(name: extra_group.name)
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]
end
users = [current_user.namespace]

View file

@ -23,7 +23,7 @@
- if current_user.can_select_namespace?
.input-group-addon
= root_url
= f.select :namespace_id, namespaces_options(namespace_id_from(params) || :current_user, display_path: true), {}, {class: 'select2 js-select-namespace', tabindex: 1}
= f.select :namespace_id, namespaces_options(namespace_id_from(params) || :current_user, display_path: true, extra_group: namespace_id_from(params)), {}, { class: 'select2 js-select-namespace', tabindex: 1}
- else
.input-group-addon.static-namespace

View file

@ -0,0 +1,4 @@
---
title: Allow admin to view all namespaces
merge_request:
author: George Andrinopoulos

View file

@ -0,0 +1,33 @@
require 'spec_helper'
describe NamespacesHelper, type: :helper do
let!(:admin) { create(:admin) }
let!(:admin_group) { create(:group, :private) }
let!(:user) { create(:user) }
let!(:user_group) { create(:group, :private) }
before do
admin_group.add_owner(admin)
user_group.add_owner(user)
end
describe '#namespaces_options' do
it 'returns groups without being a member for admin' do
allow(helper).to receive(:current_user).and_return(admin)
options = helper.namespaces_options(user_group.id, display_path: true, extra_group: user_group.id)
expect(options).to include(admin_group.name)
expect(options).to include(user_group.name)
end
it 'returns only allowed namespaces for user' do
allow(helper).to receive(:current_user).and_return(user)
options = helper.namespaces_options
expect(options).not_to include(admin_group.name)
expect(options).to include(user_group.name)
end
end
end