2019-07-25 01:24:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-18 17:45:41 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe 'Project > Members > Invite group', :js do
|
2016-08-18 17:45:41 -04:00
|
|
|
include Select2Helper
|
2017-08-31 20:31:03 -04:00
|
|
|
include ActionView::Helpers::DateHelper
|
2016-08-18 17:45:41 -04:00
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
let(:maintainer) { create(:user) }
|
2016-08-18 17:45:41 -04:00
|
|
|
|
2017-09-06 14:31:45 -04:00
|
|
|
describe 'Share with group lock' do
|
2017-08-31 21:09:17 -04:00
|
|
|
shared_examples 'the project can be shared with groups' do
|
2018-09-07 02:09:13 -04:00
|
|
|
it 'the "Invite group" tab exists' do
|
2020-05-28 11:08:02 -04:00
|
|
|
visit project_project_members_path(project)
|
2018-09-07 02:09:13 -04:00
|
|
|
expect(page).to have_selector('#invite-group-tab')
|
2017-08-31 21:09:17 -04:00
|
|
|
end
|
2017-08-31 20:31:03 -04:00
|
|
|
end
|
|
|
|
|
2017-08-31 21:09:17 -04:00
|
|
|
shared_examples 'the project cannot be shared with groups' do
|
2018-09-07 02:09:13 -04:00
|
|
|
it 'the "Invite group" tab does not exist' do
|
2020-05-28 11:08:02 -04:00
|
|
|
visit project_project_members_path(project)
|
2018-09-07 02:09:13 -04:00
|
|
|
expect(page).not_to have_selector('#invite-group-tab')
|
2017-08-31 21:09:17 -04:00
|
|
|
end
|
|
|
|
end
|
2017-08-31 20:31:03 -04:00
|
|
|
|
2017-08-31 21:09:17 -04:00
|
|
|
context 'for a project in a root group' do
|
|
|
|
let!(:group_to_share_with) { create(:group) }
|
|
|
|
let(:project) { create(:project, namespace: create(:group)) }
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(maintainer)
|
2019-02-12 07:29:47 -05:00
|
|
|
group_to_share_with.add_guest(maintainer)
|
2018-07-11 10:36:08 -04:00
|
|
|
sign_in(maintainer)
|
2017-08-31 21:09:17 -04:00
|
|
|
end
|
2017-08-31 20:31:03 -04:00
|
|
|
|
2018-09-07 18:53:18 -04:00
|
|
|
context 'when the group has "Share with group lock" disabled' do
|
2017-08-31 21:09:17 -04:00
|
|
|
it_behaves_like 'the project can be shared with groups'
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'the project can be shared with another group' do
|
2020-05-28 11:08:02 -04:00
|
|
|
visit project_project_members_path(project)
|
2017-08-31 21:09:17 -04:00
|
|
|
|
2020-06-02 20:08:38 -04:00
|
|
|
expect(page).not_to have_css('.project-members-groups')
|
|
|
|
|
2018-09-07 02:09:13 -04:00
|
|
|
click_on 'invite-group-tab'
|
2017-08-31 21:09:17 -04:00
|
|
|
|
|
|
|
select2 group_to_share_with.id, from: '#link_group_id'
|
|
|
|
page.find('body').click
|
2018-09-18 05:58:22 -04:00
|
|
|
find('.btn-success').click
|
2017-08-31 21:09:17 -04:00
|
|
|
|
|
|
|
page.within('.project-members-groups') do
|
|
|
|
expect(page).to have_content(group_to_share_with.name)
|
|
|
|
end
|
|
|
|
end
|
2017-08-31 20:31:03 -04:00
|
|
|
end
|
|
|
|
|
2018-09-07 18:53:18 -04:00
|
|
|
context 'when the group has "Share with group lock" enabled' do
|
2017-08-31 21:09:17 -04:00
|
|
|
before do
|
|
|
|
project.namespace.update_column(:share_with_group_lock, true)
|
2017-08-31 20:31:03 -04:00
|
|
|
end
|
2017-08-31 21:09:17 -04:00
|
|
|
|
|
|
|
it_behaves_like 'the project cannot be shared with groups'
|
2017-08-31 20:31:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-24 05:20:54 -04:00
|
|
|
context 'for a project in a subgroup' do
|
2017-08-31 21:09:17 -04:00
|
|
|
let!(:group_to_share_with) { create(:group) }
|
|
|
|
let(:root_group) { create(:group) }
|
|
|
|
let(:subgroup) { create(:group, parent: root_group) }
|
|
|
|
let(:project) { create(:project, namespace: subgroup) }
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(maintainer)
|
|
|
|
sign_in(maintainer)
|
2017-08-31 20:31:03 -04:00
|
|
|
end
|
|
|
|
|
2018-09-07 18:53:18 -04:00
|
|
|
context 'when the root_group has "Share with group lock" disabled' do
|
|
|
|
context 'when the subgroup has "Share with group lock" disabled' do
|
2017-08-31 21:09:17 -04:00
|
|
|
it_behaves_like 'the project can be shared with groups'
|
|
|
|
end
|
|
|
|
|
2018-09-07 18:53:18 -04:00
|
|
|
context 'when the subgroup has "Share with group lock" enabled' do
|
2017-08-31 21:09:17 -04:00
|
|
|
before do
|
|
|
|
subgroup.update_column(:share_with_group_lock, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'the project cannot be shared with groups'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-07 18:53:18 -04:00
|
|
|
context 'when the root_group has "Share with group lock" enabled' do
|
2017-08-31 21:09:17 -04:00
|
|
|
before do
|
|
|
|
root_group.update_column(:share_with_group_lock, true)
|
|
|
|
end
|
|
|
|
|
2018-09-07 18:53:18 -04:00
|
|
|
context 'when the subgroup has "Share with group lock" disabled (parent overridden)' do
|
2017-08-31 21:09:17 -04:00
|
|
|
it_behaves_like 'the project can be shared with groups'
|
|
|
|
end
|
|
|
|
|
2018-09-07 18:53:18 -04:00
|
|
|
context 'when the subgroup has "Share with group lock" enabled' do
|
2017-08-31 21:09:17 -04:00
|
|
|
before do
|
|
|
|
subgroup.update_column(:share_with_group_lock, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'the project cannot be shared with groups'
|
|
|
|
end
|
2017-08-31 20:31:03 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-18 17:45:41 -04:00
|
|
|
end
|
|
|
|
|
2017-08-31 20:31:03 -04:00
|
|
|
describe 'setting an expiration date for a group link' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let!(:group) { create(:group) }
|
|
|
|
|
|
|
|
around do |example|
|
2020-08-31 11:10:41 -04:00
|
|
|
freeze_time { example.run }
|
2017-08-31 20:31:03 -04:00
|
|
|
end
|
|
|
|
|
2016-08-18 17:45:41 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(maintainer)
|
2019-02-12 07:29:47 -05:00
|
|
|
group.add_guest(maintainer)
|
2018-07-11 10:36:08 -04:00
|
|
|
sign_in(maintainer)
|
2017-08-31 20:31:03 -04:00
|
|
|
|
2020-05-28 11:08:02 -04:00
|
|
|
visit project_project_members_path(project)
|
2016-08-18 17:45:41 -04:00
|
|
|
|
2018-09-07 02:09:13 -04:00
|
|
|
click_on 'invite-group-tab'
|
2017-06-06 17:31:47 -04:00
|
|
|
|
2016-08-18 17:45:41 -04:00
|
|
|
select2 group.id, from: '#link_group_id'
|
2017-08-31 20:31:03 -04:00
|
|
|
|
|
|
|
fill_in 'expires_at_groups', with: (Time.now + 4.5.days).strftime('%Y-%m-%d')
|
2018-09-07 02:09:13 -04:00
|
|
|
click_on 'invite-group-tab'
|
2018-09-18 05:58:22 -04:00
|
|
|
find('.btn-success').click
|
2016-08-18 17:45:41 -04:00
|
|
|
end
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
it 'the group link shows the expiration time with a warning class' do
|
2017-06-06 17:31:47 -04:00
|
|
|
page.within('.project-members-groups') do
|
2017-08-31 20:31:03 -04:00
|
|
|
# Using distance_of_time_in_words_to_now because it is not the same as
|
|
|
|
# subtraction, and this way avoids time zone issues as well
|
|
|
|
expires_in_text = distance_of_time_in_words_to_now(project.project_group_links.first.expires_at)
|
|
|
|
expect(page).to have_content(expires_in_text)
|
2016-08-18 17:45:41 -04:00
|
|
|
expect(page).to have_selector('.text-warning')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-15 10:09:53 -04:00
|
|
|
|
2017-08-31 20:31:03 -04:00
|
|
|
describe 'the groups dropdown' do
|
|
|
|
context 'with multiple groups to choose from' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(maintainer)
|
|
|
|
sign_in(maintainer)
|
2017-08-31 20:31:03 -04:00
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
create(:group).add_owner(maintainer)
|
|
|
|
create(:group).add_owner(maintainer)
|
2017-08-31 20:31:03 -04:00
|
|
|
|
2020-05-28 11:08:02 -04:00
|
|
|
visit project_project_members_path(project)
|
2018-02-20 17:20:48 -05:00
|
|
|
|
2018-09-07 02:09:13 -04:00
|
|
|
click_link 'Invite group'
|
2018-02-20 17:20:48 -05:00
|
|
|
|
|
|
|
find('.ajax-groups-select.select2-container')
|
|
|
|
|
2017-10-27 05:05:03 -04:00
|
|
|
execute_script 'GROUP_SELECT_PER_PAGE = 1;'
|
2017-08-31 20:31:03 -04:00
|
|
|
open_select2 '#link_group_id'
|
|
|
|
end
|
2017-03-15 10:09:53 -04:00
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'infinitely scrolls' do
|
2017-08-31 20:31:03 -04:00
|
|
|
expect(find('.select2-drop .select2-results')).to have_selector('.select2-result', count: 1)
|
2017-03-15 10:09:53 -04:00
|
|
|
|
2017-08-31 20:31:03 -04:00
|
|
|
scroll_select2_to_bottom('.select2-drop .select2-results:visible')
|
2017-03-15 10:09:53 -04:00
|
|
|
|
2017-08-31 20:31:03 -04:00
|
|
|
expect(find('.select2-drop .select2-results')).to have_selector('.select2-result', count: 2)
|
2017-03-15 10:09:53 -04:00
|
|
|
end
|
|
|
|
end
|
2017-03-30 08:14:32 -04:00
|
|
|
|
2017-08-31 20:31:03 -04:00
|
|
|
context 'for a project in a nested group' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let!(:nested_group) { create(:group, parent: group) }
|
2017-08-31 21:09:17 -04:00
|
|
|
let!(:group_to_share_with) { create(:group) }
|
2017-08-31 20:31:03 -04:00
|
|
|
let!(:project) { create(:project, namespace: nested_group) }
|
|
|
|
|
2018-07-05 02:32:05 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(maintainer)
|
|
|
|
sign_in(maintainer)
|
|
|
|
group.add_maintainer(maintainer)
|
|
|
|
group_to_share_with.add_maintainer(maintainer)
|
2017-08-31 20:31:03 -04:00
|
|
|
end
|
2017-03-30 08:14:32 -04:00
|
|
|
|
2019-07-24 05:20:54 -04:00
|
|
|
it 'the groups dropdown does not show ancestors' do
|
2020-05-28 11:08:02 -04:00
|
|
|
visit project_project_members_path(project)
|
2017-03-30 08:14:32 -04:00
|
|
|
|
2018-09-07 02:09:13 -04:00
|
|
|
click_on 'invite-group-tab'
|
2017-08-31 20:31:03 -04:00
|
|
|
click_link 'Search for a group'
|
2017-03-30 08:14:32 -04:00
|
|
|
|
2017-08-31 20:31:03 -04:00
|
|
|
page.within '.select2-drop' do
|
2017-08-31 21:09:17 -04:00
|
|
|
expect(page).to have_content(group_to_share_with.name)
|
2017-08-31 20:31:03 -04:00
|
|
|
expect(page).not_to have_content(group.name)
|
|
|
|
end
|
|
|
|
end
|
2017-03-30 08:14:32 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-18 17:45:41 -04:00
|
|
|
end
|