2016-03-01 10:22:29 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe GroupsFinder do
|
|
|
|
describe '#execute' do
|
2016-03-18 08:28:16 -04:00
|
|
|
let(:user) { create(:user) }
|
2016-03-01 10:22:29 -05:00
|
|
|
|
2017-05-03 19:51:25 -04:00
|
|
|
context 'root level groups' do
|
|
|
|
let!(:private_group) { create(:group, :private) }
|
|
|
|
let!(:internal_group) { create(:group, :internal) }
|
|
|
|
let!(:public_group) { create(:group, :public) }
|
|
|
|
|
|
|
|
context 'without a user' do
|
|
|
|
subject { described_class.new.execute }
|
2016-03-01 10:22:29 -05:00
|
|
|
|
|
|
|
it { is_expected.to eq([public_group]) }
|
|
|
|
end
|
|
|
|
|
2017-05-03 19:51:25 -04:00
|
|
|
context 'with a user' do
|
|
|
|
subject { described_class.new(user).execute }
|
2016-03-01 10:22:29 -05:00
|
|
|
|
2016-03-17 18:42:46 -04:00
|
|
|
context 'normal user' do
|
2017-05-03 19:51:25 -04:00
|
|
|
it { is_expected.to contain_exactly(public_group, internal_group) }
|
2016-03-17 18:42:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'external user' do
|
2016-03-18 08:28:16 -04:00
|
|
|
let(:user) { create(:user, external: true) }
|
|
|
|
|
2017-05-03 19:51:25 -04:00
|
|
|
it { is_expected.to contain_exactly(public_group) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'user is member of the private group' do
|
|
|
|
before do
|
|
|
|
private_group.add_guest(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(public_group, internal_group, private_group) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-13 03:11:33 -04:00
|
|
|
context 'subgroups', :nested_groups do
|
2017-05-03 19:51:25 -04:00
|
|
|
let!(:parent_group) { create(:group, :public) }
|
|
|
|
let!(:public_subgroup) { create(:group, :public, parent: parent_group) }
|
|
|
|
let!(:internal_subgroup) { create(:group, :internal, parent: parent_group) }
|
|
|
|
let!(:private_subgroup) { create(:group, :private, parent: parent_group) }
|
|
|
|
|
|
|
|
context 'without a user' do
|
2017-06-14 15:37:29 -04:00
|
|
|
it 'only returns parent and public subgroups' do
|
|
|
|
expect(described_class.new(nil).execute).to contain_exactly(parent_group, public_subgroup)
|
2017-05-03 19:51:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a user' do
|
2017-06-14 15:37:29 -04:00
|
|
|
subject { described_class.new(user).execute }
|
2017-06-13 03:11:33 -04:00
|
|
|
|
2017-06-14 15:37:29 -04:00
|
|
|
it 'returns parent, public, and internal subgroups' do
|
|
|
|
is_expected.to contain_exactly(parent_group, public_subgroup, internal_subgroup)
|
2017-05-03 19:51:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'being member' do
|
2017-06-14 15:37:29 -04:00
|
|
|
it 'returns parent, public subgroups, internal subgroups, and private subgroups user is member of' do
|
2017-05-03 19:51:25 -04:00
|
|
|
private_subgroup.add_guest(user)
|
|
|
|
|
2017-06-14 15:37:29 -04:00
|
|
|
is_expected.to contain_exactly(parent_group, public_subgroup, internal_subgroup, private_subgroup)
|
2017-06-13 03:11:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'parent group private' do
|
|
|
|
before do
|
|
|
|
parent_group.update_attribute(:visibility_level, Gitlab::VisibilityLevel::PRIVATE)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'being member of parent group' do
|
|
|
|
it 'returns all subgroups' do
|
|
|
|
parent_group.add_guest(user)
|
|
|
|
|
2017-06-14 15:37:29 -04:00
|
|
|
is_expected.to contain_exactly(parent_group, public_subgroup, internal_subgroup, private_subgroup)
|
2017-06-13 03:11:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'authorized to private project' do
|
2017-06-14 15:37:29 -04:00
|
|
|
context 'project one level deep' do
|
|
|
|
let!(:subproject) { create(:empty_project, :private, namespace: private_subgroup) }
|
|
|
|
before do
|
|
|
|
subproject.add_guest(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'includes the subgroup of the project' do
|
|
|
|
is_expected.to include(private_subgroup)
|
|
|
|
end
|
2017-06-13 03:11:33 -04:00
|
|
|
|
2017-06-14 15:37:29 -04:00
|
|
|
it 'does not include private subgroups deeper down' do
|
|
|
|
subsubgroup = create(:group, :private, parent: private_subgroup)
|
|
|
|
|
|
|
|
is_expected.not_to include(subsubgroup)
|
|
|
|
end
|
2017-06-13 03:11:33 -04:00
|
|
|
end
|
|
|
|
|
2017-06-14 15:37:29 -04:00
|
|
|
context 'project two levels deep' do
|
|
|
|
let!(:private_subsubgroup) { create(:group, :private, parent: private_subgroup) }
|
|
|
|
let!(:subsubproject) { create(:empty_project, :private, namespace: private_subsubgroup) }
|
|
|
|
before do
|
|
|
|
subsubproject.add_guest(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns all the ancestor groups' do
|
|
|
|
is_expected.to include(private_subsubgroup, private_subgroup, parent_group)
|
|
|
|
end
|
2017-06-13 03:11:33 -04:00
|
|
|
|
2017-06-14 15:37:29 -04:00
|
|
|
it 'returns the groups for a given parent' do
|
|
|
|
expect(described_class.new(user, parent: parent_group).execute).to include(private_subgroup)
|
|
|
|
end
|
2017-06-13 03:11:33 -04:00
|
|
|
end
|
2017-05-03 19:51:25 -04:00
|
|
|
end
|
2016-03-17 18:42:46 -04:00
|
|
|
end
|
2016-03-01 10:22:29 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|