BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
0ffa4772
Commit
0ffa4772
authored
Aug 29, 2017
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes the password change workflow for admins.
parent
d546f7d3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
16 deletions
+36
-16
users_controller.rb
app/controllers/admin/users_controller.rb
+11
-4
28938-password-change-workflow-for-admins.yml
.../unreleased/28938-password-change-workflow-for-admins.yml
+5
-0
users_controller_spec.rb
spec/controllers/admin/users_controller_spec.rb
+20
-12
No files found.
app/controllers/admin/users_controller.rb
View file @
0ffa4772
...
...
@@ -117,11 +117,14 @@ class Admin::UsersController < Admin::ApplicationController
user_params_with_pass
=
user_params
.
dup
if
params
[
:user
][
:password
].
present?
user_params_with_pass
.
merge!
(
password_params
=
{
password:
params
[
:user
][
:password
],
password_confirmation:
params
[
:user
][
:password_confirmation
],
password_expires_at:
Time
.
now
)
password_confirmation:
params
[
:user
][
:password_confirmation
]
}
password_params
[
:password_expires_at
]
=
Time
.
now
unless
changing_own_password?
user_params_with_pass
.
merge!
(
password_params
)
end
respond_to
do
|
format
|
...
...
@@ -167,6 +170,10 @@ class Admin::UsersController < Admin::ApplicationController
protected
def
changing_own_password?
user
==
current_user
end
def
user
@user
||=
User
.
find_by!
(
username:
params
[
:id
])
end
...
...
changelogs/unreleased/28938-password-change-workflow-for-admins.yml
0 → 100644
View file @
0ffa4772
---
title
:
Changes the password change workflow for admins.
merge_request
:
13901
author
:
type
:
fixed
spec/controllers/admin/users_controller_spec.rb
View file @
0ffa4772
...
...
@@ -150,6 +150,18 @@ describe Admin::UsersController do
post
:update
,
params
end
context
'when the admin changes his own password'
do
it
'updates the password'
do
expect
{
update_password
(
admin
,
'AValidPassword1'
)
}
.
to
change
{
admin
.
reload
.
encrypted_password
}
end
it
'does not set the new password to expire immediately'
do
expect
{
update_password
(
admin
,
'AValidPassword1'
)
}
.
not_to
change
{
admin
.
reload
.
password_expires_at
}
end
end
context
'when the new password is valid'
do
it
'redirects to the user'
do
update_password
(
user
,
'AValidPassword1'
)
...
...
@@ -158,15 +170,13 @@ describe Admin::UsersController do
end
it
'updates the password'
do
update_password
(
user
,
'AValidPassword1'
)
expect
{
user
.
reload
}.
to
change
{
user
.
encrypted_password
}
expect
{
update_password
(
user
,
'AValidPassword1'
)
}
.
to
change
{
user
.
reload
.
encrypted_password
}
end
it
'sets the new password to expire immediately'
do
update_password
(
user
,
'AValidPassword1'
)
expect
{
user
.
reload
}.
to
change
{
user
.
password_expires_at
}.
to
(
a_value
<=
Time
.
now
)
expect
{
update_password
(
user
,
'AValidPassword1'
)
}
.
to
change
{
user
.
reload
.
password_expires_at
}.
to
be_within
(
2
.
seconds
).
of
(
Time
.
now
)
end
end
...
...
@@ -184,9 +194,8 @@ describe Admin::UsersController do
end
it
'does not update the password'
do
update_password
(
user
,
'invalid'
)
expect
{
user
.
reload
}.
not_to
change
{
user
.
encrypted_password
}
expect
{
update_password
(
user
,
'invalid'
)
}
.
not_to
change
{
user
.
reload
.
encrypted_password
}
end
end
...
...
@@ -204,9 +213,8 @@ describe Admin::UsersController do
end
it
'does not update the password'
do
update_password
(
user
,
'AValidPassword1'
,
'AValidPassword2'
)
expect
{
user
.
reload
}.
not_to
change
{
user
.
encrypted_password
}
expect
{
update_password
(
user
,
'AValidPassword1'
,
'AValidPassword2'
)
}
.
not_to
change
{
user
.
reload
.
encrypted_password
}
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