2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
RSpec.describe 'Project members list', :js do
|
2017-08-17 22:00:37 +05:30
|
|
|
include Select2Helper
|
2021-04-17 20:07:23 +05:30
|
|
|
include Spec::Support::Helpers::Features::MembersHelpers
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
let(:user1) { create(:user, name: 'John Doe') }
|
|
|
|
let(:user2) { create(:user, name: 'Mary Jane') }
|
|
|
|
let(:group) { create(:group) }
|
2021-04-17 20:07:23 +05:30
|
|
|
let(:project) { create(:project, :internal, namespace: group) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
before do
|
2021-04-17 20:07:23 +05:30
|
|
|
stub_feature_flags(invite_members_group_modal: true)
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
sign_in(user1)
|
2017-08-17 22:00:37 +05:30
|
|
|
group.add_owner(user1)
|
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'show members from project and group' do
|
|
|
|
project.add_developer(user2)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
visit_members_page
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(first_row).to have_content(user1.name)
|
|
|
|
expect(second_row).to have_content(user2.name)
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'show user once if member of both group and project' do
|
|
|
|
project.add_developer(user1)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
visit_members_page
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(first_row).to have_content(user1.name)
|
|
|
|
expect(second_row).to be_blank
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'update user access level' do
|
|
|
|
project.add_developer(user2)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
visit_members_page
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
page.within find_member_row(user2) do
|
|
|
|
click_button('Developer')
|
|
|
|
click_button('Reporter')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(page).to have_button('Reporter')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'add user to project' do
|
|
|
|
visit_members_page
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
add_user(user2.name, 'Reporter')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
page.within find_member_row(user2) do
|
|
|
|
expect(page).to have_button('Reporter')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'uses ProjectMember access_level_roles for the invite members modal access option' do
|
|
|
|
visit_members_page
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
click_on 'Invite members'
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
click_on 'Guest'
|
|
|
|
wait_for_requests
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
page.within '.dropdown-menu' do
|
|
|
|
expect(page).to have_button('Guest')
|
|
|
|
expect(page).to have_button('Reporter')
|
|
|
|
expect(page).to have_button('Developer')
|
|
|
|
expect(page).to have_button('Maintainer')
|
|
|
|
expect(page).not_to have_button('Owner')
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'remove user from project' do
|
|
|
|
other_user = create(:user)
|
|
|
|
project.add_developer(other_user)
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
visit_members_page
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
# Open modal
|
|
|
|
page.within find_member_row(other_user) do
|
|
|
|
click_button 'Remove member'
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
page.within('[role="dialog"]') do
|
|
|
|
expect(page).to have_unchecked_field 'Also unassign this user from related issues and merge requests'
|
|
|
|
click_button('Remove member')
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
wait_for_requests
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(members_table).not_to have_content(other_user.name)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'invite user to project' do
|
|
|
|
visit_members_page
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
add_user('test@example.com', 'Reporter')
|
|
|
|
|
|
|
|
click_link 'Invited'
|
|
|
|
|
|
|
|
page.within find_invited_member_row('test@example.com') do
|
|
|
|
expect(page).to have_button('Reporter')
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
context 'project bots' do
|
|
|
|
let(:project_bot) { create(:user, :project_bot, name: 'project_bot') }
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
before do
|
2021-04-17 20:07:23 +05:30
|
|
|
project.add_maintainer(project_bot)
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'does not show form used to change roles and "Expiration date" or the remove user button' do
|
2021-03-11 19:13:27 +05:30
|
|
|
visit_members_page
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
page.within find_member_row(project_bot) do
|
|
|
|
expect(page).not_to have_button('Maintainer')
|
|
|
|
expect(page).to have_field('Expiration date', disabled: true)
|
|
|
|
expect(page).not_to have_button('Remove member')
|
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe 'when user has 2FA enabled' do
|
|
|
|
let_it_be(:admin) { create(:admin) }
|
|
|
|
let_it_be(:user_with_2fa) { create(:user, :two_factor_via_otp) }
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
before do
|
|
|
|
project.add_guest(user_with_2fa)
|
2020-05-24 23:13:21 +05:30
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'shows 2FA badge to user with "Maintainer" access level' do
|
|
|
|
project.add_maintainer(user1)
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
visit_members_page
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(find_member_row(user_with_2fa)).to have_content('2FA')
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'shows 2FA badge to admins' do
|
|
|
|
sign_in(admin)
|
|
|
|
gitlab_enable_admin_mode_sign_in(admin)
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
visit_members_page
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(find_member_row(user_with_2fa)).to have_content('2FA')
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'does not show 2FA badge to users with access level below "Maintainer"' do
|
|
|
|
group.add_developer(user1)
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
visit_members_page
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(find_member_row(user_with_2fa)).not_to have_content('2FA')
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
it 'shows 2FA badge to themselves' do
|
|
|
|
sign_in(user_with_2fa)
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
visit_members_page
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(find_member_row(user_with_2fa)).to have_content('2FA')
|
2021-03-11 19:13:27 +05:30
|
|
|
end
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
private
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
def add_user(id, role)
|
|
|
|
click_on 'Invite members'
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
page.within '#invite-members-modal' do
|
|
|
|
fill_in 'Search for members to invite', with: id
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
wait_for_requests
|
|
|
|
click_button id
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
click_button 'Guest'
|
|
|
|
wait_for_requests
|
|
|
|
click_button role
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
click_button 'Invite'
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
page.refresh
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def visit_members_page
|
2020-06-23 00:09:42 +05:30
|
|
|
visit project_project_members_path(project)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|