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
040acf53
Commit
040acf53
authored
Aug 21, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
9ab8f097
bfc7c9ad
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
80 additions
and
2 deletions
+80
-2
app/mailers/notify.rb
app/mailers/notify.rb
+13
-2
spec/mailers/notify_spec.rb
spec/mailers/notify_spec.rb
+67
-0
No files found.
app/mailers/notify.rb
View file @
040acf53
...
...
@@ -125,9 +125,8 @@ class Notify < BaseMailer
def
mail_thread
(
model
,
headers
=
{})
add_project_headers
add_unsubscription_headers_and_links
add_model_headers
(
model
)
headers
[
"X-GitLab-
#{
model
.
class
.
name
}
-ID"
]
=
model
.
id
headers
[
"X-GitLab-
#{
model
.
class
.
name
}
-IID"
]
=
model
.
iid
if
model
.
respond_to?
(
:iid
)
headers
[
'X-GitLab-Reply-Key'
]
=
reply_key
@reason
=
headers
[
'X-GitLab-NotificationReason'
]
...
...
@@ -196,6 +195,18 @@ class Notify < BaseMailer
@reply_key
||=
SentNotification
.
reply_key
end
# This method applies threading headers to the email to identify
# the instance we are discussing.
#
# All model instances must have `#id`, and may implement `#iid`.
def
add_model_headers
(
object
)
# Use replacement so we don't strip the module.
prefix
=
"X-GitLab-
#{
object
.
class
.
name
.
gsub
(
/::/
,
'-'
)
}
"
headers
[
"
#{
prefix
}
-ID"
]
=
object
.
id
headers
[
"
#{
prefix
}
-IID"
]
=
object
.
iid
if
object
.
respond_to?
(
:iid
)
end
def
add_project_headers
return
unless
@project
...
...
spec/mailers/notify_spec.rb
View file @
040acf53
...
...
@@ -543,6 +543,73 @@ describe Notify do
end
end
describe
'#mail_thread'
do
set
(
:mail_thread_note
)
{
create
(
:note
)
}
let
(
:headers
)
do
{
from:
'someone@test.com'
,
to:
'someone-else@test.com'
,
subject:
'something'
,
template_name:
'_note_email'
# re-use this for testing
}
end
let
(
:mailer
)
do
mailer
=
described_class
.
new
mailer
.
instance_variable_set
(
:@note
,
mail_thread_note
)
mailer
end
context
'the model has no namespace'
do
class
TopLevelThing
include
Referable
include
Noteable
def
to_reference
(
*
_args
)
'tlt-ref'
end
def
id
'tlt-id'
end
end
subject
do
mailer
.
send
(
:mail_thread
,
TopLevelThing
.
new
,
headers
)
end
it
'has X-GitLab-Namespaced-Thing-ID header'
do
expect
(
subject
.
header
[
'X-GitLab-TopLevelThing-ID'
].
value
).
to
eq
(
'tlt-id'
)
end
end
context
'the model has a namespace'
do
module
Namespaced
class
Thing
include
Referable
include
Noteable
def
to_reference
(
*
_args
)
'some-reference'
end
def
id
'some-id'
end
end
end
subject
do
mailer
.
send
(
:mail_thread
,
Namespaced
::
Thing
.
new
,
headers
)
end
it
'has X-GitLab-Namespaced-Thing-ID header'
do
expect
(
subject
.
header
[
'X-GitLab-Namespaced-Thing-ID'
].
value
).
to
eq
(
'some-id'
)
end
end
end
context
'for issue notes'
do
let
(
:host
)
{
Gitlab
.
config
.
gitlab
.
host
}
...
...
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