summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-07-29 07:32:01 -0700
committerStan Hu <stanhu@gmail.com>2015-08-05 00:35:53 -0700
commit0c1ccda43fe04300a07a5f046a7c1cbae56cff32 (patch)
tree6d8a997d15e58813a78e0f2806543e0b2388f756
parent4c9ba632e9468a0a8f37a031d0be90645ee6be2c (diff)
downloadgitlab-ce-0c1ccda43fe04300a07a5f046a7c1cbae56cff32.tar.gz
Add "Confirm user" button in user admin page
Closes #2116 Closes https://github.com/gitlabhq/gitlabhq/issues/9502
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/admin/users_controller.rb8
-rw-r--r--app/views/admin/users/show.html.haml10
-rw-r--r--config/routes.rb1
-rw-r--r--spec/controllers/admin/users_controller_spec.rb14
-rw-r--r--spec/models/user_spec.rb13
6 files changed, 47 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 8a24bf412d2..dcd2e3203eb 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -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)
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 770fe00af51..6092c79c254 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -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),
diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml
index 33730ff05df..a383ea57384 100644
--- a/app/views/admin/users/show.html.haml
+++ b/app/views/admin/users/show.html.haml
@@ -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
diff --git a/config/routes.rb b/config/routes.rb
index 2e16c3ecb39..ef052a11bb2 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb
index 6f4c8987637..c40b2c2a583 100644
--- a/spec/controllers/admin/users_controller_spec.rb
+++ b/spec/controllers/admin/users_controller_spec.rb
@@ -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) }
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 922e9ebf844..876cfb1204a 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -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) }