2019-04-11 08:17:24 -04:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2016-03-16 18:44:33 -04:00
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
|
describe Groups::CreateService, '#execute' do
|
2016-12-26 04:56:19 -05:00
|
|
|
|
let!(:user) { create(:user) }
|
2016-03-18 08:28:16 -04:00
|
|
|
|
let!(:group_params) { { path: "group_path", visibility_level: Gitlab::VisibilityLevel::PUBLIC } }
|
2016-03-16 18:44:33 -04:00
|
|
|
|
|
2017-02-03 05:29:56 -05:00
|
|
|
|
subject { service.execute }
|
|
|
|
|
|
2016-12-26 04:56:19 -05:00
|
|
|
|
describe 'visibility level restrictions' do
|
|
|
|
|
let!(:service) { described_class.new(user, group_params) }
|
|
|
|
|
|
2016-03-16 18:44:33 -04:00
|
|
|
|
context "create groups without restricted visibility level" do
|
2016-03-17 18:42:46 -04:00
|
|
|
|
it { is_expected.to be_persisted }
|
2016-03-16 18:44:33 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context "cannot create group with restricted visibility level" do
|
2017-06-14 14:18:56 -04:00
|
|
|
|
before do
|
|
|
|
|
allow_any_instance_of(ApplicationSetting).to receive(:restricted_visibility_levels).and_return([Gitlab::VisibilityLevel::PUBLIC])
|
|
|
|
|
end
|
2016-12-26 04:56:19 -05:00
|
|
|
|
|
2016-05-23 19:37:59 -04:00
|
|
|
|
it { is_expected.not_to be_persisted }
|
2016-03-16 18:44:33 -04:00
|
|
|
|
end
|
|
|
|
|
end
|
2016-12-26 04:56:19 -05:00
|
|
|
|
|
2017-09-07 14:35:45 -04:00
|
|
|
|
describe 'creating a top level group' do
|
|
|
|
|
let(:service) { described_class.new(user, group_params) }
|
|
|
|
|
|
|
|
|
|
context 'when user can create a group' do
|
|
|
|
|
before do
|
|
|
|
|
user.update_attribute(:can_create_group, true)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { is_expected.to be_persisted }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when user can not create a group' do
|
|
|
|
|
before do
|
|
|
|
|
user.update_attribute(:can_create_group, false)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it { is_expected.not_to be_persisted }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-08-22 12:55:49 -04:00
|
|
|
|
describe 'creating subgroup', :nested_groups do
|
2016-12-26 04:56:19 -05:00
|
|
|
|
let!(:group) { create(:group) }
|
|
|
|
|
let!(:service) { described_class.new(user, group_params.merge(parent_id: group.id)) }
|
|
|
|
|
|
|
|
|
|
context 'as group owner' do
|
2017-06-14 14:18:56 -04:00
|
|
|
|
before do
|
|
|
|
|
group.add_owner(user)
|
|
|
|
|
end
|
2016-12-26 04:56:19 -05:00
|
|
|
|
|
|
|
|
|
it { is_expected.to be_persisted }
|
2017-08-09 06:58:00 -04:00
|
|
|
|
|
|
|
|
|
context 'when nested groups feature is disabled' do
|
|
|
|
|
it 'does not save group and returns an error' do
|
2018-12-18 07:15:51 -05:00
|
|
|
|
allow(Group).to receive(:supports_nested_objects?).and_return(false)
|
2017-08-09 06:58:00 -04:00
|
|
|
|
|
|
|
|
|
is_expected.not_to be_persisted
|
|
|
|
|
expect(subject.errors[:parent_id]).to include('You don’t have permission to create a subgroup in this group.')
|
|
|
|
|
expect(subject.parent_id).to be_nil
|
|
|
|
|
end
|
|
|
|
|
end
|
2016-12-26 04:56:19 -05:00
|
|
|
|
end
|
|
|
|
|
|
2017-09-07 14:35:45 -04:00
|
|
|
|
context 'when nested groups feature is enabled' do
|
|
|
|
|
before do
|
2018-12-18 07:15:51 -05:00
|
|
|
|
allow(Group).to receive(:supports_nested_objects?).and_return(true)
|
2017-09-07 14:35:45 -04:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'as guest' do
|
|
|
|
|
it 'does not save group and returns an error' do
|
|
|
|
|
is_expected.not_to be_persisted
|
|
|
|
|
|
|
|
|
|
expect(subject.errors[:parent_id].first).to eq('You don’t have permission to create a subgroup in this group.')
|
|
|
|
|
expect(subject.parent_id).to be_nil
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'as owner' do
|
|
|
|
|
before do
|
|
|
|
|
group.add_owner(user)
|
|
|
|
|
end
|
2017-08-09 06:58:00 -04:00
|
|
|
|
|
2017-09-07 14:35:45 -04:00
|
|
|
|
it { is_expected.to be_persisted }
|
2016-12-26 04:56:19 -05:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2017-02-03 05:29:56 -05:00
|
|
|
|
|
2019-04-12 01:00:50 -04:00
|
|
|
|
describe "when visibility level is passed as a string" do
|
|
|
|
|
let(:service) { described_class.new(user, group_params) }
|
|
|
|
|
let(:group_params) { { path: 'group_path', visibility: 'public' } }
|
|
|
|
|
|
|
|
|
|
it "assigns the correct visibility level" do
|
|
|
|
|
group = service.execute
|
|
|
|
|
|
|
|
|
|
expect(group.visibility_level).to eq(Gitlab::VisibilityLevel::PUBLIC)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-02-03 05:29:56 -05:00
|
|
|
|
describe 'creating a mattermost team' do
|
2017-02-24 07:25:42 -05:00
|
|
|
|
let!(:params) { group_params.merge(create_chat_team: "true") }
|
2017-02-03 05:29:56 -05:00
|
|
|
|
let!(:service) { described_class.new(user, params) }
|
|
|
|
|
|
2017-02-24 07:25:42 -05:00
|
|
|
|
before do
|
2017-03-28 08:12:32 -04:00
|
|
|
|
stub_mattermost_setting(enabled: true)
|
2017-02-24 07:25:42 -05:00
|
|
|
|
end
|
|
|
|
|
|
2017-02-20 07:41:50 -05:00
|
|
|
|
it 'create the chat team with the group' do
|
|
|
|
|
allow_any_instance_of(Mattermost::Team).to receive(:create)
|
|
|
|
|
.and_return({ 'name' => 'tanuki', 'id' => 'lskdjfwlekfjsdifjj' })
|
|
|
|
|
|
|
|
|
|
expect { subject }.to change { ChatTeam.count }.from(0).to(1)
|
|
|
|
|
end
|
2017-02-03 05:29:56 -05:00
|
|
|
|
end
|
2016-03-16 18:44:33 -04:00
|
|
|
|
end
|