Commit 987ce34c authored by Albert Salim's avatar Albert Salim

Merge branch '290737-remove-vue-admin-users-feature-flag' into 'master'

Remove vue_admin_users feature flag [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!61129
parents 3621b7dc 12e3dfbe
......@@ -107,6 +107,7 @@ export default {
:items="users"
:fields="$options.fields"
:empty-text="s__('AdminUsers|No users found')"
data-qa-selector="user_row_content"
show-empty
stacked="md"
:tbody-tr-attr="{ 'data-qa-selector': 'user_row_content' }"
......
.gl-responsive-table-row{ role: 'row', data: { qa_selector: 'user_row_content' } }
.table-section.section-40
.table-mobile-header{ role: 'rowheader' }
= _('Name')
.table-mobile-content
= render 'user_detail', user: user
.table-section.section-10
.table-mobile-header{ role: 'rowheader' }
= _('Projects')
.table-mobile-content.gl-str-truncated{ data: { testid: "user-project-count-#{user.id}" } }
= user.authorized_projects.length
.table-section.section-15
.table-mobile-header{ role: 'rowheader' }
= _('Created on')
.table-mobile-content
= l(user.created_at.to_date, format: :admin)
.table-section.section-15
.table-mobile-header{ role: 'rowheader' }
= _('Last activity')
.table-mobile-content
= user.last_activity_on.nil? ? _('Never') : l(user.last_activity_on, format: :admin)
- unless user.internal?
.table-section.section-20.table-button-footer
.table-action-buttons{ data: { testid: "user-actions-#{user.id}" } }
= link_to _('Edit'), edit_admin_user_path(user), class: 'btn gl-button btn-default'
- unless user == current_user
%button.dropdown-new.btn.gl-button.btn-default{ type: 'button', data: { testid: "dropdown-toggle", toggle: 'dropdown' } }
= sprite_icon('settings')
= sprite_icon('chevron-down')
%ul.dropdown-menu.dropdown-menu-right
%li.dropdown-header
= _('Settings')
%li
- if user.ldap_blocked?
%span.small
= s_('AdminUsers|Cannot unblock LDAP blocked users')
- elsif user.blocked?
- if user.blocked_pending_approval?
= link_to s_('AdminUsers|Approve'), approve_admin_user_path(user), method: :put
= link_to s_('AdminUsers|Reject'), reject_admin_user_path(user), method: :delete
- else
%button.gl-button.btn.btn-default-tertiary.js-confirm-modal-button{ data: user_unblock_data(user) }
= s_('AdminUsers|Unblock')
- else
%button.gl-button.btn.btn-default-tertiary.js-confirm-modal-button{ data: user_block_data(user, user_block_effects) }
= s_('AdminUsers|Block')
- if user.can_be_deactivated?
%li
%button.gl-button.btn.btn-default-tertiary.js-confirm-modal-button{ data: user_deactivation_data(user, user_deactivation_effects) }
= s_('AdminUsers|Deactivate')
- elsif user.deactivated?
%li
%button.gl-button.btn.btn-default-tertiary.js-confirm-modal-button{ data: user_activation_data(user) }
= s_('AdminUsers|Activate')
- if user.access_locked?
%li
= link_to _('Unlock'), unlock_admin_user_path(user), method: :put, data: { confirm: _('Are you sure?') }
- if can?(current_user, :destroy_user, user) && !user.blocked_pending_approval?
%li.divider
- if user.can_be_removed?
%li
%button.js-delete-user-modal-button.gl-button.btn.btn-danger-tertiary{ data: { 'gl-modal-action': 'delete',
delete_user_url: admin_user_path(user),
block_user_url: block_admin_user_path(user),
username: sanitize_name(user.name) } }
= s_('AdminUsers|Delete user')
%li
%button.js-delete-user-modal-button.gl-button.btn.btn-danger-tertiary{ data: { 'gl-modal-action': 'delete-with-contributions',
delete_user_url: admin_user_path(user, hard_delete: true),
block_user_url: block_admin_user_path(user),
username: sanitize_name(user.name) } }
= s_('AdminUsers|Delete user and contributions')
......@@ -73,20 +73,9 @@
= link_to admin_users_path(sort: value, filter: params[:filter], search_query: params[:search_query]) do
= title
- if Feature.enabled?(:vue_admin_users, default_enabled: :yaml)
#js-admin-users-app{ data: admin_users_data_attributes(@users) }
.gl-spinner-container.gl-my-7
%span.gl-vertical-align-bottom.gl-spinner.gl-spinner-dark.gl-spinner-lg{ aria: { label: _('Loading') } }
- elsif @users.empty?
.nothing-here-block.border-top-0
= s_('AdminUsers|No users found')
- else
.table-holder
.thead-white.text-nowrap.gl-responsive-table-row.table-row-header{ role: 'row' }
- user_table_headers.each do |header|
.table-section{ class: header[:section_class_name], role: 'rowheader' }= header[:header_text]
= render partial: 'admin/users/user', collection: @users
#js-admin-users-app{ data: admin_users_data_attributes(@users) }
.gl-spinner-container.gl-my-7
%span.gl-vertical-align-bottom.gl-spinner.gl-spinner-dark.gl-spinner-lg{ aria: { label: _('Loading') } }
= paginate_collection @users
......
---
name: vue_admin_users
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/48922
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/290737
milestone: '13.7'
type: development
group: group::compliance
default_enabled: true
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe "Admin::Users" do
RSpec.describe "Admin::Users", :js do
let_it_be(:user) { create(:omniauth_user, provider: 'twitter', extern_uid: '123456') }
let_it_be(:current_user) { create(:admin) }
......@@ -11,171 +11,163 @@ RSpec.describe "Admin::Users" do
gitlab_enable_admin_mode_sign_in(current_user)
end
[true, false].each do |vue_admin_users|
context "with vue_admin_users feature flag set to #{vue_admin_users}", js: vue_admin_users do
before do
stub_feature_flags(vue_admin_users: vue_admin_users)
end
describe 'GET /admin/users' do
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
describe 'GET /admin/users' do
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
it "shows the 'Send email to users' link" do
visit admin_users_path
it "shows the 'Send email to users' link" do
visit admin_users_path
expect(page).to have_link(href: admin_email_path)
end
end
expect(page).to have_link(href: admin_email_path)
end
end
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
end
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
end
it "does not show the 'Send email to users' link" do
visit admin_users_path
it "does not show the 'Send email to users' link" do
visit admin_users_path
expect(page).not_to have_link(href: admin_email_path)
end
end
expect(page).not_to have_link(href: admin_email_path)
end
end
end
describe 'user permission export' do
context 'when `export_user_permissions` feature is available' do
before do
stub_licensed_features(export_user_permissions: true)
end
describe 'user permission export' do
context 'when `export_user_permissions` feature is available' do
before do
stub_licensed_features(export_user_permissions: true)
end
it "shows the 'Export Permissions' link" do
visit admin_users_path
it "shows the 'Export Permissions' link" do
visit admin_users_path
expect(page).to have_link(href: admin_user_permission_exports_path(format: :csv))
end
end
expect(page).to have_link(href: admin_user_permission_exports_path(format: :csv))
end
end
context 'when `export_user_permissions` feature is disabled' do
before do
stub_licensed_features(export_user_permissions: false)
end
context 'when `export_user_permissions` feature is disabled' do
before do
stub_licensed_features(export_user_permissions: false)
end
it "does not show the 'Export Permissions' link" do
visit admin_users_path
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
expect(page).not_to have_link(href: admin_user_permission_exports_path(format: :csv))
end
end
end
end
describe "GET /admin/users/:id" do
describe 'Shared runners quota status' do
before do
user.namespace.update!(shared_runners_minutes_limit: 500)
end
describe "GET /admin/users/:id" do
describe 'Shared runners quota status' do
before do
user.namespace.update!(shared_runners_minutes_limit: 500)
end
context 'with projects with shared runners enabled' do
before do
create(:project, namespace: user.namespace, shared_runners_enabled: true)
end
context 'with projects with shared runners enabled' do
before do
create(:project, namespace: user.namespace, shared_runners_enabled: true)
end
it 'shows quota' do
visit admin_users_path
it 'shows quota' do
visit admin_users_path
click_link user.name
click_link user.name
expect(page).to have_content('Pipeline minutes quota: 0 / 500')
end
end
expect(page).to have_content('Pipeline minutes quota: 0 / 500')
end
end
context 'without projects with shared runners enabled' do
before do
create(:project, namespace: user.namespace, shared_runners_enabled: false)
end
context 'without projects with shared runners enabled' do
before do
create(:project, namespace: user.namespace, shared_runners_enabled: false)
end
it 'does not show quota' do
visit admin_users_path
it 'does not show quota' do
visit admin_users_path
click_link user.name
click_link user.name
expect(page).not_to have_content('Pipeline minutes quota:')
end
end
expect(page).not_to have_content('Pipeline minutes quota:')
end
end
end
end
describe "GET /admin/users/:id/edit" do
describe "Update user account type" do
before do
visit_edit_user(user.id)
describe "GET /admin/users/:id/edit" do
describe "Update user account type" do
before do
visit_edit_user(user.id)
allow_any_instance_of(AuditorUserHelper).to receive(:license_allows_auditor_user?).and_return(true)
choose "user_access_level_auditor"
click_button "Save changes"
end
allow_any_instance_of(AuditorUserHelper).to receive(:license_allows_auditor_user?).and_return(true)
choose "user_access_level_auditor"
click_button "Save changes"
end
it "changes account type to be auditor" do
user.reload
it "changes account type to be auditor" do
user.reload
expect(user).not_to be_admin
expect(user).to be_auditor
end
end
expect(user).not_to be_admin
expect(user).to be_auditor
end
end
describe 'Update shared runners quota' do
let_it_be(:project) { create(:project, namespace: user.namespace, shared_runners_enabled: true) }
describe 'Update shared runners quota' do
let_it_be(:project) { create(:project, namespace: user.namespace, shared_runners_enabled: true) }
it "shows page with new data" do
visit_edit_user(user.id)
fill_in "user_namespace_attributes_shared_runners_minutes_limit", with: "500"
it "shows page with new data" do
visit_edit_user(user.id)
fill_in "user_namespace_attributes_shared_runners_minutes_limit", with: "500"
click_button "Save changes"
click_button "Save changes"
expect(page).to have_content('Pipeline minutes quota: 0 / 500')
end
end
expect(page).to have_content('Pipeline minutes quota: 0 / 500')
end
end
def visit_edit_user(user_id)
visit admin_users_path
def visit_edit_user(user_id)
visit admin_users_path
page.within("[data-testid='user-actions-#{user_id}']") do
click_link 'Edit'
end
end
page.within("[data-testid='user-actions-#{user_id}']") do
click_link 'Edit'
end
end
end
describe 'show user keys for SSH and LDAP' do
let_it_be(:key1) do
create(:ldap_key, user: user, title: "LDAP Key1")
end
describe 'show user keys for SSH and LDAP' do
let_it_be(:key1) do
create(:ldap_key, user: user, title: "LDAP Key1")
end
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")
end
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")
end
it 'only shows the delete button for regular keys' do
visit admin_users_path
it 'only shows the delete button for regular keys' do
visit admin_users_path
click_link user.name
click_link 'SSH keys'
click_link user.name
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
within('ul.content-list li.key-list-item:nth-of-type(1)') do
expect(page).to have_content(key2.title)
expect(page).to have_button('Delete')
end
# SSH key should be the first in the list
within('ul.content-list li.key-list-item:nth-of-type(1)') do
expect(page).to have_content(key2.title)
expect(page).to have_button('Delete')
end
# Next, LDAP key
within('ul.content-list li.key-list-item:nth-of-type(2)') do
expect(page).to have_content(key1.title)
expect(page).not_to have_button('Delete')
end
end
# Next, LDAP key
within('ul.content-list li.key-list-item:nth-of-type(2)') do
expect(page).to have_content(key1.title)
expect(page).not_to have_button('Delete')
end
end
end
......
......@@ -84,8 +84,8 @@ tests = [
{
explanation: 'FOSS views should map to respective spec',
source: 'app/views/admin/users/_user.html.haml',
expected: ['spec/views/admin/users/_user.html.haml_spec.rb']
source: 'app/views/admin/dashboard/index.html.haml',
expected: ['spec/views/admin/dashboard/index.html.haml_spec.rb']
},
{
......
......@@ -356,27 +356,19 @@ RSpec.describe 'Admin::Users::User' do
end
end
[true, false].each do |vue_admin_users|
context "with vue_admin_users feature flag set to #{vue_admin_users}", js: vue_admin_users do
before do
stub_feature_flags(vue_admin_users: vue_admin_users)
end
describe 'GET /admin/users' do
context 'user pending approval' do
it 'shows user info', :aggregate_failures do
user = create(:user, :blocked_pending_approval)
describe 'GET /admin/users', :js do
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
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
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
......
......@@ -11,291 +11,300 @@ RSpec.describe 'Admin::Users' do
gitlab_enable_admin_mode_sign_in(current_user)
end
[true, false].each do |vue_admin_users|
context "with vue_admin_users feature flag set to #{vue_admin_users}", js: vue_admin_users do
before do
stub_feature_flags(vue_admin_users: vue_admin_users)
end
describe 'GET /admin/users', :js do
before do
visit admin_users_path
end
describe 'GET /admin/users' do
before do
visit admin_users_path
end
it "is ok" do
expect(current_path).to eq(admin_users_path)
end
it "is ok" do
expect(current_path).to eq(admin_users_path)
end
it "has users list" do
current_user.reload
it "has users list" do
current_user.reload
expect(page).to have_content(current_user.email)
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_content(current_user.email)
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')
click_user_dropdown_toggle(user.id)
click_user_dropdown_toggle(user.id)
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
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
it 'clicking edit user takes us to edit page', :aggregate_failures do
page.within("[data-testid='user-actions-#{user.id}']") do
click_link 'Edit'
end
it 'clicking edit user takes us to edit page', :aggregate_failures do
page.within("[data-testid='user-actions-#{user.id}']") do
click_link 'Edit'
end
expect(page).to have_content('Name')
expect(page).to have_content('Password')
end
expect(page).to have_content('Name')
expect(page).to have_content('Password')
end
describe 'view extra user information' do
it 'shows the user popover on hover', :js, quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/11290' do
expect(page).not_to have_selector('#__BV_popover_1__')
describe 'view extra user information' do
it 'shows the user popover on hover', :js, quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/11290' do
expect(page).not_to have_selector('#__BV_popover_1__')
first_user_link = page.first('.js-user-link')
first_user_link.hover
first_user_link = page.first('.js-user-link')
first_user_link.hover
expect(page).to have_selector('#__BV_popover_1__')
end
end
expect(page).to have_selector('#__BV_popover_1__')
end
end
context 'user project count' do
before do
project = create(:project)
project.add_maintainer(current_user)
end
it 'displays count of users projects' do
visit admin_users_path
context 'user project count' do
before do
project = create(:project)
project.add_maintainer(current_user)
end
expect(page.find("[data-testid='user-project-count-#{current_user.id}']").text).to eq("1")
end
end
it 'displays count of users projects' do
visit admin_users_path
describe 'tabs' do
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
expect(page.find("[data-testid='user-project-count-#{current_user.id}']").text).to eq("1")
end
context '`Pending approval` tab' do
before do
visit admin_users_path
end
describe 'tabs' do
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('Banned', href: admin_users_path(filter: 'banned'))
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
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
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
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
it 'searches users by name' do
visit admin_users_path(search_query: 'Foo')
it 'searches users by name' do
visit admin_users_path(search_query: 'Foo')
expect(page).to have_content('Foo Bar')
expect(page).to have_content('Foo Baz')
expect(page).not_to have_content('Dmitriy')
end
expect(page).to have_content('Foo Bar')
expect(page).to have_content('Foo Baz')
expect(page).not_to have_content('Dmitriy')
end
it 'sorts users by name' do
visit admin_users_path
it 'sorts users by name' do
visit admin_users_path
sort_by('Name')
sort_by('Name')
expect(first_row.text).to include('Dmitriy')
expect(second_row.text).to include('Foo Bar')
end
expect(first_row.text).to include('Dmitriy')
expect(second_row.text).to include('Foo Bar')
end
it 'sorts search results only' do
visit admin_users_path(search_query: 'Foo')
it 'sorts search results only' do
visit admin_users_path(search_query: 'Foo')
sort_by('Name')
expect(page).not_to have_content('Dmitriy')
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
sort_by('Name')
expect(page).not_to have_content('Dmitriy')
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
it 'searches with respect of sorting' do
visit admin_users_path(sort: 'Name')
fill_in :search_query, with: 'Foo'
click_button('Search users')
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
it 'searches with respect of sorting' do
visit admin_users_path(sort: 'Name')
it 'sorts users by recent last activity' do
visit admin_users_path(search_query: 'Foo')
fill_in :search_query, with: 'Foo'
click_button('Search users')
sort_by('Recent last activity')
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
expect(first_row.text).to include('Foo Baz')
expect(second_row.text).to include('Foo Bar')
end
it 'sorts users by recent last activity' do
visit admin_users_path(search_query: 'Foo')
it 'sorts users by oldest last activity' do
visit admin_users_path(search_query: 'Foo')
sort_by('Recent last activity')
sort_by('Oldest last activity')
expect(first_row.text).to include('Foo Baz')
expect(second_row.text).to include('Foo Bar')
end
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
end
it 'sorts users by oldest last activity' do
visit admin_users_path(search_query: 'Foo')
describe 'Two-factor Authentication filters' do
it 'counts users who have enabled 2FA' do
create(:user, :two_factor)
sort_by('Oldest last activity')
visit admin_users_path
expect(first_row.text).to include('Foo Bar')
expect(second_row.text).to include('Foo Baz')
end
page.within('.filter-two-factor-enabled small') do
expect(page).to have_content('1')
end
end
describe 'Two-factor Authentication filters' do
it 'counts users who have enabled 2FA' do
create(:user, :two_factor)
it 'filters by users who have enabled 2FA' do
user = create(:user, :two_factor)
visit admin_users_path
visit admin_users_path
click_link '2FA Enabled'
page.within('.filter-two-factor-enabled small') do
expect(page).to have_content('1')
end
end
expect(page).to have_content(user.email)
end
it 'filters by users who have enabled 2FA' do
user = create(:user, :two_factor)
it 'counts users who have not enabled 2FA' do
visit admin_users_path
visit admin_users_path
click_link '2FA Enabled'
page.within('.filter-two-factor-disabled small') do
expect(page).to have_content('2') # Including admin
end
end
expect(page).to have_content(user.email)
end
it 'filters by users who have not enabled 2FA' do
visit admin_users_path
click_link '2FA Disabled'
it 'counts users who have not enabled 2FA' do
visit admin_users_path
expect(page).to have_content(user.email)
end
end
page.within('.filter-two-factor-disabled small') do
expect(page).to have_content('2') # Including admin
end
end
describe 'Pending approval filter' do
it 'counts users who are pending approval' do
create_list(:user, 2, :blocked_pending_approval)
it 'filters by users who have not enabled 2FA' do
visit admin_users_path
click_link '2FA Disabled'
visit admin_users_path
expect(page).to have_content(user.email)
end
page.within('.filter-blocked-pending-approval small') do
expect(page).to have_content('2')
end
end
describe 'Pending approval filter' do
it 'counts users who are pending approval' do
create_list(:user, 2, :blocked_pending_approval)
it 'filters by users who are pending approval' do
user = create(:user, :blocked_pending_approval)
visit admin_users_path
visit admin_users_path
click_link 'Pending approval'
page.within('.filter-blocked-pending-approval small') do
expect(page).to have_content('2')
end
end
expect(page).to have_content(user.email)
end
end
it 'filters by users who are pending approval' do
user = create(:user, :blocked_pending_approval)
context 'when blocking/unblocking a user' do
it 'shows confirmation and allows blocking and unblocking', :js do
expect(page).to have_content(user.email)
visit admin_users_path
click_link 'Pending approval'
click_action_in_user_dropdown(user.id, 'Block')
expect(page).to have_content(user.email)
end
end
wait_for_requests
expect(page).to have_content('Block user')
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')
context 'when blocking/unblocking a user' do
it 'shows confirmation and allows blocking and unblocking', :js do
expect(page).to have_content(user.email)
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).not_to have_content(user.email)
expect(page).to have_content('Block user')
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')
expect(page).to have_content('You can always block their account again if needed.')
wait_for_requests
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).not_to have_content(user.email)
end
end
expect(page).to have_content('Unblock user')
expect(page).to have_content('You can always block their account again if needed.')
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)
find('.modal-footer button', text: 'Unblock').click
click_action_in_user_dropdown(user.id, 'Deactivate')
wait_for_requests
expect(page).to have_content('Deactivate user')
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')
expect(page).to have_content('Successfully unblocked')
expect(page).not_to have_content(user.email)
end
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).not_to have_content(user.email)
expect(page).to have_content('Deactivate user')
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')
expect(page).to have_content('You can always deactivate their account again if needed.')
wait_for_requests
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).not_to have_content(user.email)
end
end
expect(page).to have_content('Activate user')
expect(page).to have_content('You can always deactivate their account again if needed.')
describe 'internal users' do
context 'when showing a `Ghost User`' do
let_it_be(:ghost_user) { create(:user, :ghost) }
find('.modal-footer button', text: 'Activate').click
it 'does not render actions dropdown' do
expect(page).not_to have_css("[data-testid='user-actions-#{ghost_user.id}'] [data-testid='dropdown-toggle']")
end
end
wait_for_requests
context 'when showing a `Bot User`' do
let_it_be(:bot_user) { create(:user, user_type: :alert_bot) }
expect(page).to have_content('Successfully activated')
expect(page).not_to have_content(user.email)
end
it 'does not render actions dropdown' do
expect(page).not_to have_css("[data-testid='user-actions-#{bot_user.id}'] [data-testid='dropdown-toggle']")
end
end
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'admin/users/_user.html.haml' do
before do
allow(view).to receive(:user).and_return(user)
end
context 'internal users' do
context 'when showing a `Ghost User`' do
let(:user) { create(:user, :ghost) }
it 'does not render action buttons' do
render
expect(rendered).not_to have_selector('.table-action-buttons')
end
end
context 'when showing a `Bot User`' do
let(:user) { create(:user, user_type: :alert_bot) }
it 'does not render action buttons' do
render
expect(rendered).not_to have_selector('.table-action-buttons')
end
end
context 'when showing a `Migration User`' do
let(:user) { create(:user, user_type: :migration_bot) }
it 'does not render action buttons' do
render
expect(rendered).not_to have_selector('.table-action-buttons')
end
end
end
context 'when showing an external user' do
let(:user) { create(:user) }
it 'renders action buttons' do
render
expect(rendered).to have_selector('.table-action-buttons')
end
end
end
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