Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
30e3a49e
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
30e3a49e
编写于
9月 12, 2017
作者:
B
Brett Walker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimized the email services
上级
a9b31786
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
19 addition
and
16 deletion
+19
-16
app/controllers/profiles/emails_controller.rb
app/controllers/profiles/emails_controller.rb
+9
-5
app/services/emails/base_service.rb
app/services/emails/base_service.rb
+1
-1
app/services/emails/confirm_service.rb
app/services/emails/confirm_service.rb
+2
-2
app/services/emails/destroy_service.rb
app/services/emails/destroy_service.rb
+2
-2
spec/services/emails/confirm_service_spec.rb
spec/services/emails/confirm_service_spec.rb
+3
-4
spec/services/emails/destroy_service_spec.rb
spec/services/emails/destroy_service_spec.rb
+2
-2
未找到文件。
app/controllers/profiles/emails_controller.rb
浏览文件 @
30e3a49e
class
Profiles::EmailsController
<
Profiles
::
ApplicationController
class
Profiles::EmailsController
<
Profiles
::
ApplicationController
before_action
:find_email
,
only:
[
:destroy
,
:resend_confirmation_instructions
]
def
index
def
index
@primary
=
current_user
.
email
@primary
=
current_user
.
email
@emails
=
current_user
.
emails
.
order_id_desc
@emails
=
current_user
.
emails
.
order_id_desc
...
@@ -14,9 +17,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
...
@@ -14,9 +17,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
end
end
def
destroy
def
destroy
@email
=
current_user
.
emails
.
find
(
params
[
:id
])
Emails
::
DestroyService
.
new
(
current_user
).
execute
(
@email
)
Emails
::
DestroyService
.
new
(
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
}
...
@@ -25,8 +26,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
...
@@ -25,8 +26,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
end
end
def
resend_confirmation_instructions
def
resend_confirmation_instructions
@email
=
current_user
.
emails
.
find
(
params
[
:id
])
if
Emails
::
ConfirmService
.
new
(
current_user
).
execute
(
@email
)
if
@email
&&
Emails
::
ConfirmService
.
new
(
current_user
,
email:
@email
.
email
).
execute
flash
[
:notice
]
=
"Confirmation email sent to
#{
@email
.
email
}
"
flash
[
:notice
]
=
"Confirmation email sent to
#{
@email
.
email
}
"
else
else
flash
[
:alert
]
=
"There was a problem sending the confirmation email"
flash
[
:alert
]
=
"There was a problem sending the confirmation email"
...
@@ -39,4 +39,8 @@ class Profiles::EmailsController < Profiles::ApplicationController
...
@@ -39,4 +39,8 @@ class Profiles::EmailsController < Profiles::ApplicationController
def
email_params
def
email_params
params
.
require
(
:email
).
permit
(
:email
)
params
.
require
(
:email
).
permit
(
:email
)
end
end
def
find_email
@email
=
current_user
.
emails
.
find
(
params
[
:id
])
end
end
end
app/services/emails/base_service.rb
浏览文件 @
30e3a49e
module
Emails
module
Emails
class
BaseService
class
BaseService
def
initialize
(
user
,
opts
)
def
initialize
(
user
,
opts
=
{}
)
@user
=
user
@user
=
user
@email
=
opts
[
:email
]
@email
=
opts
[
:email
]
end
end
...
...
app/services/emails/confirm_service.rb
浏览文件 @
30e3a49e
module
Emails
module
Emails
class
ConfirmService
<
::
Emails
::
BaseService
class
ConfirmService
<
::
Emails
::
BaseService
def
execute
def
execute
(
email_record
)
Email
.
find_by_email!
(
@email
)
.
resend_confirmation_instructions
email_record
.
resend_confirmation_instructions
end
end
end
end
end
end
app/services/emails/destroy_service.rb
浏览文件 @
30e3a49e
module
Emails
module
Emails
class
DestroyService
<
::
Emails
::
BaseService
class
DestroyService
<
::
Emails
::
BaseService
def
execute
def
execute
(
email_record
)
Email
.
find_by_email!
(
@email
)
.
destroy
&&
update_secondary_emails!
email_record
.
destroy
&&
update_secondary_emails!
end
end
private
private
...
...
spec/services/emails/confirm_service_spec.rb
浏览文件 @
30e3a49e
...
@@ -2,14 +2,13 @@ require 'spec_helper'
...
@@ -2,14 +2,13 @@ require 'spec_helper'
describe
Emails
::
ConfirmService
do
describe
Emails
::
ConfirmService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:opts
)
{
{
email:
'new@email.com'
}
}
subject
(
:service
)
{
described_class
.
new
(
user
,
opts
)
}
subject
(
:service
)
{
described_class
.
new
(
user
)
}
describe
'#execute'
do
describe
'#execute'
do
it
'sends a confirmation email again'
do
it
'sends a confirmation email again'
do
user
.
emails
.
create
(
email:
opts
[
:email
]
)
email
=
user
.
emails
.
create
(
email:
'new@email.com'
)
mail
=
service
.
execute
mail
=
service
.
execute
(
email
)
expect
(
mail
.
subject
).
to
eq
(
'Confirmation instructions'
)
expect
(
mail
.
subject
).
to
eq
(
'Confirmation instructions'
)
end
end
end
end
...
...
spec/services/emails/destroy_service_spec.rb
浏览文件 @
30e3a49e
...
@@ -4,11 +4,11 @@ describe Emails::DestroyService do
...
@@ -4,11 +4,11 @@ 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
,
email:
email
.
email
)
}
subject
(
:service
)
{
described_class
.
new
(
user
)
}
describe
'#execute'
do
describe
'#execute'
do
it
'removes an email'
do
it
'removes an email'
do
expect
{
service
.
execute
}.
to
change
{
user
.
emails
.
count
}.
by
(
-
1
)
expect
{
service
.
execute
(
email
)
}.
to
change
{
user
.
emails
.
count
}.
by
(
-
1
)
end
end
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录