Commit 62d706c5 authored by Brandon Labuschagne's avatar Brandon Labuschagne

Merge branch 'peterhegman/admin-users-move-confirm-button' into 'master'

Move "Confirm user" button into header of Admin area

See merge request gitlab-org/gitlab!64812
parents 460736b1 dbdbaf6a
......@@ -231,6 +231,34 @@ module UsersHelper
}
end
def confirm_user_data(user)
message = if user.unconfirmed_email.present?
_('This user has an unconfirmed email address (%{email}). You may force a confirmation.') % { email: user.unconfirmed_email }
else
_('This user has an unconfirmed email address. You may force a confirmation.')
end
modal_attributes = Gitlab::Json.dump({
title: s_('AdminUsers|Confirm user %{username}?') % { username: sanitize_name(user.name) },
messageHtml: message,
actionPrimary: {
text: s_('AdminUsers|Confirm user'),
attributes: [{ variant: 'info', 'data-qa-selector': 'confirm_user_confirm_button' }]
},
actionSecondary: {
text: _('Cancel'),
attributes: [{ variant: 'default' }]
}
})
{
path: confirm_admin_user_path(user),
method: 'put',
modal_attributes: modal_attributes,
qa_selector: 'confirm_user_button'
}
end
def user_deactivation_effects
header = tag.p s_('AdminUsers|Deactivating a user has the following effects:')
......
......@@ -22,11 +22,16 @@
= render_if_exists 'admin/users/gma_user_badge'
.float-right
- if impersonation_enabled? && @user != current_user && @user.can?(:log_in)
= link_to _('Impersonate'), impersonate_admin_user_path(@user), method: :post, class: "btn btn-info gl-button btn-grouped", data: { qa_selector: 'impersonate_user_link' }
= link_to edit_admin_user_path(@user), class: "btn btn-default gl-button btn-grouped" do
= sprite_icon('pencil-square', css_class: 'gl-icon gl-button-icon')
= _('Edit')
- if @user != current_user
- if impersonation_enabled? && @user.can?(:log_in)
= link_to _('Impersonate'), impersonate_admin_user_path(@user), method: :post, class: "btn btn-default gl-button btn-grouped", data: { qa_selector: 'impersonate_user_link' }
- if can_force_email_confirmation?(@user)
%button.btn.gl-button.btn-info.btn-grouped.js-confirm-modal-button{ data: confirm_user_data(@user) }
= _('Confirm user')
%hr
%ul.nav-links.nav.nav-tabs
= nav_link(path: 'users#show') do
......
......@@ -141,17 +141,6 @@
.col-md-6
- unless @user == current_user
- if can_force_email_confirmation?(@user)
.gl-card.border-info.gl-mb-5
.gl-card-header.bg-info.text-white
= _('Confirm user')
.gl-card-body
- if @user.unconfirmed_email.present?
- email = " (#{@user.unconfirmed_email})"
%p= _('This user has an unconfirmed email address %{email}. You may force a confirmation.') % { email: email }
%br
= link_to _('Confirm user'), confirm_admin_user_path(@user), method: :put, class: "btn gl-button btn-info", data: { confirm: _('Are you sure?'), qa_selector: 'confirm_user_button' }
= render 'admin/users/user_detail_note'
- unless @user.internal?
......
......@@ -2569,6 +2569,12 @@ msgstr ""
msgid "AdminUsers|Cohorts"
msgstr ""
msgid "AdminUsers|Confirm user"
msgstr ""
msgid "AdminUsers|Confirm user %{username}?"
msgstr ""
msgid "AdminUsers|Could not load user group counts. Please refresh the page to try again."
msgstr ""
......@@ -33543,7 +33549,10 @@ msgstr ""
msgid "This user does not have a pending request"
msgstr ""
msgid "This user has an unconfirmed email address %{email}. You may force a confirmation."
msgid "This user has an unconfirmed email address (%{email}). You may force a confirmation."
msgstr ""
msgid "This user has an unconfirmed email address. You may force a confirmation."
msgstr ""
msgid "This user has been temporarily locked due to excessive number of failed logins. You may manually unlock the account."
......
......@@ -11,7 +11,6 @@ module QA
end
view 'app/views/admin/users/show.html.haml' do
element :confirm_user_button
element :user_id_content
end
......@@ -19,6 +18,11 @@ module QA
element :approve_user_button
end
view 'app/helpers/users_helper.rb' do
element :confirm_user_button
element :confirm_user_confirm_button
end
def click_impersonate_user
click_element(:impersonate_user_link)
end
......@@ -28,9 +32,8 @@ module QA
end
def confirm_user
accept_confirm do
click_element :confirm_user_button
end
click_element :confirm_user_button
click_element :confirm_user_confirm_button
end
def approve_user
......
......@@ -364,4 +364,36 @@ RSpec.describe UsersHelper do
expect(data[:paths]).to match_schema('entities/admin_users_data_attributes_paths')
end
end
describe '#confirm_user_data' do
confirm_admin_user_path = '/admin/users/root/confirm'
before do
allow(helper).to receive(:confirm_admin_user_path).with(user).and_return(confirm_admin_user_path)
end
subject(:confirm_user_data) { helper.confirm_user_data(user) }
it 'sets `path` key correctly' do
expect(confirm_user_data[:path]).to eq(confirm_admin_user_path)
end
it 'sets `modal_attributes` key to valid json' do
expect(confirm_user_data[:modal_attributes]).to be_valid_json
end
context 'when `user.unconfirmed_email` is set' do
let(:user) { create(:user, unconfirmed_email: 'foo@bar.com') }
it 'sets `modal_attributes.messageHtml` correctly' do
expect(Gitlab::Json.parse(confirm_user_data[:modal_attributes])['messageHtml']).to eq('This user has an unconfirmed email address (foo@bar.com). You may force a confirmation.')
end
end
context 'when `user.unconfirmed_email` is not set' do
it 'sets `modal_attributes.messageHtml` correctly' do
expect(Gitlab::Json.parse(confirm_user_data[:modal_attributes])['messageHtml']).to eq('This user has an unconfirmed email address. You may force a confirmation.')
end
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