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
0ee002c7
Commit
0ee002c7
authored
Jun 22, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more refactoring
parent
4c75fe5d
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
9 additions
and
31 deletions
+9
-31
avatars_controller.rb
app/controllers/profiles/avatars_controller.rb
+1
-3
emails_controller.rb
app/controllers/profiles/emails_controller.rb
+3
-2
two_factor_auths_controller.rb
app/controllers/profiles/two_factor_auths_controller.rb
+1
-2
update_service.rb
app/services/users/update_service.rb
+4
-2
create_service_spec.rb
spec/services/emails/create_service_spec.rb
+0
-10
destroy_service_spec.rb
spec/services/emails/destroy_service_spec.rb
+0
-12
No files found.
app/controllers/profiles/avatars_controller.rb
View file @
0ee002c7
...
...
@@ -2,9 +2,7 @@ class Profiles::AvatarsController < Profiles::ApplicationController
def
destroy
@user
=
current_user
Users
::
UpdateService
.
new
(
@user
,
@user
).
execute
do
|
user
|
user
.
remove_avatar!
end
Users
::
UpdateService
.
new
(
@user
,
@user
).
execute
{
|
user
|
user
.
remove_avatar!
}
redirect_to
profile_path
,
status:
302
end
...
...
app/controllers/profiles/emails_controller.rb
View file @
0ee002c7
...
...
@@ -5,9 +5,9 @@ class Profiles::EmailsController < Profiles::ApplicationController
end
def
create
@email
=
current_user
.
emails
.
new
(
email_params
)
@email
=
Emails
::
CreateService
.
new
(
current_user
,
current_user
,
email_params
).
execute
if
Emails
::
CreateService
.
new
(
current_user
,
current_user
,
email_params
).
execute
if
@email
.
errors
.
blank?
NotificationService
.
new
.
new_email
(
@email
)
else
flash
[
:alert
]
=
@email
.
errors
.
full_messages
.
first
...
...
@@ -18,6 +18,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
def
destroy
@email
=
current_user
.
emails
.
find
(
params
[
:id
])
Emails
::
DestroyService
.
new
(
current_user
,
current_user
,
email:
@email
.
email
).
execute
respond_to
do
|
format
|
...
...
app/controllers/profiles/two_factor_auths_controller.rb
View file @
0ee002c7
...
...
@@ -41,8 +41,7 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController
def
create
if
current_user
.
validate_and_consume_otp!
(
params
[
:pin_code
])
Users
::
UpdateService
.
new
(
current_user
,
current_user
).
execute!
do
|
user
|
user
.
otp_required_for_login
=
true
Users
::
UpdateService
.
new
(
current_user
,
current_user
,
otp_required_for_login:
true
).
execute!
do
|
user
|
@codes
=
user
.
generate_otp_backup_codes!
end
...
...
app/services/users/update_service.rb
View file @
0ee002c7
...
...
@@ -17,10 +17,12 @@ module Users
end
end
def
execute!
(
skip_authorization:
false
,
&
block
)
def
execute!
(
*
args
,
&
block
)
result
=
execute
(
*
args
,
&
block
)
raise
SomeCustomException
(
result
[
:message
])
unless
result
[
:status
]
==
:success
raise
ActiveRecord
::
RecordInvalid
(
result
[
:message
])
unless
result
[
:status
]
==
:success
true
end
private
...
...
spec/services/emails/create_service_spec.rb
View file @
0ee002c7
...
...
@@ -17,15 +17,5 @@ describe Emails::CreateService, services: true do
expect
(
user
.
emails
).
to
eq
(
Email
.
where
(
opts
))
end
it
'does not create an email if the user has no permissions'
do
expect
{
described_class
.
new
(
create
(
:user
),
user
,
opts
).
execute
}.
to
raise_error
(
Gitlab
::
Access
::
AccessDeniedError
)
end
it
'creates an email if we skip authorization'
do
expect
do
described_class
.
new
(
create
(
:user
),
user
,
opts
).
execute
(
skip_authorization:
true
)
end
.
to
change
{
Email
.
count
}.
by
(
1
)
end
end
end
spec/services/emails/destroy_service_spec.rb
View file @
0ee002c7
...
...
@@ -10,17 +10,5 @@ describe Emails::DestroyService, services: true do
it
'removes an email'
do
expect
{
service
.
execute
}.
to
change
{
user
.
emails
.
count
}.
by
(
-
1
)
end
it
'does not remove an email if the user has no permissions'
do
expect
do
described_class
.
new
(
create
(
:user
),
user
,
email:
email
.
email
).
execute
end
.
to
raise_error
(
Gitlab
::
Access
::
AccessDeniedError
)
end
it
'removes an email if we skip authorization'
do
expect
do
described_class
.
new
(
create
(
:user
),
user
,
email:
email
.
email
).
execute
(
skip_authorization:
true
)
end
.
to
change
{
Email
.
count
}.
by
(
-
1
)
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