Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
83347954
Commit
83347954
authored
Sep 24, 2015
by
Pavel Forkert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to admin area to sign in as a specific user
Closes #2291
parent
f2999fe8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
1 deletion
+40
-1
app/controllers/admin/users_controller.rb
app/controllers/admin/users_controller.rb
+6
-0
app/views/admin/users/index.html.haml
app/views/admin/users/index.html.haml
+2
-1
config/routes.rb
config/routes.rb
+1
-0
spec/controllers/admin/users_controller_spec.rb
spec/controllers/admin/users_controller_spec.rb
+15
-0
spec/features/admin/admin_users_spec.rb
spec/features/admin/admin_users_spec.rb
+16
-0
No files found.
app/controllers/admin/users_controller.rb
View file @
83347954
...
...
@@ -63,6 +63,12 @@ class Admin::UsersController < Admin::ApplicationController
end
end
def
login_as
sign_in
(
user
)
flash
[
:alert
]
=
"Logged in as
#{
user
.
username
}
"
redirect_to
root_path
end
def
disable_two_factor
user
.
disable_two_factor!
redirect_to
admin_user_path
(
user
),
...
...
app/views/admin/users/index.html.haml
View file @
83347954
...
...
@@ -72,7 +72,7 @@
=
link_to
'New User'
,
new_admin_user_path
,
class:
"btn btn-new btn-sm"
%ul
.well-list
-
@users
.
each
do
|
user
|
%li
%li
{
class:
"user-#{user.id}"
}
.list-item-name
-
if
user
.
blocked?
%i
.fa.fa-lock.cred
...
...
@@ -90,6 +90,7 @@
=
link_to
'Edit'
,
edit_admin_user_path
(
user
),
id:
"edit_
#{
dom_id
(
user
)
}
"
,
class:
"btn btn-xs"
-
unless
user
==
current_user
=
link_to
'Log in'
,
login_as_admin_user_path
(
user
),
method: :put
,
class:
"btn btn-xs btn-primary"
-
if
user
.
blocked?
=
link_to
'Unblock'
,
unblock_admin_user_path
(
user
),
method: :put
,
class:
"btn btn-xs btn-success"
-
else
...
...
config/routes.rb
View file @
83347954
...
...
@@ -262,6 +262,7 @@ Gitlab::Application.routes.draw do
put
:unblock
put
:unlock
put
:confirm
put
:login_as
patch
:disable_two_factor
delete
'remove/:email_id'
,
action:
'remove_email'
,
as:
'remove_email'
end
...
...
spec/controllers/admin/users_controller_spec.rb
View file @
83347954
...
...
@@ -7,6 +7,21 @@ describe Admin::UsersController do
sign_in
(
admin
)
end
describe
'PUT login_as'
do
let
(
:user
)
{
create
(
:user
)
}
it
'logs admin as another user'
do
expect
(
warden
.
authenticate
(
scope: :user
)).
not_to
eq
(
user
)
put
:login_as
,
id:
user
.
username
expect
(
warden
.
authenticate
(
scope: :user
)).
to
eq
(
user
)
end
it
'redirects user to homepage'
do
put
:login_as
,
id:
user
.
username
expect
(
response
).
to
redirect_to
(
root_path
)
end
end
describe
'DELETE #user with projects'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
...
...
spec/features/admin/admin_users_spec.rb
View file @
83347954
...
...
@@ -166,4 +166,20 @@ describe "Admin::Users", feature: true do
end
end
end
it
'should be able to log in as another user'
do
another_user
=
create
(
:user
)
visit
admin_users_path
page
.
within
".user-
#{
another_user
.
id
}
"
do
click_link
'Log in'
end
expect
(
page
).
to
have_content
(
"Logged in as
#{
another_user
.
username
}
"
)
page
.
within
'.sidebar-user .username'
do
expect
(
page
).
to
have_content
(
another_user
.
username
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment