Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ed3c25e4
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,发现更多精彩内容 >>
提交
ed3c25e4
编写于
10月 01, 2017
作者:
A
Alexandra
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
spacing and small optimisations
上级
39fbac86
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
28 addition
and
24 deletion
+28
-24
app/controllers/confirmations_controller.rb
app/controllers/confirmations_controller.rb
+1
-1
app/controllers/profiles/emails_controller.rb
app/controllers/profiles/emails_controller.rb
+2
-1
app/models/user.rb
app/models/user.rb
+7
-7
app/services/emails/base_service.rb
app/services/emails/base_service.rb
+2
-3
app/services/emails/confirm_service.rb
app/services/emails/confirm_service.rb
+2
-2
app/services/emails/create_service.rb
app/services/emails/create_service.rb
+2
-2
app/services/emails/destroy_service.rb
app/services/emails/destroy_service.rb
+2
-2
app/views/profiles/emails/index.html.haml
app/views/profiles/emails/index.html.haml
+3
-3
spec/controllers/profiles/emails_controller_spec.rb
spec/controllers/profiles/emails_controller_spec.rb
+4
-3
spec/models/email_spec.rb
spec/models/email_spec.rb
+3
-0
未找到文件。
app/controllers/confirmations_controller.rb
浏览文件 @
ed3c25e4
...
...
@@ -10,7 +10,7 @@ class ConfirmationsController < Devise::ConfirmationsController
users_almost_there_path
end
def
after_confirmation_path_for
(
resource_name
,
resource
)
def
after_confirmation_path_for
(
_
resource_name
,
resource
)
# incoming resource can either be a :user or an :email
if
signed_in?
(
:user
)
after_sign_in_path_for
(
resource
)
...
...
app/controllers/profiles/emails_controller.rb
浏览文件 @
ed3c25e4
...
...
@@ -2,7 +2,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
before_action
:find_email
,
only:
[
:destroy
,
:resend_confirmation_instructions
]
def
index
@primary
=
current_user
.
email
@primary
_email
=
current_user
.
email
@emails
=
current_user
.
emails
.
order_id_desc
end
...
...
@@ -30,6 +30,7 @@ class Profiles::EmailsController < Profiles::ApplicationController
else
flash
[
:alert
]
=
"There was a problem sending the confirmation email"
end
redirect_to
profile_emails_url
end
...
...
app/models/user.rb
浏览文件 @
ed3c25e4
...
...
@@ -164,7 +164,7 @@ class User < ActiveRecord::Base
before_save
:ensure_authentication_token
,
:ensure_incoming_email_token
before_save
:ensure_user_rights_and_limits
,
if: :external_changed?
before_save
:skip_reconfirmation!
,
if:
->
(
user
)
{
user
.
email_changed?
&&
user
.
read_only_attribute?
(
:email
)
}
before_save
:check_for_verified_email
,
if:
->
(
user
)
{
user
.
email_changed?
&&
!
user
.
new_record?
}
before_save
:check_for_verified_email
,
if:
->
(
user
)
{
user
.
email_changed?
&&
!
user
.
new_record?
}
after_save
:ensure_namespace_correct
after_destroy
:post_destroy_hook
after_commit
:update_emails_with_primary_email
,
on: :update
,
if:
->
{
previous_changes
.
key?
(
'email'
)
}
...
...
@@ -223,11 +223,6 @@ class User < ActiveRecord::Base
end
end
# see if the new email is already a verified secondary email
def
check_for_verified_email
skip_reconfirmation!
if
emails
.
find_by
(
email:
self
.
email
).
try
(
:confirmed?
)
end
mount_uploader
:avatar
,
AvatarUploader
has_many
:uploads
,
as: :model
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
...
...
@@ -529,6 +524,11 @@ class User < ActiveRecord::Base
errors
.
add
(
:public_email
,
"is not an email you own"
)
unless
all_emails
.
include?
(
public_email
)
end
# see if the new email is already a verified secondary email
def
check_for_verified_email
skip_reconfirmation!
if
emails
.
confirmed
.
where
(
email:
self
.
email
).
any?
end
# Note: the use of the Emails services will cause `saves` on the user object, running
# through the callbacks again and can have side effects, such as the `previous_changes`
# hash and `_was` variables getting munged.
...
...
@@ -843,7 +843,7 @@ class User < ActiveRecord::Base
def
verified_email?
(
check_email
)
downcased
=
check_email
.
downcase
(
email
==
downcased
&&
primary_email_verified?
)
||
emails
.
confirmed
.
where
(
email:
downcased
).
exists?
email
==
downcased
?
primary_email_verified?
:
emails
.
confirmed
.
where
(
email:
downcased
).
exists?
end
def
hook_attrs
...
...
app/services/emails/base_service.rb
浏览文件 @
ed3c25e4
module
Emails
class
BaseService
def
initialize
(
user
,
opts
=
{})
@user
=
user
@email
=
opts
[
:email
]
def
initialize
(
user
,
params
=
{})
@user
,
@params
=
user
,
params
.
dup
end
end
end
app/services/emails/confirm_service.rb
浏览文件 @
ed3c25e4
module
Emails
class
ConfirmService
<
::
Emails
::
BaseService
def
execute
(
email
_record
)
email
_record
.
resend_confirmation_instructions
def
execute
(
email
)
email
.
resend_confirmation_instructions
end
end
end
app/services/emails/create_service.rb
浏览文件 @
ed3c25e4
module
Emails
class
CreateService
<
::
Emails
::
BaseService
def
execute
(
option
s
=
{})
@user
.
emails
.
create
(
{
email:
@email
}.
merge
(
option
s
))
def
execute
(
extra_param
s
=
{})
@user
.
emails
.
create
(
@params
.
merge
(
extra_param
s
))
end
end
end
app/services/emails/destroy_service.rb
浏览文件 @
ed3c25e4
module
Emails
class
DestroyService
<
::
Emails
::
BaseService
def
execute
(
email
_record
)
email
_record
.
destroy
&&
update_secondary_emails!
def
execute
(
email
)
email
.
destroy
&&
update_secondary_emails!
end
private
...
...
app/views/profiles/emails/index.html.haml
浏览文件 @
ed3c25e4
...
...
@@ -32,12 +32,12 @@
All email addresses will be used to identify your commits.
%ul
.well-list
%li
=
render
partial:
'shared/email_with_badge'
,
locals:
{
email:
@primary
,
verified:
current_user
.
confirmed?
}
=
render
partial:
'shared/email_with_badge'
,
locals:
{
email:
@primary
_email
,
verified:
current_user
.
confirmed?
}
%span
.pull-right
%span
.label.label-success
Primary email
-
if
@primary
===
current_user
.
public_email
-
if
@primary
_email
===
current_user
.
public_email
%span
.label.label-info
Public email
-
if
@primary
===
current_user
.
notification_email
-
if
@primary
_email
===
current_user
.
notification_email
%span
.label.label-info
Notification email
-
@emails
.
each
do
|
email
|
%li
...
...
spec/controllers/profiles/emails_controller_spec.rb
浏览文件 @
ed3c25e4
...
...
@@ -11,7 +11,7 @@ describe Profiles::EmailsController do
let
(
:email_params
)
{
{
email:
"add_email@example.com"
}
}
it
'sends an email confirmation'
do
expect
{
post
(
:create
,
{
email:
email_params
})
}.
to
change
{
ActionMailer
::
Base
.
deliveries
.
size
}
expect
{
post
(
:create
,
{
email:
email_params
})
}.
to
change
{
ActionMailer
::
Base
.
deliveries
.
size
}
expect
(
ActionMailer
::
Base
.
deliveries
.
last
.
to
).
to
eq
[
email_params
[
:email
]]
expect
(
ActionMailer
::
Base
.
deliveries
.
last
.
subject
).
to
match
"Confirmation instructions"
end
...
...
@@ -22,13 +22,14 @@ describe Profiles::EmailsController do
it
'resends an email confirmation'
do
email
=
user
.
emails
.
create
(
email:
'add_email@example.com'
)
expect
{
put
(
:resend_confirmation_instructions
,
{
id:
email
})}.
to
change
{
ActionMailer
::
Base
.
deliveries
.
size
}
expect
{
put
(
:resend_confirmation_instructions
,
{
id:
email
})
}.
to
change
{
ActionMailer
::
Base
.
deliveries
.
size
}
expect
(
ActionMailer
::
Base
.
deliveries
.
last
.
to
).
to
eq
[
email_params
[
:email
]]
expect
(
ActionMailer
::
Base
.
deliveries
.
last
.
subject
).
to
match
"Confirmation instructions"
end
it
'unable to resend an email confirmation'
do
expect
{
put
(
:resend_confirmation_instructions
,
{
id:
1
})
}.
not_to
change
{
ActionMailer
::
Base
.
deliveries
.
size
}
expect
{
put
(
:resend_confirmation_instructions
,
{
id:
1
})
}.
not_to
change
{
ActionMailer
::
Base
.
deliveries
.
size
}
end
end
end
spec/models/email_spec.rb
浏览文件 @
ed3c25e4
...
...
@@ -22,7 +22,9 @@ describe Email do
it
'synchronizes the gpg keys when the email is updated'
do
email
=
user
.
emails
.
create
(
email:
'new@email.com'
)
expect
(
user
).
to
receive
(
:update_invalid_gpg_signatures
)
email
.
confirm
end
end
...
...
@@ -33,6 +35,7 @@ describe Email do
it
'scopes confirmed emails'
do
create
(
:email
,
:confirmed
,
user:
user
)
create
(
:email
,
user:
user
)
expect
(
user
.
emails
.
count
).
to
eq
2
expect
(
user
.
emails
.
confirmed
.
count
).
to
eq
1
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录