Commit dbdbaf6a authored by Peter Hegman's avatar Peter Hegman Committed by Brandon Labuschagne

Move "Confirm user" button into header of Admin area

parent 9c80c1a6
...@@ -231,6 +231,34 @@ module UsersHelper ...@@ -231,6 +231,34 @@ module UsersHelper
} }
end 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 def user_deactivation_effects
header = tag.p s_('AdminUsers|Deactivating a user has the following effects:') header = tag.p s_('AdminUsers|Deactivating a user has the following effects:')
......
...@@ -22,11 +22,16 @@ ...@@ -22,11 +22,16 @@
= render_if_exists 'admin/users/gma_user_badge' = render_if_exists 'admin/users/gma_user_badge'
.float-right .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 = 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') = sprite_icon('pencil-square', css_class: 'gl-icon gl-button-icon')
= _('Edit') = _('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 %hr
%ul.nav-links.nav.nav-tabs %ul.nav-links.nav.nav-tabs
= nav_link(path: 'users#show') do = nav_link(path: 'users#show') do
......
...@@ -141,17 +141,6 @@ ...@@ -141,17 +141,6 @@
.col-md-6 .col-md-6
- unless @user == current_user - 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' = render 'admin/users/user_detail_note'
- unless @user.internal? - unless @user.internal?
......
...@@ -2569,6 +2569,12 @@ msgstr "" ...@@ -2569,6 +2569,12 @@ msgstr ""
msgid "AdminUsers|Cohorts" msgid "AdminUsers|Cohorts"
msgstr "" 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." msgid "AdminUsers|Could not load user group counts. Please refresh the page to try again."
msgstr "" msgstr ""
...@@ -33543,7 +33549,10 @@ msgstr "" ...@@ -33543,7 +33549,10 @@ msgstr ""
msgid "This user does not have a pending request" msgid "This user does not have a pending request"
msgstr "" 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 "" msgstr ""
msgid "This user has been temporarily locked due to excessive number of failed logins. You may manually unlock the account." 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 ...@@ -11,7 +11,6 @@ module QA
end end
view 'app/views/admin/users/show.html.haml' do view 'app/views/admin/users/show.html.haml' do
element :confirm_user_button
element :user_id_content element :user_id_content
end end
...@@ -19,6 +18,11 @@ module QA ...@@ -19,6 +18,11 @@ module QA
element :approve_user_button element :approve_user_button
end end
view 'app/helpers/users_helper.rb' do
element :confirm_user_button
element :confirm_user_confirm_button
end
def click_impersonate_user def click_impersonate_user
click_element(:impersonate_user_link) click_element(:impersonate_user_link)
end end
...@@ -28,9 +32,8 @@ module QA ...@@ -28,9 +32,8 @@ module QA
end end
def confirm_user def confirm_user
accept_confirm do click_element :confirm_user_button
click_element :confirm_user_button click_element :confirm_user_confirm_button
end
end end
def approve_user def approve_user
......
...@@ -364,4 +364,36 @@ RSpec.describe UsersHelper do ...@@ -364,4 +364,36 @@ RSpec.describe UsersHelper do
expect(data[:paths]).to match_schema('entities/admin_users_data_attributes_paths') expect(data[:paths]).to match_schema('entities/admin_users_data_attributes_paths')
end end
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 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