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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
b33c6384
Commit
b33c6384
authored
Jun 23, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update code based on feedback
parent
8f2adb80
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
14 additions
and
15 deletions
+14
-15
app/controllers/admin/users_controller.rb
app/controllers/admin/users_controller.rb
+2
-4
app/controllers/profiles/two_factor_auths_controller.rb
app/controllers/profiles/two_factor_auths_controller.rb
+3
-1
app/services/users/build_service.rb
app/services/users/build_service.rb
+0
-1
app/services/users/create_service.rb
app/services/users/create_service.rb
+0
-1
app/services/users/update_service.rb
app/services/users/update_service.rb
+2
-3
lib/api/internal.rb
lib/api/internal.rb
+4
-2
spec/services/users/update_service_spec.rb
spec/services/users/update_service_spec.rb
+3
-3
No files found.
app/controllers/admin/users_controller.rb
View file @
b33c6384
...
@@ -210,10 +210,8 @@ class Admin::UsersController < Admin::ApplicationController
...
@@ -210,10 +210,8 @@ class Admin::UsersController < Admin::ApplicationController
]
]
end
end
def
update_user
def
update_user
(
&
block
)
result
=
Users
::
UpdateService
.
new
(
user
).
execute
do
|
user
|
result
=
Users
::
UpdateService
.
new
(
user
).
execute
(
&
block
)
yield
(
user
)
end
result
[
:status
]
==
:success
result
[
:status
]
==
:success
end
end
...
...
app/controllers/profiles/two_factor_auths_controller.rb
View file @
b33c6384
...
@@ -41,8 +41,10 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController
...
@@ -41,8 +41,10 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController
def
create
def
create
if
current_user
.
validate_and_consume_otp!
(
params
[
:pin_code
])
if
current_user
.
validate_and_consume_otp!
(
params
[
:pin_code
])
codes
=
nil
Users
::
UpdateService
.
new
(
current_user
,
otp_required_for_login:
true
).
execute!
do
|
user
|
Users
::
UpdateService
.
new
(
current_user
,
otp_required_for_login:
true
).
execute!
do
|
user
|
@
codes
=
user
.
generate_otp_backup_codes!
codes
=
user
.
generate_otp_backup_codes!
end
end
render
'create'
render
'create'
...
...
app/services/users/build_service.rb
View file @
b33c6384
module
Users
module
Users
# Service for building a new user.
class
BuildService
<
BaseService
class
BuildService
<
BaseService
def
initialize
(
current_user
,
params
=
{})
def
initialize
(
current_user
,
params
=
{})
@current_user
=
current_user
@current_user
=
current_user
...
...
app/services/users/create_service.rb
View file @
b33c6384
module
Users
module
Users
# Service for creating a new user.
class
CreateService
<
BaseService
class
CreateService
<
BaseService
def
initialize
(
current_user
,
params
=
{})
def
initialize
(
current_user
,
params
=
{})
@current_user
=
current_user
@current_user
=
current_user
...
...
app/services/users/update_service.rb
View file @
b33c6384
module
Users
module
Users
# Service for updating a user.
class
UpdateService
<
BaseService
class
UpdateService
<
BaseService
def
initialize
(
user
,
params
=
{})
def
initialize
(
user
,
params
=
{})
@user
=
user
@user
=
user
...
@@ -7,6 +6,8 @@ module Users
...
@@ -7,6 +6,8 @@ module Users
end
end
def
execute
(
validate:
true
,
&
block
)
def
execute
(
validate:
true
,
&
block
)
yield
(
@user
)
if
block_given?
assign_attributes
(
&
block
)
assign_attributes
(
&
block
)
if
@user
.
save
(
validate:
validate
)
if
@user
.
save
(
validate:
validate
)
...
@@ -27,8 +28,6 @@ module Users
...
@@ -27,8 +28,6 @@ module Users
private
private
def
assign_attributes
(
&
block
)
def
assign_attributes
(
&
block
)
yield
(
@user
)
if
block_given?
@user
.
assign_attributes
(
params
)
if
params
.
any?
@user
.
assign_attributes
(
params
)
if
params
.
any?
end
end
end
end
...
...
lib/api/internal.rb
View file @
b33c6384
...
@@ -132,11 +132,13 @@ module API
...
@@ -132,11 +132,13 @@ module API
return
{
success:
false
,
message:
'Two-factor authentication is not enabled for this user'
}
return
{
success:
false
,
message:
'Two-factor authentication is not enabled for this user'
}
end
end
codes
=
nil
::
Users
::
UpdateService
.
new
(
user
).
execute!
do
|
user
|
::
Users
::
UpdateService
.
new
(
user
).
execute!
do
|
user
|
@
codes
=
user
.
generate_otp_backup_codes!
codes
=
user
.
generate_otp_backup_codes!
end
end
{
success:
true
,
recovery_codes:
@
codes
}
{
success:
true
,
recovery_codes:
codes
}
end
end
post
"/notify_post_receive"
do
post
"/notify_post_receive"
do
...
...
spec/services/users/update_service_spec.rb
View file @
b33c6384
...
@@ -7,7 +7,7 @@ describe Users::UpdateService, services: true do
...
@@ -7,7 +7,7 @@ describe Users::UpdateService, services: true do
it
'updates the name'
do
it
'updates the name'
do
result
=
update_user
(
user
,
name:
'New Name'
)
result
=
update_user
(
user
,
name:
'New Name'
)
expect
(
result
).
to
eq
(
{
status: :success
}
)
expect
(
result
).
to
eq
(
status: :success
)
expect
(
user
.
name
).
to
eq
(
'New Name'
)
expect
(
user
.
name
).
to
eq
(
'New Name'
)
end
end
...
@@ -30,9 +30,9 @@ describe Users::UpdateService, services: true do
...
@@ -30,9 +30,9 @@ describe Users::UpdateService, services: true do
expect
(
user
.
name
).
to
eq
(
'New Name'
)
expect
(
user
.
name
).
to
eq
(
'New Name'
)
end
end
it
'r
eturns an error result
when record cannot be updated'
do
it
'r
aises an error
when record cannot be updated'
do
expect
do
expect
do
update_user
(
user
,
{
email:
'invalid'
}
)
update_user
(
user
,
email:
'invalid'
)
end
.
to
raise_error
(
ActiveRecord
::
RecordInvalid
)
end
.
to
raise_error
(
ActiveRecord
::
RecordInvalid
)
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