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
1dcb7111
Commit
1dcb7111
authored
Sep 27, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor emails service
parent
e07819cb
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
14 additions
and
14 deletions
+14
-14
app/controllers/admin/users_controller.rb
app/controllers/admin/users_controller.rb
+1
-1
app/controllers/profiles/emails_controller.rb
app/controllers/profiles/emails_controller.rb
+2
-2
app/models/user.rb
app/models/user.rb
+2
-2
app/services/emails/base_service.rb
app/services/emails/base_service.rb
+2
-2
lib/api/users.rb
lib/api/users.rb
+4
-4
spec/services/emails/create_service_spec.rb
spec/services/emails/create_service_spec.rb
+2
-2
spec/services/emails/destroy_service_spec.rb
spec/services/emails/destroy_service_spec.rb
+1
-1
No files found.
app/controllers/admin/users_controller.rb
View file @
1dcb7111
...
@@ -155,7 +155,7 @@ class Admin::UsersController < Admin::ApplicationController
...
@@ -155,7 +155,7 @@ class Admin::UsersController < Admin::ApplicationController
def
remove_email
def
remove_email
email
=
user
.
emails
.
find
(
params
[
:email_id
])
email
=
user
.
emails
.
find
(
params
[
:email_id
])
success
=
Emails
::
DestroyService
.
new
(
current_user
,
user
,
email:
email
.
email
).
execute
success
=
Emails
::
DestroyService
.
new
(
current_user
,
user
:
user
,
email:
email
.
email
).
execute
respond_to
do
|
format
|
respond_to
do
|
format
|
if
success
if
success
...
...
app/controllers/profiles/emails_controller.rb
View file @
1dcb7111
...
@@ -5,7 +5,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
...
@@ -5,7 +5,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
end
end
def
create
def
create
@email
=
Emails
::
CreateService
.
new
(
current_user
,
current_user
,
email_params
).
execute
@email
=
Emails
::
CreateService
.
new
(
current_user
,
email_params
.
merge
(
user:
current_user
)
).
execute
if
@email
.
errors
.
blank?
if
@email
.
errors
.
blank?
NotificationService
.
new
.
new_email
(
@email
)
NotificationService
.
new
.
new_email
(
@email
)
...
@@ -19,7 +19,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
...
@@ -19,7 +19,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
def
destroy
def
destroy
@email
=
current_user
.
emails
.
find
(
params
[
:id
])
@email
=
current_user
.
emails
.
find
(
params
[
:id
])
Emails
::
DestroyService
.
new
(
current_user
,
current_user
,
email:
@email
.
email
).
execute
Emails
::
DestroyService
.
new
(
current_user
,
user:
current_user
,
email:
@email
.
email
).
execute
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
{
redirect_to
profile_emails_url
,
status:
302
}
format
.
html
{
redirect_to
profile_emails_url
,
status:
302
}
...
...
app/models/user.rb
View file @
1dcb7111
...
@@ -526,8 +526,8 @@ class User < ActiveRecord::Base
...
@@ -526,8 +526,8 @@ class User < ActiveRecord::Base
def
update_emails_with_primary_email
def
update_emails_with_primary_email
primary_email_record
=
emails
.
find_by
(
email:
email
)
primary_email_record
=
emails
.
find_by
(
email:
email
)
if
primary_email_record
if
primary_email_record
Emails
::
DestroyService
.
new
(
self
,
self
,
email:
email
).
execute
Emails
::
DestroyService
.
new
(
self
,
user:
self
,
email:
email
).
execute
Emails
::
CreateService
.
new
(
self
,
self
,
email:
email_was
).
execute
Emails
::
CreateService
.
new
(
self
,
user:
self
,
email:
email_was
).
execute
end
end
end
end
...
...
app/services/emails/base_service.rb
View file @
1dcb7111
module
Emails
module
Emails
class
BaseService
class
BaseService
def
initialize
(
current_user
,
user
,
opts
)
def
initialize
(
current_user
,
opts
)
@current_user
=
current_user
@current_user
=
current_user
@user
=
user
@user
=
opts
.
delete
(
:user
)
@email
=
opts
[
:email
]
@email
=
opts
[
:email
]
end
end
end
end
...
...
lib/api/users.rb
View file @
1dcb7111
...
@@ -326,7 +326,7 @@ module API
...
@@ -326,7 +326,7 @@ module API
user
=
User
.
find_by
(
id:
params
.
delete
(
:id
))
user
=
User
.
find_by
(
id:
params
.
delete
(
:id
))
not_found!
(
'User'
)
unless
user
not_found!
(
'User'
)
unless
user
email
=
Emails
::
CreateService
.
new
(
current_user
,
user
,
declared_params
(
include_missing:
false
)).
execute
email
=
Emails
::
CreateService
.
new
(
current_user
,
declared_params
(
include_missing:
false
).
merge
(
user:
user
)).
execute
if
email
.
errors
.
blank?
if
email
.
errors
.
blank?
NotificationService
.
new
.
new_email
(
email
)
NotificationService
.
new
.
new_email
(
email
)
...
@@ -367,7 +367,7 @@ module API
...
@@ -367,7 +367,7 @@ module API
not_found!
(
'Email'
)
unless
email
not_found!
(
'Email'
)
unless
email
destroy_conditionally!
(
email
)
do
|
email
|
destroy_conditionally!
(
email
)
do
|
email
|
Emails
::
DestroyService
.
new
(
current_user
,
user
,
email:
email
.
email
).
execute
Emails
::
DestroyService
.
new
(
current_user
,
user
:
user
,
email:
email
.
email
).
execute
end
end
user
.
update_secondary_emails!
user
.
update_secondary_emails!
...
@@ -672,7 +672,7 @@ module API
...
@@ -672,7 +672,7 @@ module API
requires
:email
,
type:
String
,
desc:
'The new email'
requires
:email
,
type:
String
,
desc:
'The new email'
end
end
post
"emails"
do
post
"emails"
do
email
=
Emails
::
CreateService
.
new
(
current_user
,
current_user
,
declared_params
).
execute
email
=
Emails
::
CreateService
.
new
(
current_user
,
declared_params
.
merge
(
user:
current_user
)
).
execute
if
email
.
errors
.
blank?
if
email
.
errors
.
blank?
NotificationService
.
new
.
new_email
(
email
)
NotificationService
.
new
.
new_email
(
email
)
...
@@ -691,7 +691,7 @@ module API
...
@@ -691,7 +691,7 @@ module API
not_found!
(
'Email'
)
unless
email
not_found!
(
'Email'
)
unless
email
destroy_conditionally!
(
email
)
do
|
email
|
destroy_conditionally!
(
email
)
do
|
email
|
Emails
::
DestroyService
.
new
(
current_user
,
current_user
,
email:
email
.
email
).
execute
Emails
::
DestroyService
.
new
(
current_user
,
user:
current_user
,
email:
email
.
email
).
execute
end
end
current_user
.
update_secondary_emails!
current_user
.
update_secondary_emails!
...
...
spec/services/emails/create_service_spec.rb
View file @
1dcb7111
...
@@ -2,9 +2,9 @@ require 'spec_helper'
...
@@ -2,9 +2,9 @@ require 'spec_helper'
describe
Emails
::
CreateService
do
describe
Emails
::
CreateService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:opts
)
{
{
email:
'new@email.com'
}
}
let
(
:opts
)
{
{
email:
'new@email.com'
,
user:
user
}
}
subject
(
:service
)
{
described_class
.
new
(
user
,
user
,
opts
)
}
subject
(
:service
)
{
described_class
.
new
(
user
,
opts
)
}
describe
'#execute'
do
describe
'#execute'
do
it
'creates an email with valid attributes'
do
it
'creates an email with valid attributes'
do
...
...
spec/services/emails/destroy_service_spec.rb
View file @
1dcb7111
...
@@ -4,7 +4,7 @@ describe Emails::DestroyService do
...
@@ -4,7 +4,7 @@ describe Emails::DestroyService do
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:email
)
{
create
(
:email
,
user:
user
)
}
let!
(
:email
)
{
create
(
:email
,
user:
user
)
}
subject
(
:service
)
{
described_class
.
new
(
user
,
user
,
email:
email
.
email
)
}
subject
(
:service
)
{
described_class
.
new
(
user
,
user
:
user
,
email:
email
.
email
)
}
describe
'#execute'
do
describe
'#execute'
do
it
'removes an email'
do
it
'removes an email'
do
...
...
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