summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-07-01 22:26:14 -0700
committerStan Hu <stanhu@gmail.com>2015-07-02 04:22:51 -0700
commit3e738e3b9aeae5620116109258c4d4da84180e7e (patch)
treed433a56409141671d9c56e6bca3e0ce16f546ce5
parent2ca7ffd094ae285823d1a00b8cf1a7d23b80a2a3 (diff)
downloadgitlab-ce-3e738e3b9aeae5620116109258c4d4da84180e7e.tar.gz
Add support for unlocking users in admin settings
Closes https://github.com/gitlabhq/gitlabhq/issues/9381
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/admin/users_controller.rb8
-rw-r--r--app/views/admin/users/index.html.haml2
-rw-r--r--app/views/admin/users/show.html.haml8
-rw-r--r--config/routes.rb1
-rw-r--r--spec/controllers/admin/users_controller_spec.rb15
6 files changed, 35 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 616b41a4269..d7d12034e3b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
Please view this file on the master branch, on stable branches it's out of date.
v 7.13.0 (unreleased)
+ - Add support for unlocking users in admin settings (Stan Hu)
- Fix order of issues imported form GitHub (Hiroyuki Sato)
- Bump rugments to 1.0.0beta8 to fix C prototype function highlighting (Jonathon Reinhart)
- Fix Merge Request webhook to properly fire "merge" action when accepted from the web UI
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index ec29c320654..7a683098df3 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -47,6 +47,14 @@ class Admin::UsersController < Admin::ApplicationController
end
end
+ def unlock
+ if user.unlock_access!
+ redirect_to :back, alert: "Successfully unlocked"
+ else
+ redirect_to :back, alert: "Error occurred. User was not unlocked"
+ end
+ end
+
def create
opts = {
force_random_password: true,
diff --git a/app/views/admin/users/index.html.haml b/app/views/admin/users/index.html.haml
index 9c1bec7c84d..b0d31170704 100644
--- a/app/views/admin/users/index.html.haml
+++ b/app/views/admin/users/index.html.haml
@@ -93,6 +93,8 @@
= link_to 'Unblock', unblock_admin_user_path(user), method: :put, class: "btn btn-xs btn-success"
- else
= link_to 'Block', block_admin_user_path(user), data: {confirm: 'USER WILL BE BLOCKED! Are you sure?'}, method: :put, class: "btn btn-xs btn-warning"
+ - if user.access_locked?
+ = link_to 'Unlock', unlock_admin_user_path(user), method: :put, class: "btn btn-xs btn-success", data: { confirm: 'Are you sure?' }
- if user.can_be_removed?
= link_to 'Destroy', [:admin, user], data: { confirm: "USER #{user.name} WILL BE REMOVED! All tickets linked to this user will also be removed! Maybe block the user instead? Are you sure?" }, method: :delete, class: "btn btn-xs btn-remove"
= paginate @users, theme: "gitlab"
diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml
index 2662b3569ec..8c6b8e851c4 100644
--- a/app/views/admin/users/show.html.haml
+++ b/app/views/admin/users/show.html.haml
@@ -131,6 +131,14 @@
%li Owned groups will be left
%br
= link_to 'Block user', block_admin_user_path(@user), data: { confirm: 'USER WILL BE BLOCKED! Are you sure?' }, method: :put, class: "btn btn-warning"
+ - if @user.access_locked?
+ .panel.panel-info
+ .panel-heading
+ This account has been locked
+ .panel-body
+ %p This user has been temporarily locked due to excessive number of failed logins. You may manually unlock the account.
+ %br
+ = link_to 'Unlock user', unlock_admin_user_path(@user), method: :put, class: "btn btn-info", data: { confirm: 'Are you sure?' }
.panel.panel-danger
.panel-heading
diff --git a/config/routes.rb b/config/routes.rb
index 33f55dde476..f904c975733 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -158,6 +158,7 @@ Gitlab::Application.routes.draw do
put :team_update
put :block
put :unblock
+ put :unlock
delete 'remove/:email_id', action: 'remove_email', as: 'remove_email'
end
end
diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb
index f27e861e175..550a91a79e2 100644
--- a/spec/controllers/admin/users_controller_spec.rb
+++ b/spec/controllers/admin/users_controller_spec.rb
@@ -21,4 +21,19 @@ describe Admin::UsersController do
expect { User.find(user.id) }.to raise_exception(ActiveRecord::RecordNotFound)
end
end
+
+ describe 'PUT unlock/:id' do
+ let(:user) { create(:user) }
+
+ before do
+ request.env["HTTP_REFERER"] = "/"
+ user.lock_access!
+ end
+
+ it 'unlocks user' do
+ put :unlock, id: user.username
+ user.reload
+ expect(user.access_locked?).to be_falsey
+ end
+ end
end