2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-14 13:11:55 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-03 18:08:28 +00:00
|
|
|
RSpec.describe 'Admin Groups' do
|
2016-12-26 19:36:33 +00:00
|
|
|
include Select2Helper
|
|
|
|
|
2016-11-14 13:11:55 +00:00
|
|
|
let(:internal) { Gitlab::VisibilityLevel::INTERNAL }
|
2016-12-26 19:36:33 +00:00
|
|
|
let(:user) { create :user }
|
|
|
|
let!(:group) { create :group }
|
2017-06-21 23:44:10 +00:00
|
|
|
let!(:current_user) { create(:admin) }
|
2016-11-14 13:11:55 +00:00
|
|
|
|
|
|
|
before do
|
2017-06-21 23:44:10 +00:00
|
|
|
sign_in(current_user)
|
2016-11-14 13:11:55 +00:00
|
|
|
stub_application_setting(default_group_visibility: internal)
|
|
|
|
end
|
|
|
|
|
2016-12-26 19:36:33 +00:00
|
|
|
describe 'list' do
|
|
|
|
it 'renders groups' do
|
|
|
|
visit admin_groups_path
|
|
|
|
|
|
|
|
expect(page).to have_content(group.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-14 13:11:55 +00:00
|
|
|
describe 'create a group' do
|
2016-12-26 19:36:33 +00:00
|
|
|
it 'creates new group' do
|
|
|
|
visit admin_groups_path
|
|
|
|
|
2017-05-31 15:23:48 +00:00
|
|
|
page.within '#content-body' do
|
|
|
|
click_link "New group"
|
|
|
|
end
|
2017-03-12 15:22:00 +00:00
|
|
|
path_component = 'gitlab'
|
|
|
|
group_name = 'GitLab group name'
|
|
|
|
group_description = 'Description of group for GitLab'
|
2018-06-22 15:06:00 +00:00
|
|
|
|
2017-03-12 15:22:00 +00:00
|
|
|
fill_in 'group_path', with: path_component
|
|
|
|
fill_in 'group_name', with: group_name
|
|
|
|
fill_in 'group_description', with: group_description
|
2016-12-26 19:36:33 +00:00
|
|
|
click_button "Create group"
|
|
|
|
|
2017-03-12 15:22:00 +00:00
|
|
|
expect(current_path).to eq admin_group_path(Group.find_by(path: path_component))
|
|
|
|
content = page.find('div#content-body')
|
|
|
|
h3_texts = content.all('h3').collect(&:text).join("\n")
|
|
|
|
expect(h3_texts).to match group_name
|
|
|
|
li_texts = content.all('li').collect(&:text).join("\n")
|
|
|
|
expect(li_texts).to match group_name
|
|
|
|
expect(li_texts).to match path_component
|
|
|
|
expect(li_texts).to match group_description
|
2016-12-26 19:36:33 +00:00
|
|
|
end
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'shows the visibility level radio populated with the default value' do
|
2016-11-14 13:11:55 +00:00
|
|
|
visit new_admin_group_path
|
|
|
|
|
|
|
|
expect_selected_visibility(internal)
|
|
|
|
end
|
2017-03-12 15:22:00 +00:00
|
|
|
|
2018-10-30 16:23:47 +00:00
|
|
|
it 'when entered in group name, it auto filled the group path', :js do
|
2017-03-12 15:22:00 +00:00
|
|
|
visit admin_groups_path
|
|
|
|
click_link "New group"
|
2018-10-30 16:23:47 +00:00
|
|
|
group_name = 'gitlab'
|
|
|
|
fill_in 'group_name', with: group_name
|
|
|
|
path_field = find('input#group_path')
|
|
|
|
expect(path_field.value).to eq group_name
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'auto populates the group path with the group name', :js do
|
|
|
|
visit admin_groups_path
|
|
|
|
click_link "New group"
|
|
|
|
group_name = 'my gitlab project'
|
|
|
|
fill_in 'group_name', with: group_name
|
|
|
|
path_field = find('input#group_path')
|
|
|
|
expect(path_field.value).to eq 'my-gitlab-project'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'when entering in group path, group name does not change anymore', :js do
|
|
|
|
visit admin_groups_path
|
|
|
|
click_link "New group"
|
|
|
|
group_path = 'my-gitlab-project'
|
|
|
|
group_name = 'My modified gitlab project'
|
2017-03-12 15:22:00 +00:00
|
|
|
fill_in 'group_path', with: group_path
|
2018-10-30 16:23:47 +00:00
|
|
|
fill_in 'group_name', with: group_name
|
|
|
|
path_field = find('input#group_path')
|
|
|
|
expect(path_field.value).to eq 'my-gitlab-project'
|
2017-03-12 15:22:00 +00:00
|
|
|
end
|
2016-11-14 13:11:55 +00:00
|
|
|
end
|
|
|
|
|
2016-12-28 11:10:34 +00:00
|
|
|
describe 'show a group' do
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'shows the group' do
|
2016-12-28 11:10:34 +00:00
|
|
|
group = create(:group, :private)
|
|
|
|
|
|
|
|
visit admin_group_path(group)
|
|
|
|
|
|
|
|
expect(page).to have_content("Group: #{group.name}")
|
2019-07-22 12:52:30 +00:00
|
|
|
expect(page).to have_content("ID: #{group.id}")
|
2016-12-28 11:10:34 +00:00
|
|
|
end
|
2019-12-14 00:08:27 +00:00
|
|
|
|
|
|
|
it 'has a link to the group' do
|
|
|
|
group = create(:group, :private)
|
|
|
|
|
|
|
|
visit admin_group_path(group)
|
|
|
|
|
|
|
|
expect(page).to have_link(group.name, href: group_path(group))
|
|
|
|
end
|
2016-12-28 11:10:34 +00:00
|
|
|
end
|
|
|
|
|
2016-11-14 13:11:55 +00:00
|
|
|
describe 'group edit' do
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'shows the visibility level radio populated with the group visibility_level value' do
|
2016-11-14 13:11:55 +00:00
|
|
|
group = create(:group, :private)
|
|
|
|
|
2016-12-08 18:59:41 +00:00
|
|
|
visit admin_group_edit_path(group)
|
2016-11-14 13:11:55 +00:00
|
|
|
|
|
|
|
expect_selected_visibility(group.visibility_level)
|
|
|
|
end
|
2017-03-12 15:22:00 +00:00
|
|
|
|
2019-07-01 20:41:32 +00:00
|
|
|
it 'shows the subgroup creation level dropdown populated with the group subgroup_creation_level value' do
|
|
|
|
group = create(:group, :private, :owner_subgroup_creation_only)
|
|
|
|
|
|
|
|
visit admin_group_edit_path(group)
|
|
|
|
|
2019-07-02 15:38:38 +00:00
|
|
|
expect(page).to have_content('Allowed to create subgroups')
|
2019-07-01 20:41:32 +00:00
|
|
|
end
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'edit group path does not change group name', :js do
|
2017-03-12 15:22:00 +00:00
|
|
|
group = create(:group, :private)
|
|
|
|
|
|
|
|
visit admin_group_edit_path(group)
|
|
|
|
name_field = find('input#group_name')
|
|
|
|
original_name = name_field.value
|
|
|
|
fill_in 'group_path', with: 'this-new-path'
|
|
|
|
|
|
|
|
expect(name_field.value).to eq original_name
|
|
|
|
end
|
2016-11-14 13:11:55 +00:00
|
|
|
end
|
|
|
|
|
2017-10-03 08:35:01 +00:00
|
|
|
describe 'add user into a group', :js do
|
2020-01-27 21:08:47 +00:00
|
|
|
shared_examples 'adds user into a group' do
|
2016-12-26 19:36:33 +00:00
|
|
|
it do
|
|
|
|
visit admin_group_path(group)
|
|
|
|
|
|
|
|
select2(user_selector, from: '#user_ids', multiple: true)
|
|
|
|
page.within '#new_project_member' do
|
|
|
|
select2(Gitlab::Access::REPORTER, from: '#access_level')
|
|
|
|
end
|
|
|
|
click_button "Add users to group"
|
|
|
|
page.within ".group-users-list" do
|
|
|
|
expect(page).to have_content(user.name)
|
|
|
|
expect(page).to have_content('Reporter')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'adds user into a group' do
|
|
|
|
let(:user_selector) { user.id }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'adds user into a group' do
|
|
|
|
let(:user_selector) { user.email }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'add admin himself to a group' do
|
|
|
|
before do
|
|
|
|
group.add_user(:user, Gitlab::Access::OWNER)
|
|
|
|
end
|
|
|
|
|
2017-10-03 08:35:01 +00:00
|
|
|
it 'adds admin a to a group as developer', :js do
|
2016-12-26 19:36:33 +00:00
|
|
|
visit group_group_members_path(group)
|
|
|
|
|
2020-01-13 15:07:53 +00:00
|
|
|
page.within '.invite-users-form' do
|
2016-12-26 19:36:33 +00:00
|
|
|
select2(current_user.id, from: '#user_ids', multiple: true)
|
|
|
|
select 'Developer', from: 'access_level'
|
|
|
|
end
|
|
|
|
|
2020-01-13 15:07:53 +00:00
|
|
|
click_button 'Invite'
|
2016-12-26 19:36:33 +00:00
|
|
|
|
2020-01-13 15:07:53 +00:00
|
|
|
page.within '[data-qa-selector="members_list"]' do
|
2016-12-26 19:36:33 +00:00
|
|
|
expect(page).to have_content(current_user.name)
|
|
|
|
expect(page).to have_content('Developer')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-15 18:08:43 +00:00
|
|
|
describe 'admin remove themself from a group', :js, quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/222342' do
|
2016-12-26 19:36:33 +00:00
|
|
|
it 'removes admin from the group' do
|
|
|
|
group.add_user(current_user, Gitlab::Access::DEVELOPER)
|
|
|
|
|
|
|
|
visit group_group_members_path(group)
|
|
|
|
|
2020-01-13 15:07:53 +00:00
|
|
|
page.within '[data-qa-selector="members_list"]' do
|
2016-12-26 19:36:33 +00:00
|
|
|
expect(page).to have_content(current_user.name)
|
|
|
|
expect(page).to have_content('Developer')
|
|
|
|
end
|
|
|
|
|
2017-09-27 11:36:05 +00:00
|
|
|
accept_confirm { find(:css, 'li', text: current_user.name).find(:css, 'a.btn-remove').click }
|
2016-12-26 19:36:33 +00:00
|
|
|
|
|
|
|
visit group_group_members_path(group)
|
|
|
|
|
2020-01-13 15:07:53 +00:00
|
|
|
page.within '[data-qa-selector="members_list"]' do
|
2016-12-26 19:36:33 +00:00
|
|
|
expect(page).not_to have_content(current_user.name)
|
|
|
|
expect(page).not_to have_content('Developer')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'shared projects' do
|
|
|
|
it 'renders shared project' do
|
2017-08-02 19:55:11 +00:00
|
|
|
empty_project = create(:project)
|
2016-12-26 19:36:33 +00:00
|
|
|
empty_project.project_group_links.create!(
|
2018-07-11 14:36:08 +00:00
|
|
|
group_access: Gitlab::Access::MAINTAINER,
|
2016-12-26 19:36:33 +00:00
|
|
|
group: group
|
|
|
|
)
|
|
|
|
|
|
|
|
visit admin_group_path(group)
|
|
|
|
|
2018-03-05 14:15:26 +00:00
|
|
|
expect(page).to have_content(empty_project.full_name)
|
2016-12-26 19:36:33 +00:00
|
|
|
expect(page).to have_content('Projects shared with')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-14 13:11:55 +00:00
|
|
|
def expect_selected_visibility(level)
|
|
|
|
selector = "#group_visibility_level_#{level}[checked=checked]"
|
|
|
|
|
|
|
|
expect(page).to have_selector(selector, count: 1)
|
|
|
|
end
|
|
|
|
end
|