Commit c8d00787 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'add-resend-confirm-email-admin-page' into 'master'

Add "Confirm user" button to admin page

### What does this MR do?

This MR adds a "Confirm user" to the admin user page.

### Why was this MR needed?

There is no way for an admin to force a user confirmation. Some users create users in the API and then don't have a way to force the user into a confirmed state.

Originally, I attempted to add a link to allow the admin to resend a confirmation e-mail. But that may not be helpful because a user can be in the unconfirmed state with no `unconfirmed_email` set.

### Screenshot

![image](https://gitlab.com/gitlab-org/gitlab-ce/uploads/0571b1e27597289b760a72948ba869e5/image.png)

### What are the relevant issue numbers?

* Closes #2116
* Closes https://github.com/gitlabhq/gitlabhq/issues/9502

See merge request !1067
parents 46a84d80 0c1ccda4
......@@ -3,6 +3,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 7.14.0 (unreleased)
- Fix multi-line syntax highlighting (Stan Hu)
- Fix network graph when branch name has single quotes (Stan Hu)
- Add "Confirm user" button in user admin page (Stan Hu)
- Upgrade gitlab_git to version 7.2.6 to fix Error 500 when creating network graphs (Stan Hu)
- Add support for Unicode filenames in relative links (Hiroyuki Sato)
- Fix URL used for refreshing notes if relative_url is present (Bartłomiej Święcki)
......
......@@ -55,6 +55,14 @@ class Admin::UsersController < Admin::ApplicationController
end
end
def confirm
if user.confirm!
redirect_to :back, notice: "Successfully confirmed"
else
redirect_to :back, alert: "Error occurred. User was not confirmed"
end
end
def disable_two_factor
user.disable_two_factor!
redirect_to admin_user_path(user),
......
......@@ -105,6 +105,16 @@
.col-md-6
- unless @user == current_user
- unless @user.confirmed?
.panel.panel-info
.panel-heading
Confirm user
.panel-body
- if @user.unconfirmed_email.present?
- email = " (#{@user.unconfirmed_email})"
%p This user has an unconfirmed email address#{email}. You may force a confirmation.
%br
= link_to 'Confirm user', confirm_admin_user_path(@user), method: :put, class: "btn btn-info", data: { confirm: 'Are you sure?' }
- if @user.blocked?
.panel.panel-info
.panel-heading
......
......@@ -159,6 +159,7 @@ Gitlab::Application.routes.draw do
put :block
put :unblock
put :unlock
put :confirm
patch :disable_two_factor
delete 'remove/:email_id', action: 'remove_email', as: 'remove_email'
end
......
......@@ -37,6 +37,20 @@ describe Admin::UsersController do
end
end
describe 'PUT confirm/:id' do
let(:user) { create(:user, confirmed_at: nil) }
before do
request.env["HTTP_REFERER"] = "/"
end
it 'confirms user' do
put :confirm, id: user.username
user.reload
expect(user.confirmed?).to be_truthy
end
end
describe 'PATCH disable_two_factor' do
let(:user) { create(:user) }
......
......@@ -184,6 +184,19 @@ describe User do
it { is_expected.to respond_to(:private_token) }
end
describe '#confirm' do
let(:user) { create(:user, confirmed_at: nil, unconfirmed_email: 'test@gitlab.com') }
it 'returns unconfirmed' do
expect(user.confirmed?).to be_falsey
end
it 'confirms a user' do
user.confirm!
expect(user.confirmed?).to be_truthy
end
end
describe '#to_reference' do
let(:user) { create(: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