2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe 'Admin Groups', feature_category: :subgroups do
|
2021-01-29 00:20:46 +05:30
|
|
|
include Spec::Support::Helpers::Features::MembersHelpers
|
2021-06-08 01:23:25 +05:30
|
|
|
include Spec::Support::Helpers::Features::InviteMembersModalHelper
|
2022-04-04 11:22:00 +05:30
|
|
|
include Spec::Support::Helpers::ModalHelpers
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
let(:internal) { Gitlab::VisibilityLevel::INTERNAL }
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
let_it_be(:user) { create :user }
|
|
|
|
let_it_be(:group) { create :group }
|
2022-08-13 15:12:31 +05:30
|
|
|
let_it_be_with_reload(:current_user) { create(:admin) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
before do
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(current_user)
|
2021-02-22 17:27:13 +05:30
|
|
|
gitlab_enable_admin_mode_sign_in(current_user)
|
2017-08-17 22:00:37 +05:30
|
|
|
stub_application_setting(default_group_visibility: internal)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'list' do
|
|
|
|
it 'renders groups' do
|
|
|
|
visit admin_groups_path
|
|
|
|
|
|
|
|
expect(page).to have_content(group.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
describe 'create a group', :js do
|
2021-02-22 17:27:13 +05:30
|
|
|
describe 'with expected fields' do
|
|
|
|
it 'renders from as expected', :aggregate_failures do
|
|
|
|
visit new_admin_group_path
|
|
|
|
|
|
|
|
expect(page).to have_field('name')
|
|
|
|
expect(page).to have_field('group_path')
|
|
|
|
expect(page).to have_field('group_visibility_level_0')
|
|
|
|
expect(page).to have_field('description')
|
2021-04-29 21:17:54 +05:30
|
|
|
expect(page).to have_field('group_admin_note_attributes_note')
|
2021-02-22 17:27:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'creates new group' do
|
|
|
|
visit admin_groups_path
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
page.within '#content-body' do
|
|
|
|
click_link "New group"
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
path_component = 'gitlab'
|
|
|
|
group_name = 'GitLab group name'
|
|
|
|
group_description = 'Description of group for GitLab'
|
2021-04-29 21:17:54 +05:30
|
|
|
group_admin_note = 'A note about this group by an admin'
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
fill_in 'group_path', with: path_component
|
|
|
|
fill_in 'group_name', with: group_name
|
|
|
|
fill_in 'group_description', with: group_description
|
2021-04-29 21:17:54 +05:30
|
|
|
fill_in 'group_admin_note_attributes_note', with: group_admin_note
|
2017-08-17 22:00:37 +05:30
|
|
|
click_button "Create group"
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
expect(page).to have_current_path admin_group_path(Group.find_by(path: path_component)), ignore_query: true
|
2021-03-11 19:13:27 +05:30
|
|
|
content = page.find('#content-body')
|
2022-07-23 23:45:48 +05:30
|
|
|
expect(page).to have_content group_name
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
2021-04-29 21:17:54 +05:30
|
|
|
p_texts = content.all('p').collect(&:text).join('/n')
|
|
|
|
expect(p_texts).to match group_admin_note
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'shows the visibility level radio populated with the default value' do
|
2017-08-17 22:00:37 +05:30
|
|
|
visit new_admin_group_path
|
|
|
|
|
|
|
|
expect_selected_visibility(internal)
|
|
|
|
end
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
it 'when entered in group name, it auto filled the group path' do
|
2017-08-17 22:00:37 +05:30
|
|
|
visit admin_groups_path
|
|
|
|
click_link "New group"
|
2018-12-13 13:39:08 +05:30
|
|
|
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
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
it 'auto populates the group path with the group name' do
|
2018-12-13 13:39:08 +05:30
|
|
|
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
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
it 'when entering in group path, group name does not change anymore' do
|
2018-12-13 13:39:08 +05:30
|
|
|
visit admin_groups_path
|
|
|
|
click_link "New group"
|
|
|
|
group_path = 'my-gitlab-project'
|
|
|
|
group_name = 'My modified gitlab project'
|
2017-08-17 22:00:37 +05:30
|
|
|
fill_in 'group_path', with: group_path
|
2018-12-13 13:39:08 +05:30
|
|
|
fill_in 'group_name', with: group_name
|
|
|
|
path_field = find('input#group_path')
|
|
|
|
expect(path_field.value).to eq 'my-gitlab-project'
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'show a group' do
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'shows the group' do
|
2017-08-17 22:00:37 +05:30
|
|
|
group = create(:group, :private)
|
|
|
|
|
|
|
|
visit admin_group_path(group)
|
|
|
|
|
|
|
|
expect(page).to have_content("Group: #{group.name}")
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(page).to have_content("ID: #{group.id}")
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2020-01-01 13:55:28 +05:30
|
|
|
|
|
|
|
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
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
it 'has a note if one is available' do
|
|
|
|
group = create(:group, :private)
|
|
|
|
note_text = 'A group administrator note'
|
|
|
|
group.update!(admin_note_attributes: { note: note_text })
|
|
|
|
|
|
|
|
visit admin_group_path(group)
|
|
|
|
|
|
|
|
expect(page).to have_text(note_text)
|
|
|
|
end
|
2021-09-30 23:02:18 +05:30
|
|
|
|
|
|
|
context 'when group has open access requests' do
|
|
|
|
let!(:access_request) { create(:group_member, :access_request, group: group) }
|
|
|
|
|
|
|
|
it 'shows access requests with link to manage access' do
|
|
|
|
visit admin_group_path(group)
|
|
|
|
|
|
|
|
page.within '[data-testid="access-requests"]' do
|
|
|
|
expect(page).to have_content access_request.user.name
|
|
|
|
expect(page).to have_link 'Manage access', href: group_group_members_path(group, tab: 'access_requests')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'group edit' do
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'shows the visibility level radio populated with the group visibility_level value' do
|
2017-08-17 22:00:37 +05:30
|
|
|
group = create(:group, :private)
|
|
|
|
|
|
|
|
visit admin_group_edit_path(group)
|
|
|
|
|
|
|
|
expect_selected_visibility(group.visibility_level)
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
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)
|
|
|
|
|
|
|
|
expect(page).to have_content('Allowed to create subgroups')
|
|
|
|
end
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
it 'edit group path does not change group name', :js do
|
2017-08-17 22:00:37 +05:30
|
|
|
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
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
it 'adding an admin note to group without one' do
|
|
|
|
group = create(:group, :private)
|
|
|
|
expect(group.admin_note).to be_nil
|
|
|
|
|
|
|
|
visit admin_group_edit_path(group)
|
|
|
|
admin_note_text = 'A note by an administrator'
|
|
|
|
|
|
|
|
fill_in 'group_admin_note_attributes_note', with: admin_note_text
|
|
|
|
click_button 'Save changes'
|
|
|
|
|
|
|
|
expect(page).to have_content(admin_note_text)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'editing an existing group admin note' do
|
|
|
|
admin_note_text = 'A note by an administrator'
|
|
|
|
new_admin_note_text = 'A new note by an administrator'
|
|
|
|
group = create(:group, :private)
|
|
|
|
group.create_admin_note(note: admin_note_text)
|
|
|
|
|
|
|
|
visit admin_group_edit_path(group)
|
|
|
|
|
|
|
|
admin_note_field = find('#group_admin_note_attributes_note')
|
|
|
|
expect(admin_note_field.value).to eq(admin_note_text)
|
|
|
|
|
|
|
|
fill_in 'group_admin_note_attributes_note', with: new_admin_note_text
|
|
|
|
click_button 'Save changes'
|
|
|
|
|
|
|
|
expect(page).to have_content(new_admin_note_text)
|
|
|
|
end
|
2023-03-17 16:20:25 +05:30
|
|
|
|
|
|
|
it 'hides removed note' do
|
|
|
|
group = create(:group, :private)
|
|
|
|
group.create_admin_note(note: 'A note by an administrator')
|
|
|
|
|
|
|
|
visit admin_group_edit_path(group)
|
|
|
|
fill_in 'group_admin_note_attributes_note', with: ''
|
|
|
|
click_button 'Save changes'
|
|
|
|
|
|
|
|
expect(page).not_to have_content(s_('Admin|Admin notes'))
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
describe 'add user into a group', :js do
|
2022-08-13 15:12:31 +05:30
|
|
|
context 'when membership is set to expire' do
|
|
|
|
it 'renders relative time' do
|
|
|
|
expire_time = Time.current + 2.days
|
|
|
|
current_user.update!(time_display_relative: true)
|
|
|
|
group.add_member(user, Gitlab::Access::REPORTER, expires_at: expire_time)
|
|
|
|
|
|
|
|
visit admin_group_path(group)
|
|
|
|
|
|
|
|
expect(page).to have_content(/Expires in \d day/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'renders absolute time' do
|
|
|
|
expire_time = Time.current.tomorrow.middle_of_day
|
|
|
|
current_user.update!(time_display_relative: false)
|
|
|
|
group.add_member(user, Gitlab::Access::REPORTER, expires_at: expire_time)
|
|
|
|
|
|
|
|
visit admin_group_path(group)
|
|
|
|
|
|
|
|
expect(page).to have_content("Expires on #{expire_time.strftime('%b %-d')}")
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe 'add admin himself to a group' do
|
|
|
|
before do
|
2022-08-13 15:12:31 +05:30
|
|
|
group.add_member(:user, Gitlab::Access::OWNER)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
it 'adds admin a to a group as developer', :js do
|
2017-08-17 22:00:37 +05:30
|
|
|
visit group_group_members_path(group)
|
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
invite_member(current_user.name, role: 'Developer')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
page.within members_table do
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(page).to have_content(current_user.name)
|
|
|
|
expect(page).to have_content('Developer')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
describe 'admin removes themself from a group', :js do
|
2017-08-17 22:00:37 +05:30
|
|
|
it 'removes admin from the group' do
|
2022-08-13 15:12:31 +05:30
|
|
|
group.add_member(current_user, Gitlab::Access::DEVELOPER)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
visit group_group_members_path(group)
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
page.within members_table do
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(page).to have_content(current_user.name)
|
|
|
|
expect(page).to have_content('Developer')
|
|
|
|
end
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
show_actions_for_username(current_user)
|
|
|
|
click_button _('Leave group')
|
2022-04-04 11:22:00 +05:30
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
within_modal do
|
|
|
|
click_button _('Leave')
|
|
|
|
end
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
wait_for_all_requests
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
visit group_group_members_path(group)
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
expect(members_table).not_to have_content(current_user.name)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'shared projects' do
|
|
|
|
it 'renders shared project' do
|
2017-09-10 17:25:29 +05:30
|
|
|
empty_project = create(:project)
|
2017-08-17 22:00:37 +05:30
|
|
|
empty_project.project_group_links.create!(
|
2018-11-18 11:00:15 +05:30
|
|
|
group_access: Gitlab::Access::MAINTAINER,
|
2017-08-17 22:00:37 +05:30
|
|
|
group: group
|
|
|
|
)
|
|
|
|
|
|
|
|
visit admin_group_path(group)
|
|
|
|
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(page).to have_content(empty_project.full_name)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(page).to have_content('Projects shared with')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def expect_selected_visibility(level)
|
|
|
|
selector = "#group_visibility_level_#{level}[checked=checked]"
|
|
|
|
|
|
|
|
expect(page).to have_selector(selector, count: 1)
|
|
|
|
end
|
|
|
|
end
|