Commit e18c629a authored by Jiaan Louw's avatar Jiaan Louw Committed by Nicolò Maria Mezzopera

Convert admin/users view - update specs for feature flag rollout

parent 668fc6a8
...@@ -23,9 +23,7 @@ export default { ...@@ -23,9 +23,7 @@ export default {
'data-method': 'put', 'data-method': 'put',
'data-modal-attributes': JSON.stringify({ 'data-modal-attributes': JSON.stringify({
title: sprintf(s__('AdminUsers|Unblock user %{username}?'), { username: this.username }), title: sprintf(s__('AdminUsers|Unblock user %{username}?'), { username: this.username }),
message: s__( message: s__('AdminUsers|You can always block their account again if needed.'),
'AdminUsers|You can always unblock their account, their data will remain intact.',
),
okVariant: 'confirm', okVariant: 'confirm',
okTitle: s__('AdminUsers|Unblock'), okTitle: s__('AdminUsers|Unblock'),
}), }),
......
...@@ -70,14 +70,14 @@ export default { ...@@ -70,14 +70,14 @@ export default {
</script> </script>
<template> <template>
<div class="gl-display-flex gl-justify-content-end"> <div class="gl-display-flex gl-justify-content-end" :data-testid="`user-actions-${user.id}`">
<gl-button v-if="hasEditAction" data-testid="edit" :href="userPaths.edit">{{ <gl-button v-if="hasEditAction" data-testid="edit" :href="userPaths.edit">{{
$options.i18n.edit $options.i18n.edit
}}</gl-button> }}</gl-button>
<gl-dropdown <gl-dropdown
v-if="hasDropdownActions" v-if="hasDropdownActions"
data-testid="actions" data-testid="dropdown-toggle"
right right
class="gl-ml-2" class="gl-ml-2"
icon="settings" icon="settings"
......
...@@ -77,6 +77,10 @@ export default { ...@@ -77,6 +77,10 @@ export default {
<user-date :date="lastActivityOn" show-never /> <user-date :date="lastActivityOn" show-never />
</template> </template>
<template #cell(projectsCount)="{ item: { id, projectsCount } }">
<div :data-testid="`user-project-count-${id}`">{{ projectsCount }}</div>
</template>
<template #cell(settings)="{ item: user }"> <template #cell(settings)="{ item: user }">
<user-actions :user="user" :paths="paths" /> <user-actions :user="user" :paths="paths" />
</template> </template>
......
...@@ -21,13 +21,13 @@ ...@@ -21,13 +21,13 @@
= user.last_activity_on.nil? ? _('Never') : l(user.last_activity_on, format: :admin) = user.last_activity_on.nil? ? _('Never') : l(user.last_activity_on, format: :admin)
- unless user.internal? - unless user.internal?
.table-section.section-20.table-button-footer .table-section.section-20.table-button-footer
.table-action-buttons .table-action-buttons{ data: { testid: "user-actions-#{user.id}" } }
= link_to _('Edit'), edit_admin_user_path(user), id: "edit_#{dom_id(user)}", class: 'btn gl-button btn-default' = link_to _('Edit'), edit_admin_user_path(user), class: 'btn gl-button btn-default'
- unless user == current_user - unless user == current_user
%button.dropdown-new.btn.gl-button.btn-default{ type: 'button', data: { testid: "user-action-button-#{user.id}", toggle: 'dropdown' } } %button.dropdown-new.btn.gl-button.btn-default{ type: 'button', data: { testid: "dropdown-toggle", toggle: 'dropdown' } }
= sprite_icon('settings') = sprite_icon('settings')
= sprite_icon('chevron-down') = sprite_icon('chevron-down')
%ul.dropdown-menu.dropdown-menu-right{ data: { testid: "user-action-dropdown-#{user.id}" } } %ul.dropdown-menu.dropdown-menu-right
%li.dropdown-header %li.dropdown-header
= _('Settings') = _('Settings')
%li %li
......
...@@ -3,172 +3,179 @@ ...@@ -3,172 +3,179 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe "Admin::Users" do RSpec.describe "Admin::Users" do
include Spec::Support::Helpers::Features::ResponsiveTableHelpers let_it_be(:user) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') }
let_it_be(:current_user) { create(:admin) }
let!(:user) do
create(:omniauth_user, provider: 'twitter', extern_uid: '123456')
end
let!(:current_user) { create(:admin, last_activity_on: 5.days.ago) }
before do before do
stub_feature_flags(vue_admin_users: false)
sign_in(current_user) sign_in(current_user)
gitlab_enable_admin_mode_sign_in(current_user) gitlab_enable_admin_mode_sign_in(current_user)
end end
describe 'GET /admin/users' do [true, false].each do |vue_admin_users|
describe 'send emails to users' do context "with vue_admin_users feature flag set to #{vue_admin_users}", js: vue_admin_users do
context 'when `send_emails_from_admin_area` feature is enabled' do before do
before do stub_feature_flags(vue_admin_users: vue_admin_users)
stub_licensed_features(send_emails_from_admin_area: true) end
end
it "shows the 'Send email to users' link" do describe 'GET /admin/users' do
visit admin_users_path describe 'send emails to users' do
context 'when `send_emails_from_admin_area` feature is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: true)
end
expect(page).to have_link(href: admin_email_path) it "shows the 'Send email to users' link" do
end visit admin_users_path
end
context 'when `send_emails_from_admin_area` feature is disabled' do expect(page).to have_link(href: admin_email_path)
before do end
stub_licensed_features(send_emails_from_admin_area: false) end
end
it "does not show the 'Send email to users' link" do context 'when `send_emails_from_admin_area` feature is disabled' do
visit admin_users_path before do
stub_licensed_features(send_emails_from_admin_area: false)
end
expect(page).not_to have_link(href: admin_email_path) it "does not show the 'Send email to users' link" do
end visit admin_users_path
end
end
describe 'user permission export' do expect(page).not_to have_link(href: admin_email_path)
context 'when `export_user_permissions` feature is available' do end
before do end
stub_licensed_features(export_user_permissions: true)
end end
it "shows the 'Export Permissions' link" do describe 'user permission export' do
visit admin_users_path context 'when `export_user_permissions` feature is available' do
before do
stub_licensed_features(export_user_permissions: true)
end
expect(page).to have_link(href: admin_user_permission_exports_path(format: :csv)) it "shows the 'Export Permissions' link" do
end visit admin_users_path
end
context 'when `export_user_permissions` feature is disabled' do expect(page).to have_link(href: admin_user_permission_exports_path(format: :csv))
before do end
stub_licensed_features(export_user_permissions: false) end
end
it "does not show the 'Export Permissions' link" do context 'when `export_user_permissions` feature is disabled' do
visit admin_users_path before do
stub_licensed_features(export_user_permissions: false)
end
expect(page).not_to have_link(href: admin_user_permission_exports_path(format: :csv)) it "does not show the 'Export Permissions' link" do
visit admin_users_path
expect(page).not_to have_link(href: admin_user_permission_exports_path(format: :csv))
end
end
end end
end end
end
end
describe "GET /admin/users/:id" do describe "GET /admin/users/:id" do
describe 'Shared runners quota status' do describe 'Shared runners quota status' do
before do before do
user.namespace.update!(shared_runners_minutes_limit: 500) user.namespace.update!(shared_runners_minutes_limit: 500)
end end
context 'with projects with shared runners enabled' do context 'with projects with shared runners enabled' do
before do before do
create(:project, namespace: user.namespace, shared_runners_enabled: true) create(:project, namespace: user.namespace, shared_runners_enabled: true)
end end
it 'shows quota' do it 'shows quota' do
visit admin_users_path visit admin_users_path
click_link user.name click_link user.name
expect(page).to have_content('Pipeline minutes quota: 0 / 500') expect(page).to have_content('Pipeline minutes quota: 0 / 500')
end end
end end
context 'without projects with shared runners enabled' do context 'without projects with shared runners enabled' do
before do before do
create(:project, namespace: user.namespace, shared_runners_enabled: false) create(:project, namespace: user.namespace, shared_runners_enabled: false)
end end
it 'does not show quota' do it 'does not show quota' do
visit admin_users_path visit admin_users_path
click_link user.name click_link user.name
expect(page).not_to have_content('Pipeline minutes quota:') expect(page).not_to have_content('Pipeline minutes quota:')
end
end
end end
end end
end
end
describe "GET /admin/users/:id/edit" do describe "GET /admin/users/:id/edit" do
before do describe "Update user account type" do
visit admin_users_path before do
click_link "edit_user_#{user.id}" visit_edit_user(user.id)
end
describe "Update user account type" do allow_any_instance_of(AuditorUserHelper).to receive(:license_allows_auditor_user?).and_return(true)
before do choose "user_access_level_auditor"
allow_any_instance_of(AuditorUserHelper).to receive(:license_allows_auditor_user?).and_return(true) click_button "Save changes"
choose "user_access_level_auditor" end
click_button "Save changes"
end
it "changes account type to be auditor" do it "changes account type to be auditor" do
user.reload user.reload
expect(user).not_to be_admin expect(user).not_to be_admin
expect(user).to be_auditor expect(user).to be_auditor
end end
end end
describe 'Update shared runners quota' do describe 'Update shared runners quota' do
let!(:project) { create(:project, namespace: user.namespace, shared_runners_enabled: true) } let_it_be(:project) { create(:project, namespace: user.namespace, shared_runners_enabled: true) }
before do it "shows page with new data" do
fill_in "user_namespace_attributes_shared_runners_minutes_limit", with: "500" visit_edit_user(user.id)
click_button "Save changes" fill_in "user_namespace_attributes_shared_runners_minutes_limit", with: "500"
end
click_button "Save changes"
it "shows page with new data" do expect(page).to have_content('Pipeline minutes quota: 0 / 500')
expect(page).to have_content('Pipeline minutes quota: 0 / 500') end
end
def visit_edit_user(user_id)
visit admin_users_path
page.within("[data-testid='user-actions-#{user_id}']") do
click_link 'Edit'
end
end
end end
end
end
describe 'show user keys for SSH and LDAP' do describe 'show user keys for SSH and LDAP' do
let!(:key1) do let_it_be(:key1) do
create(:ldap_key, user: user, title: "LDAP Key1") create(:ldap_key, user: user, title: "LDAP Key1")
end end
let!(:key2) do let_it_be(:key2) do
create(:key, user: user, title: "ssh-rsa Key2", key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4FIEBXGi4bPU8kzxMefudPIJ08/gNprdNTaO9BR/ndy3+58s2HCTw2xCHcsuBmq+TsAqgEidVq4skpqoTMB+Uot5Uzp9z4764rc48dZiI661izoREoKnuRQSsRqUTHg5wrLzwxlQbl1MVfRWQpqiz/5KjBC7yLEb9AbusjnWBk8wvC1bQPQ1uLAauEA7d836tgaIsym9BrLsMVnR4P1boWD3Xp1B1T/ImJwAGHvRmP/ycIqmKdSpMdJXwxcb40efWVj0Ibbe7ii9eeoLdHACqevUZi6fwfbymdow+FeqlkPoHyGg3Cu4vD/D8+8cRc7mE/zGCWcQ15Var83Tczour Key2") create(:key, user: user, title: "ssh-rsa Key2", key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4FIEBXGi4bPU8kzxMefudPIJ08/gNprdNTaO9BR/ndy3+58s2HCTw2xCHcsuBmq+TsAqgEidVq4skpqoTMB+Uot5Uzp9z4764rc48dZiI661izoREoKnuRQSsRqUTHg5wrLzwxlQbl1MVfRWQpqiz/5KjBC7yLEb9AbusjnWBk8wvC1bQPQ1uLAauEA7d836tgaIsym9BrLsMVnR4P1boWD3Xp1B1T/ImJwAGHvRmP/ycIqmKdSpMdJXwxcb40efWVj0Ibbe7ii9eeoLdHACqevUZi6fwfbymdow+FeqlkPoHyGg3Cu4vD/D8+8cRc7mE/zGCWcQ15Var83Tczour Key2")
end end
it 'only shows the delete button for regular keys' do it 'only shows the delete button for regular keys' do
visit admin_users_path visit admin_users_path
click_link user.name click_link user.name
click_link 'SSH keys' click_link 'SSH keys'
# Check that the regular Key shows the delete icon and the LDAPKey does not # Check that the regular Key shows the delete icon and the LDAPKey does not
# SSH key should be the first in the list # SSH key should be the first in the list
within('ul.content-list li.key-list-item:nth-of-type(1)') do within('ul.content-list li.key-list-item:nth-of-type(1)') do
expect(page).to have_content(key2.title) expect(page).to have_content(key2.title)
expect(page).to have_button('Delete') expect(page).to have_button('Delete')
end end
# Next, LDAP key # Next, LDAP key
within('ul.content-list li.key-list-item:nth-of-type(2)') do within('ul.content-list li.key-list-item:nth-of-type(2)') do
expect(page).to have_content(key1.title) expect(page).to have_content(key1.title)
expect(page).not_to have_button('Delete') expect(page).not_to have_button('Delete')
end
end
end end
end end
end end
......
...@@ -4,18 +4,16 @@ require 'spec_helper' ...@@ -4,18 +4,16 @@ require 'spec_helper'
RSpec.describe 'Admin::Users::User' do RSpec.describe 'Admin::Users::User' do
let_it_be(:user) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') } let_it_be(:user) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') }
let_it_be(:current_user) { create(:admin, last_activity_on: 5.days.ago) } let_it_be(:current_user) { create(:admin) }
before do before do
sign_in(current_user) sign_in(current_user)
gitlab_enable_admin_mode_sign_in(current_user) gitlab_enable_admin_mode_sign_in(current_user)
stub_feature_flags(vue_admin_users: false)
end end
describe 'GET /admin/users/:id' do describe 'GET /admin/users/:id' do
it 'has user info', :aggregate_failures do it 'has user info', :aggregate_failures do
visit admin_users_path visit admin_user_path(user)
click_link user.name
expect(page).to have_content(user.email) expect(page).to have_content(user.email)
expect(page).to have_content(user.name) expect(page).to have_content(user.name)
...@@ -27,21 +25,6 @@ RSpec.describe 'Admin::Users::User' do ...@@ -27,21 +25,6 @@ RSpec.describe 'Admin::Users::User' do
expect(page).to have_button('Delete user and contributions') expect(page).to have_button('Delete user and contributions')
end end
context 'user pending approval' do
it 'shows user info', :aggregate_failures do
user = create(:user, :blocked_pending_approval)
visit admin_users_path
click_link 'Pending approval'
click_link user.name
expect(page).to have_content(user.name)
expect(page).to have_content('Pending approval')
expect(page).to have_link('Approve user')
expect(page).to have_link('Reject request')
end
end
context 'when blocking/unblocking the user' do context 'when blocking/unblocking the user' do
it 'shows confirmation and allows blocking and unblocking', :js do it 'shows confirmation and allows blocking and unblocking', :js do
visit admin_user_path(user) visit admin_user_path(user)
...@@ -171,6 +154,8 @@ RSpec.describe 'Admin::Users::User' do ...@@ -171,6 +154,8 @@ RSpec.describe 'Admin::Users::User' do
it 'logs in as the user when impersonate is clicked' do it 'logs in as the user when impersonate is clicked' do
subject subject
find('[data-qa-selector="user_menu"]').click
expect(page.find(:css, '[data-testid="user-profile-link"]')['data-user']).to eql(another_user.username) expect(page.find(:css, '[data-testid="user-profile-link"]')['data-user']).to eql(another_user.username)
end end
...@@ -205,6 +190,8 @@ RSpec.describe 'Admin::Users::User' do ...@@ -205,6 +190,8 @@ RSpec.describe 'Admin::Users::User' do
it 'logs out of impersonated user back to original user' do it 'logs out of impersonated user back to original user' do
subject subject
find('[data-qa-selector="user_menu"]').click
expect(page.find(:css, '[data-testid="user-profile-link"]')['data-user']).to eq(current_user.username) expect(page.find(:css, '[data-testid="user-profile-link"]')['data-user']).to eq(current_user.username)
end end
...@@ -238,6 +225,8 @@ RSpec.describe 'Admin::Users::User' do ...@@ -238,6 +225,8 @@ RSpec.describe 'Admin::Users::User' do
end end
it 'shows when disabled' do it 'shows when disabled' do
user.update!(otp_required_for_login: false)
visit admin_user_path(user) visit admin_user_path(user)
expect_two_factor_status('Disabled') expect_two_factor_status('Disabled')
...@@ -251,7 +240,7 @@ RSpec.describe 'Admin::Users::User' do ...@@ -251,7 +240,7 @@ RSpec.describe 'Admin::Users::User' do
end end
describe 'Email verification status' do describe 'Email verification status' do
let!(:secondary_email) do let_it_be(:secondary_email) do
create :email, email: 'secondary@example.com', user: user create :email, email: 'secondary@example.com', user: user
end end
...@@ -274,99 +263,121 @@ RSpec.describe 'Admin::Users::User' do ...@@ -274,99 +263,121 @@ RSpec.describe 'Admin::Users::User' do
expect(page).to have_content("#{secondary_email.email} Verified") expect(page).to have_content("#{secondary_email.email} Verified")
end end
end end
end
describe 'show user attributes' do
it 'has expected attributes', :aggregate_failures do
visit admin_users_path
click_link user.name describe 'show user identities' do
it 'shows user identities', :aggregate_failures do
visit admin_user_identities_path(user)
expect(page).to have_content 'Account' expect(page).to have_content(user.name)
expect(page).to have_content 'Personal projects limit' expect(page).to have_content('twitter')
end
end end
end
describe 'remove users secondary email', :js do describe 'update user identities' do
let!(:secondary_email) do before do
create :email, email: 'secondary@example.com', user: user allow(Gitlab::Auth::OAuth::Provider).to receive(:providers).and_return([:twitter, :twitter_updated])
end
it 'modifies twitter identity', :aggregate_failures do
visit admin_user_identities_path(user)
find('.table').find(:link, 'Edit').click
fill_in 'identity_extern_uid', with: '654321'
select 'twitter_updated', from: 'identity_provider'
click_button 'Save changes'
expect(page).to have_content(user.name)
expect(page).to have_content('twitter_updated')
expect(page).to have_content('654321')
end
end end
it do describe 'remove users secondary email', :js do
visit admin_user_path(user.username) let_it_be(:secondary_email) do
create :email, email: 'secondary@example.com', user: user
end
it do
visit admin_user_path(user.username)
expect(page).to have_content("Secondary email: #{secondary_email.email}") expect(page).to have_content("Secondary email: #{secondary_email.email}")
accept_confirm { find("#remove_email_#{secondary_email.id}").click } accept_confirm { find("#remove_email_#{secondary_email.id}").click }
expect(page).not_to have_content(secondary_email.email) expect(page).not_to have_content(secondary_email.email)
end
end end
end
describe 'show user keys', :js do describe 'remove user with identities' do
it do it 'removes user with twitter identity', :aggregate_failures do
key1 = create(:key, user: user, title: 'ssh-rsa Key1', key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4FIEBXGi4bPU8kzxMefudPIJ08/gNprdNTaO9BR/ndy3+58s2HCTw2xCHcsuBmq+TsAqgEidVq4skpqoTMB+Uot5Uzp9z4764rc48dZiI661izoREoKnuRQSsRqUTHg5wrLzwxlQbl1MVfRWQpqiz/5KjBC7yLEb9AbusjnWBk8wvC1bQPQ1uLAauEA7d836tgaIsym9BrLsMVnR4P1boWD3Xp1B1T/ImJwAGHvRmP/ycIqmKdSpMdJXwxcb40efWVj0Ibbe7ii9eeoLdHACqevUZi6fwfbymdow+FeqlkPoHyGg3Cu4vD/D8+8cRc7mE/zGCWcQ15Var83Tczour Key1') visit admin_user_identities_path(user)
key2 = create(:key, user: user, title: 'ssh-rsa Key2', key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQSTWXhJAX/He+nG78MiRRRn7m0Pb0XbcgTxE0etArgoFoh9WtvDf36HG6tOSg/0UUNcp0dICsNAmhBKdncp6cIyPaXJTURPRAGvhI0/VDk4bi27bRnccGbJ/hDaUxZMLhhrzY0r22mjVf8PF6dvv5QUIQVm1/LeaWYsHHvLgiIjwrXirUZPnFrZw6VLREoBKG8uWvfSXw1L5eapmstqfsME8099oi+vWLR8MgEysZQmD28M73fgW4zek6LDQzKQyJx9nB+hJkKUDvcuziZjGmRFlNgSA2mguERwL1OXonD8WYUrBDGKroIvBT39zS5d9tQDnidEJZ9Y8gv5ViYP7x Key2')
visit admin_users_path click_link 'Delete'
click_link user.name expect(page).to have_content(user.name)
click_link 'SSH keys' expect(page).not_to have_content('twitter')
end
end
expect(page).to have_content(key1.title) describe 'show user keys', :js do
expect(page).to have_content(key2.title) it do
key1 = create(:key, user: user, title: 'ssh-rsa Key1', key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC4FIEBXGi4bPU8kzxMefudPIJ08/gNprdNTaO9BR/ndy3+58s2HCTw2xCHcsuBmq+TsAqgEidVq4skpqoTMB+Uot5Uzp9z4764rc48dZiI661izoREoKnuRQSsRqUTHg5wrLzwxlQbl1MVfRWQpqiz/5KjBC7yLEb9AbusjnWBk8wvC1bQPQ1uLAauEA7d836tgaIsym9BrLsMVnR4P1boWD3Xp1B1T/ImJwAGHvRmP/ycIqmKdSpMdJXwxcb40efWVj0Ibbe7ii9eeoLdHACqevUZi6fwfbymdow+FeqlkPoHyGg3Cu4vD/D8+8cRc7mE/zGCWcQ15Var83Tczour Key1')
key2 = create(:key, user: user, title: 'ssh-rsa Key2', key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQSTWXhJAX/He+nG78MiRRRn7m0Pb0XbcgTxE0etArgoFoh9WtvDf36HG6tOSg/0UUNcp0dICsNAmhBKdncp6cIyPaXJTURPRAGvhI0/VDk4bi27bRnccGbJ/hDaUxZMLhhrzY0r22mjVf8PF6dvv5QUIQVm1/LeaWYsHHvLgiIjwrXirUZPnFrZw6VLREoBKG8uWvfSXw1L5eapmstqfsME8099oi+vWLR8MgEysZQmD28M73fgW4zek6LDQzKQyJx9nB+hJkKUDvcuziZjGmRFlNgSA2mguERwL1OXonD8WYUrBDGKroIvBT39zS5d9tQDnidEJZ9Y8gv5ViYP7x Key2')
click_link key2.title visit admin_user_path(user)
expect(page).to have_content(key2.title) click_link 'SSH keys'
expect(page).to have_content(key2.key)
click_button 'Delete' expect(page).to have_content(key1.title)
expect(page).to have_content(key2.title)
page.within('.modal') do click_link key2.title
page.click_button('Delete')
end
expect(page).not_to have_content(key2.title) expect(page).to have_content(key2.title)
end expect(page).to have_content(key2.key)
end
describe 'show user identities' do click_button 'Delete'
it 'shows user identities', :aggregate_failures do
visit admin_user_identities_path(user)
expect(page).to have_content(user.name) page.within('.modal') do
expect(page).to have_content('twitter') page.click_button('Delete')
end end
end
describe 'update user identities' do expect(page).not_to have_content(key2.title)
before do end
allow(Gitlab::Auth::OAuth::Provider).to receive(:providers).and_return([:twitter, :twitter_updated])
end end
it 'modifies twitter identity', :aggregate_failures do describe 'show user attributes' do
visit admin_user_identities_path(user) it 'has expected attributes', :aggregate_failures do
visit admin_user_path(user)
find('.table').find(:link, 'Edit').click
fill_in 'identity_extern_uid', with: '654321'
select 'twitter_updated', from: 'identity_provider'
click_button 'Save changes'
expect(page).to have_content(user.name) expect(page).to have_content 'Account'
expect(page).to have_content('twitter_updated') expect(page).to have_content 'Personal projects limit'
expect(page).to have_content('654321') end
end end
end end
describe 'remove user with identities' do [true, false].each do |vue_admin_users|
it 'removes user with twitter identity', :aggregate_failures do context "with vue_admin_users feature flag set to #{vue_admin_users}", js: vue_admin_users do
visit admin_user_identities_path(user) before do
stub_feature_flags(vue_admin_users: vue_admin_users)
end
click_link 'Delete' describe 'GET /admin/users' do
context 'user pending approval' do
it 'shows user info', :aggregate_failures do
user = create(:user, :blocked_pending_approval)
expect(page).to have_content(user.name) visit admin_users_path
expect(page).not_to have_content('twitter') click_link 'Pending approval'
click_link user.name
expect(page).to have_content(user.name)
expect(page).to have_content('Pending approval')
expect(page).to have_link('Approve user')
expect(page).to have_link('Reject request')
end
end
end
end end
end end
end end
...@@ -3,298 +3,305 @@ ...@@ -3,298 +3,305 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Admin::Users' do RSpec.describe 'Admin::Users' do
include Spec::Support::Helpers::Features::ResponsiveTableHelpers
let_it_be(:user, reload: true) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') } let_it_be(:user, reload: true) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') }
let_it_be(:current_user) { create(:admin, last_activity_on: 5.days.ago) } let_it_be(:current_user) { create(:admin) }
before do before do
sign_in(current_user) sign_in(current_user)
gitlab_enable_admin_mode_sign_in(current_user) gitlab_enable_admin_mode_sign_in(current_user)
end end
describe 'GET /admin/users' do [true, false].each do |vue_admin_users|
before do context "with vue_admin_users feature flag set to #{vue_admin_users}", js: vue_admin_users do
stub_feature_flags(vue_admin_users: false) before do
visit admin_users_path stub_feature_flags(vue_admin_users: vue_admin_users)
end end
it "is ok" do describe 'GET /admin/users' do
expect(current_path).to eq(admin_users_path) before do
end visit admin_users_path
end
it "has users list" do it "is ok" do
expect(page).to have_content(current_user.email) expect(current_path).to eq(admin_users_path)
expect(page).to have_content(current_user.name) end
expect(page).to have_content(current_user.created_at.strftime('%e %b, %Y'))
expect(page).to have_content(current_user.last_activity_on.strftime('%e %b, %Y'))
expect(page).to have_content(user.email)
expect(page).to have_content(user.name)
expect(page).to have_content('Projects')
expect(page).to have_button('Block')
expect(page).to have_button('Deactivate')
expect(page).to have_button('Delete user')
expect(page).to have_button('Delete user and contributions')
end
describe 'view extra user information' do it "has users list" do
it 'shows the user popover on hover', :js, quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/11290' do current_user.reload
expect(page).not_to have_selector('#__BV_popover_1__')
first_user_link = page.first('.js-user-link') expect(page).to have_content(current_user.email)
first_user_link.hover expect(page).to have_content(current_user.name)
expect(page).to have_content(current_user.created_at.strftime('%e %b, %Y'))
expect(page).to have_content(user.email)
expect(page).to have_content(user.name)
expect(page).to have_content('Projects')
expect(page).to have_selector('#__BV_popover_1__') click_user_dropdown_toggle(user.id)
end
end
context 'user project count' do expect(page).to have_button('Block')
before do expect(page).to have_button('Deactivate')
project = create(:project) expect(page).to have_button('Delete user')
project.add_maintainer(current_user) expect(page).to have_button('Delete user and contributions')
end end
it 'displays count of users projects' do it 'clicking edit user takes us to edit page', :aggregate_failures do
visit admin_users_path page.within("[data-testid='user-actions-#{user.id}']") do
click_link 'Edit'
end
expect(page.find("[data-testid='user-project-count-#{current_user.id}']").text).to eq("1") expect(page).to have_content('Name')
end expect(page).to have_content('Password')
end end
describe 'tabs' do describe 'view extra user information' do
it 'has multiple tabs to filter users' do it 'shows the user popover on hover', :js, quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/11290' do
expect(page).to have_link('Active', href: admin_users_path) expect(page).not_to have_selector('#__BV_popover_1__')
expect(page).to have_link('Admins', href: admin_users_path(filter: 'admins'))
expect(page).to have_link('2FA Enabled', href: admin_users_path(filter: 'two_factor_enabled'))
expect(page).to have_link('2FA Disabled', href: admin_users_path(filter: 'two_factor_disabled'))
expect(page).to have_link('External', href: admin_users_path(filter: 'external'))
expect(page).to have_link('Blocked', href: admin_users_path(filter: 'blocked'))
expect(page).to have_link('Deactivated', href: admin_users_path(filter: 'deactivated'))
expect(page).to have_link('Without projects', href: admin_users_path(filter: 'wop'))
end
context '`Pending approval` tab' do first_user_link = page.first('.js-user-link')
before do first_user_link.hover
visit admin_users_path
end
it 'shows the `Pending approval` tab' do expect(page).to have_selector('#__BV_popover_1__')
expect(page).to have_link('Pending approval', href: admin_users_path(filter: 'blocked_pending_approval')) end
end end
end
end
describe 'search and sort' do context 'user project count' do
before_all do before do
create(:user, name: 'Foo Bar', last_activity_on: 3.days.ago) project = create(:project)
create(:user, name: 'Foo Baz', last_activity_on: 2.days.ago) project.add_maintainer(current_user)
create(:user, name: 'Dmitriy') end
end
it 'searches users by name' do it 'displays count of users projects' do
visit admin_users_path(search_query: 'Foo') visit admin_users_path
expect(page).to have_content('Foo Bar') expect(page.find("[data-testid='user-project-count-#{current_user.id}']").text).to eq("1")
expect(page).to have_content('Foo Baz') end
expect(page).not_to have_content('Dmitriy') end
end
it 'sorts users by name' do describe 'tabs' do
visit admin_users_path it 'has multiple tabs to filter users' do
expect(page).to have_link('Active', href: admin_users_path)
expect(page).to have_link('Admins', href: admin_users_path(filter: 'admins'))
expect(page).to have_link('2FA Enabled', href: admin_users_path(filter: 'two_factor_enabled'))
expect(page).to have_link('2FA Disabled', href: admin_users_path(filter: 'two_factor_disabled'))
expect(page).to have_link('External', href: admin_users_path(filter: 'external'))
expect(page).to have_link('Blocked', href: admin_users_path(filter: 'blocked'))
expect(page).to have_link('Deactivated', href: admin_users_path(filter: 'deactivated'))
expect(page).to have_link('Without projects', href: admin_users_path(filter: 'wop'))
end
context '`Pending approval` tab' do
before do
visit admin_users_path
end
it 'shows the `Pending approval` tab' do
expect(page).to have_link('Pending approval', href: admin_users_path(filter: 'blocked_pending_approval'))
end
end
end
sort_by('Name') describe 'search and sort' do
before_all do
create(:user, name: 'Foo Bar', last_activity_on: 3.days.ago)
create(:user, name: 'Foo Baz', last_activity_on: 2.days.ago)
create(:user, name: 'Dmitriy')
end
expect(first_row.text).to include('Dmitriy') it 'searches users by name' do
expect(second_row.text).to include('Foo Bar') visit admin_users_path(search_query: 'Foo')
end
it 'sorts search results only' do expect(page).to have_content('Foo Bar')
visit admin_users_path(search_query: 'Foo') expect(page).to have_content('Foo Baz')
expect(page).not_to have_content('Dmitriy')
end
sort_by('Name') it 'sorts users by name' do
visit admin_users_path
expect(page).not_to have_content('Dmitriy') sort_by('Name')
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
it 'searches with respect of sorting' do expect(first_row.text).to include('Dmitriy')
visit admin_users_path(sort: 'Name') expect(second_row.text).to include('Foo Bar')
end
fill_in :search_query, with: 'Foo' it 'sorts search results only' do
click_button('Search users') visit admin_users_path(search_query: 'Foo')
expect(first_row.text).to include('Foo Bar') sort_by('Name')
expect(second_row.text).to include('Foo Baz') expect(page).not_to have_content('Dmitriy')
end expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
it 'sorts users by recent last activity' do it 'searches with respect of sorting' do
visit admin_users_path(search_query: 'Foo') visit admin_users_path(sort: 'Name')
sort_by('Recent last activity') fill_in :search_query, with: 'Foo'
click_button('Search users')
expect(first_row.text).to include('Foo Baz') expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Bar') expect(second_row.text).to include('Foo Baz')
end end
it 'sorts users by oldest last activity' do it 'sorts users by recent last activity' do
visit admin_users_path(search_query: 'Foo') visit admin_users_path(search_query: 'Foo')
sort_by('Oldest last activity') sort_by('Recent last activity')
expect(first_row.text).to include('Foo Bar') expect(first_row.text).to include('Foo Baz')
expect(second_row.text).to include('Foo Baz') expect(second_row.text).to include('Foo Bar')
end end
end
describe 'Two-factor Authentication filters' do it 'sorts users by oldest last activity' do
it 'counts users who have enabled 2FA' do visit admin_users_path(search_query: 'Foo')
create(:user, :two_factor)
visit admin_users_path sort_by('Oldest last activity')
page.within('.filter-two-factor-enabled small') do expect(first_row.text).to include('Foo Bar')
expect(page).to have_content('1') expect(second_row.text).to include('Foo Baz')
end
end end
end
it 'filters by users who have enabled 2FA' do describe 'Two-factor Authentication filters' do
user = create(:user, :two_factor) it 'counts users who have enabled 2FA' do
create(:user, :two_factor)
visit admin_users_path visit admin_users_path
click_link '2FA Enabled'
expect(page).to have_content(user.email) page.within('.filter-two-factor-enabled small') do
end expect(page).to have_content('1')
end
end
it 'counts users who have not enabled 2FA' do it 'filters by users who have enabled 2FA' do
visit admin_users_path user = create(:user, :two_factor)
page.within('.filter-two-factor-disabled small') do visit admin_users_path
expect(page).to have_content('2') # Including admin click_link '2FA Enabled'
end
end
it 'filters by users who have not enabled 2FA' do expect(page).to have_content(user.email)
visit admin_users_path end
click_link '2FA Disabled'
expect(page).to have_content(user.email) it 'counts users who have not enabled 2FA' do
end visit admin_users_path
end
describe 'Pending approval filter' do page.within('.filter-two-factor-disabled small') do
it 'counts users who are pending approval' do expect(page).to have_content('2') # Including admin
create_list(:user, 2, :blocked_pending_approval) end
end
visit admin_users_path it 'filters by users who have not enabled 2FA' do
visit admin_users_path
click_link '2FA Disabled'
page.within('.filter-blocked-pending-approval small') do expect(page).to have_content(user.email)
expect(page).to have_content('2') end
end end
end
it 'filters by users who are pending approval' do describe 'Pending approval filter' do
user = create(:user, :blocked_pending_approval) it 'counts users who are pending approval' do
create_list(:user, 2, :blocked_pending_approval)
visit admin_users_path visit admin_users_path
click_link 'Pending approval'
expect(page).to have_content(user.email) page.within('.filter-blocked-pending-approval small') do
end expect(page).to have_content('2')
end end
end
context 'when blocking/unblocking a user' do it 'filters by users who are pending approval' do
it 'shows confirmation and allows blocking and unblocking', :js do user = create(:user, :blocked_pending_approval)
expect(page).to have_content(user.email)
click_action_in_user_dropdown(user.id, 'Block') visit admin_users_path
click_link 'Pending approval'
wait_for_requests expect(page).to have_content(user.email)
end
end
expect(page).to have_content('Block user') context 'when blocking/unblocking a user' do
expect(page).to have_content('Blocking user has the following effects') it 'shows confirmation and allows blocking and unblocking', :js do
expect(page).to have_content('User will not be able to login') expect(page).to have_content(user.email)
expect(page).to have_content('Owned groups will be left')
find('.modal-footer button', text: 'Block').click click_action_in_user_dropdown(user.id, 'Block')
wait_for_requests wait_for_requests
expect(page).to have_content('Successfully blocked') expect(page).to have_content('Block user')
expect(page).not_to have_content(user.email) expect(page).to have_content('Blocking user has the following effects')
expect(page).to have_content('User will not be able to login')
expect(page).to have_content('Owned groups will be left')
click_link 'Blocked' find('.modal-footer button', text: 'Block').click
wait_for_requests wait_for_requests
expect(page).to have_content(user.email) expect(page).to have_content('Successfully blocked')
expect(page).not_to have_content(user.email)
click_action_in_user_dropdown(user.id, 'Unblock') click_link 'Blocked'
expect(page).to have_content('Unblock user') wait_for_requests
expect(page).to have_content('You can always block their account again if needed.')
find('.modal-footer button', text: 'Unblock').click expect(page).to have_content(user.email)
wait_for_requests click_action_in_user_dropdown(user.id, 'Unblock')
expect(page).to have_content('Successfully unblocked') expect(page).to have_content('Unblock user')
expect(page).not_to have_content(user.email) expect(page).to have_content('You can always block their account again if needed.')
end
end
context 'when deactivating/re-activating a user' do find('.modal-footer button', text: 'Unblock').click
it 'shows confirmation and allows deactivating and re-activating', :js do
expect(page).to have_content(user.email)
click_action_in_user_dropdown(user.id, 'Deactivate') wait_for_requests
expect(page).to have_content('Deactivate user') expect(page).to have_content('Successfully unblocked')
expect(page).to have_content('Deactivating a user has the following effects') expect(page).not_to have_content(user.email)
expect(page).to have_content('The user will be logged out') end
expect(page).to have_content('Personal projects, group and user history will be left intact') end
find('.modal-footer button', text: 'Deactivate').click context 'when deactivating/re-activating a user' do
it 'shows confirmation and allows deactivating and re-activating', :js do
expect(page).to have_content(user.email)
wait_for_requests click_action_in_user_dropdown(user.id, 'Deactivate')
expect(page).to have_content('Successfully deactivated') expect(page).to have_content('Deactivate user')
expect(page).not_to have_content(user.email) expect(page).to have_content('Deactivating a user has the following effects')
expect(page).to have_content('The user will be logged out')
expect(page).to have_content('Personal projects, group and user history will be left intact')
click_link 'Deactivated' find('.modal-footer button', text: 'Deactivate').click
wait_for_requests wait_for_requests
expect(page).to have_content(user.email) expect(page).to have_content('Successfully deactivated')
expect(page).not_to have_content(user.email)
click_action_in_user_dropdown(user.id, 'Activate') click_link 'Deactivated'
expect(page).to have_content('Activate user') wait_for_requests
expect(page).to have_content('You can always deactivate their account again if needed.')
find('.modal-footer button', text: 'Activate').click expect(page).to have_content(user.email)
wait_for_requests click_action_in_user_dropdown(user.id, 'Activate')
expect(page).to have_content('Successfully activated') expect(page).to have_content('Activate user')
expect(page).not_to have_content(user.email) expect(page).to have_content('You can always deactivate their account again if needed.')
end
end
def click_action_in_user_dropdown(user_id, action) find('.modal-footer button', text: 'Activate').click
find("[data-testid='user-action-button-#{user_id}']").click
within find("[data-testid='user-action-dropdown-#{user_id}']") do wait_for_requests
find('li button', text: action).click
end
wait_for_requests expect(page).to have_content('Successfully activated')
expect(page).not_to have_content(user.email)
end
end
end
end end
end end
describe 'GET /admin/users/new' do describe 'GET /admin/users/new' do
let(:user_username) { 'bang' } let_it_be(:user_username) { 'bang' }
before do before do
visit new_admin_user_path visit new_admin_user_path
...@@ -344,7 +351,7 @@ RSpec.describe 'Admin::Users' do ...@@ -344,7 +351,7 @@ RSpec.describe 'Admin::Users' do
end end
context 'username contains spaces' do context 'username contains spaces' do
let(:user_username) { 'Bing bang' } let_it_be(:user_username) { 'Bing bang' }
it "doesn't create the user and shows an error message" do it "doesn't create the user and shows an error message" do
expect { click_button 'Create user' }.to change {User.count}.by(0) expect { click_button 'Create user' }.to change {User.count}.by(0)
...@@ -363,22 +370,6 @@ RSpec.describe 'Admin::Users' do ...@@ -363,22 +370,6 @@ RSpec.describe 'Admin::Users' do
visit new_admin_user_path visit new_admin_user_path
end end
def expects_external_to_be_checked
expect(find('#user_external')).to be_checked
end
def expects_external_to_be_unchecked
expect(find('#user_external')).not_to be_checked
end
def expects_warning_to_be_hidden
expect(find('#warning_external_automatically_set', visible: :all)[:class]).to include 'hidden'
end
def expects_warning_to_be_shown
expect(find('#warning_external_automatically_set')[:class]).not_to include 'hidden'
end
it 'automatically unchecks external for matching email' do it 'automatically unchecks external for matching email' do
expects_external_to_be_checked expects_external_to_be_checked
expects_warning_to_be_hidden expects_warning_to_be_hidden
...@@ -413,55 +404,22 @@ RSpec.describe 'Admin::Users' do ...@@ -413,55 +404,22 @@ RSpec.describe 'Admin::Users' do
expect(new_user.external).to be_falsy expect(new_user.external).to be_falsy
end end
end
end
end
describe 'GET /admin/users/:id/edit' do
before do
stub_feature_flags(vue_admin_users: false)
visit admin_users_path
click_link "edit_user_#{user.id}"
end
it 'has user edit page' do
expect(page).to have_content('Name')
expect(page).to have_content('Password')
end
describe 'Update user' do
before do
fill_in 'user_name', with: 'Big Bang'
fill_in 'user_email', with: 'bigbang@mail.com'
fill_in 'user_password', with: 'AValidPassword1'
fill_in 'user_password_confirmation', with: 'AValidPassword1'
choose 'user_access_level_admin'
click_button 'Save changes'
end
it 'shows page with new data' do def expects_external_to_be_checked
expect(page).to have_content('bigbang@mail.com') expect(find('#user_external')).to be_checked
expect(page).to have_content('Big Bang') end
end
it 'changes user entry' do
user.reload
expect(user.name).to eq('Big Bang')
expect(user.admin?).to be_truthy
expect(user.password_expires_at).to be <= Time.now
end
end
describe 'update username to non ascii char' do def expects_external_to_be_unchecked
it do expect(find('#user_external')).not_to be_checked
fill_in 'user_username', with: '\u3042\u3044' end
click_button('Save')
page.within '#error_explanation' do def expects_warning_to_be_hidden
expect(page).to have_content('Username') expect(find('#warning_external_automatically_set', visible: :all)[:class]).to include 'hidden'
end end
expect(page).to have_selector(%(form[action="/admin/users/#{user.username}"])) def expects_warning_to_be_shown
expect(find('#warning_external_automatically_set')[:class]).not_to include 'hidden'
end
end end
end end
end end
...@@ -541,15 +499,82 @@ RSpec.describe 'Admin::Users' do ...@@ -541,15 +499,82 @@ RSpec.describe 'Admin::Users' do
check_breadcrumb('Edit Identity') check_breadcrumb('Edit Identity')
end end
def check_breadcrumb(content)
expect(find('.breadcrumbs-sub-title')).to have_content(content)
end
end
describe 'GET /admin/users/:id/edit' do
before do
visit edit_admin_user_path(user)
end
describe 'Update user' do
before do
fill_in 'user_name', with: 'Big Bang'
fill_in 'user_email', with: 'bigbang@mail.com'
fill_in 'user_password', with: 'AValidPassword1'
fill_in 'user_password_confirmation', with: 'AValidPassword1'
choose 'user_access_level_admin'
click_button 'Save changes'
end
it 'shows page with new data' do
expect(page).to have_content('bigbang@mail.com')
expect(page).to have_content('Big Bang')
end
it 'changes user entry' do
user.reload
expect(user.name).to eq('Big Bang')
expect(user.admin?).to be_truthy
expect(user.password_expires_at).to be <= Time.now
end
end
describe 'update username to non ascii char' do
it do
fill_in 'user_username', with: '\u3042\u3044'
click_button('Save')
page.within '#error_explanation' do
expect(page).to have_content('Username')
end
expect(page).to have_selector(%(form[action="/admin/users/#{user.username}"]))
end
end
end end
def check_breadcrumb(content) def click_user_dropdown_toggle(user_id)
expect(find('.breadcrumbs-sub-title')).to have_content(content) page.within("[data-testid='user-actions-#{user_id}']") do
find("[data-testid='dropdown-toggle']").click
end
end
def first_row
page.all('[role="row"]')[1]
end
def second_row
page.all('[role="row"]')[2]
end end
def sort_by(text) def sort_by(option)
page.within('.user-sort-dropdown') do page.within('.filtered-search-block') do
click_link text find('.dropdown-menu-toggle').click
click_link option
end end
end end
def click_action_in_user_dropdown(user_id, action)
click_user_dropdown_toggle(user_id)
within find("[data-testid='user-actions-#{user_id}']") do
find('li button', text: action).click
end
wait_for_requests
end
end end
import { GlDropdownDivider } from '@gitlab/ui'; import { GlDropdownDivider } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import Actions from '~/admin/users/components/actions'; import Actions from '~/admin/users/components/actions';
import AdminUserActions from '~/admin/users/components/user_actions.vue'; import AdminUserActions from '~/admin/users/components/user_actions.vue';
import { I18N_USER_ACTIONS } from '~/admin/users/constants'; import { I18N_USER_ACTIONS } from '~/admin/users/constants';
...@@ -14,12 +14,14 @@ describe('AdminUserActions component', () => { ...@@ -14,12 +14,14 @@ describe('AdminUserActions component', () => {
const user = users[0]; const user = users[0];
const userPaths = generateUserPaths(paths, user.username); const userPaths = generateUserPaths(paths, user.username);
const findEditButton = () => wrapper.find('[data-testid="edit"]'); const findUserActions = (id) => wrapper.findByTestId(`user-actions-${id}`);
const findActionsDropdown = () => wrapper.find('[data-testid="actions"'); const findEditButton = (id = user.id) => findUserActions(id).find('[data-testid="edit"]');
const findDropdownDivider = () => wrapper.find(GlDropdownDivider); const findActionsDropdown = (id = user.id) =>
findUserActions(id).find('[data-testid="dropdown-toggle"]');
const findDropdownDivider = () => wrapper.findComponent(GlDropdownDivider);
const initComponent = ({ actions = [] } = {}) => { const initComponent = ({ actions = [] } = {}) => {
wrapper = shallowMount(AdminUserActions, { wrapper = shallowMountExtended(AdminUserActions, {
propsData: { propsData: {
user: { user: {
...user, ...user,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment