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
c668cc55
Commit
c668cc55
authored
Jul 30, 2018
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add emails for new epic
parent
abb412d4
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
225 additions
and
26 deletions
+225
-26
app/workers/all_queues.yml
app/workers/all_queues.yml
+1
-0
config/sidekiq_queues.yml
config/sidekiq_queues.yml
+1
-0
ee/app/mailers/ee/notify.rb
ee/app/mailers/ee/notify.rb
+1
-0
ee/app/mailers/emails/epics.rb
ee/app/mailers/emails/epics.rb
+32
-0
ee/app/services/ee/notification_service.rb
ee/app/services/ee/notification_service.rb
+4
-0
ee/app/services/epics/create_service.rb
ee/app/services/epics/create_service.rb
+8
-0
ee/app/views/notify/new_epic_email.html.haml
ee/app/views/notify/new_epic_email.html.haml
+11
-0
ee/app/views/notify/new_epic_email.text.erb
ee/app/views/notify/new_epic_email.text.erb
+10
-0
ee/app/workers/new_epic_worker.rb
ee/app/workers/new_epic_worker.rb
+17
-0
ee/spec/mailers/notify_spec.rb
ee/spec/mailers/notify_spec.rb
+57
-26
ee/spec/services/epics/create_service_spec.rb
ee/spec/services/epics/create_service_spec.rb
+3
-0
ee/spec/support/shared_examples/notify_shared_examples.rb
ee/spec/support/shared_examples/notify_shared_examples.rb
+26
-0
ee/spec/workers/new_epic_worker_spec.rb
ee/spec/workers/new_epic_worker_spec.rb
+54
-0
No files found.
app/workers/all_queues.yml
View file @
c668cc55
...
@@ -181,6 +181,7 @@
...
@@ -181,6 +181,7 @@
-
elastic_indexer
-
elastic_indexer
-
export_csv
-
export_csv
-
ldap_group_sync
-
ldap_group_sync
-
new_epic
-
project_import_schedule
-
project_import_schedule
-
project_update_repository_storage
-
project_update_repository_storage
-
rebase
-
rebase
...
...
config/sidekiq_queues.yml
View file @
c668cc55
...
@@ -85,6 +85,7 @@
...
@@ -85,6 +85,7 @@
- [chat_notification, 2]
- [chat_notification, 2]
- [geo, 1]
- [geo, 1]
- [repository_update_mirror, 1]
- [repository_update_mirror, 1]
- [new_epic, 2]
- [project_import_schedule, 1]
- [project_import_schedule, 1]
- [project_update_repository_storage, 1]
- [project_update_repository_storage, 1]
- [admin_emails, 1]
- [admin_emails, 1]
...
...
ee/app/mailers/ee/notify.rb
View file @
c668cc55
...
@@ -7,6 +7,7 @@ module EE
...
@@ -7,6 +7,7 @@ module EE
include
::
Emails
::
AdminNotification
include
::
Emails
::
AdminNotification
include
::
Emails
::
CsvExport
include
::
Emails
::
CsvExport
include
::
Emails
::
ServiceDesk
include
::
Emails
::
ServiceDesk
include
::
Emails
::
Epics
attr_reader
:group
attr_reader
:group
end
end
...
...
ee/app/mailers/emails/epics.rb
0 → 100644
View file @
c668cc55
# frozen_string_literal: true
module
Emails
module
Epics
def
new_epic_email
(
recipient_id
,
epic_id
,
reason
=
nil
)
@epic
=
Epic
.
find_by_id
(
epic_id
)
return
unless
@epic
setup_epic_mail
(
recipient_id
)
mail_new_thread
(
@epic
,
epic_thread_options
(
@epic
.
author_id
,
recipient_id
,
reason
))
end
private
def
setup_epic_mail
(
recipient_id
)
@group
=
@epic
.
group
@target_url
=
group_epic_url
(
@epic
.
group
,
@epic
)
@sent_notification
=
SentNotification
.
record
(
@epic
,
recipient_id
,
reply_key
)
end
def
epic_thread_options
(
sender_id
,
recipient_id
,
reason
)
{
from:
sender
(
sender_id
),
to:
recipient
(
recipient_id
),
subject:
subject
(
"
#{
@epic
.
title
}
(
#{
@epic
.
to_reference
}
)"
),
'X-GitLab-NotificationReason'
=>
reason
}
end
end
end
ee/app/services/ee/notification_service.rb
View file @
c668cc55
...
@@ -38,6 +38,10 @@ module EE
...
@@ -38,6 +38,10 @@ module EE
end
end
end
end
def
new_epic
(
epic
)
new_resource_email
(
epic
,
:new_epic_email
)
end
def
project_mirror_user_changed
(
new_mirror_user
,
deleted_user_name
,
project
)
def
project_mirror_user_changed
(
new_mirror_user
,
deleted_user_name
,
project
)
mailer
.
project_mirror_user_changed_email
(
new_mirror_user
.
id
,
deleted_user_name
,
project
.
id
).
deliver_later
mailer
.
project_mirror_user_changed_email
(
new_mirror_user
.
id
,
deleted_user_name
,
project
.
id
).
deliver_later
end
end
...
...
ee/app/services/epics/create_service.rb
View file @
c668cc55
...
@@ -7,6 +7,14 @@ module Epics
...
@@ -7,6 +7,14 @@ module Epics
private
private
def
before_create
(
epic
)
# current_user (defined in BaseService) is not available within run_after_commit block
user
=
current_user
epic
.
run_after_commit
do
NewEpicWorker
.
perform_async
(
epic
.
id
,
user
.
id
)
end
end
def
whitelisted_epic_params
def
whitelisted_epic_params
params
.
slice
(
:title
,
:description
,
:start_date
,
:end_date
)
params
.
slice
(
:title
,
:description
,
:start_date
,
:end_date
)
end
end
...
...
ee/app/views/notify/new_epic_email.html.haml
0 → 100644
View file @
c668cc55
-
if
Gitlab
::
CurrentSettings
.
email_author_in_body
%p
.details
#{
link_to
@epic
.
author_name
,
user_url
(
@epic
.
author
)
}
created an epic:
-
if
@epic
.
assignee
%p
Assignee:
#{
@epic
.
assignee
.
name
}
-
if
@epic
.
description
%div
=
markdown
(
@epic
.
description
,
pipeline: :email
,
author:
@epic
.
author
)
ee/app/views/notify/new_epic_email.text.erb
0 → 100644
View file @
c668cc55
New Epic
<%=
@epic
.
to_reference
(
full:
true
)
%>
was created.
<%=
url_for
(
group_epic_url
(
@epic
.
group
,
@epic
))
%>
Author:
<%=
@epic
.
author_name
%>
<%
if
@epic
.
assignee
%>
Assignee:
<%=
@epic
.
assignee
.
name
%>
<%
end
%>
<%=
@epic
.
description
%>
ee/app/workers/new_epic_worker.rb
0 → 100644
View file @
c668cc55
# frozen_string_literal: true
class
NewEpicWorker
include
ApplicationWorker
include
NewIssuable
def
perform
(
epic_id
,
user_id
)
return
unless
objects_found?
(
epic_id
,
user_id
)
NotificationService
.
new
.
new_epic
(
issuable
)
issuable
.
create_cross_references!
(
user
)
end
def
issuable_class
Epic
end
end
ee/spec/mailers/notify_spec.rb
View file @
c668cc55
...
@@ -151,46 +151,77 @@ describe Notify do
...
@@ -151,46 +151,77 @@ describe Notify do
end
end
context
'for a group'
do
context
'for a group'
do
context
'for epic note
s'
do
describe
'for epic
s'
do
set
(
:group
)
{
create
(
:group
)
}
set
(
:group
)
{
create
(
:group
)
}
set
(
:epic
)
{
create
(
:epic
,
group:
group
)
}
set
(
:epic
)
{
create
(
:epic
,
group:
group
)
}
set
(
:note
)
{
create
(
:note
,
project:
nil
,
noteable:
epic
)
}
let
(
:note_author
)
{
note
.
author
}
let
(
:epic_note_path
)
{
group_epic_path
(
group
,
epic
,
anchor:
"note_
#{
note
.
id
}
"
)
}
subject
{
described_class
.
note_epic_email
(
recipient
.
id
,
note
.
id
)
}
context
'that are new'
do
subject
{
described_class
.
new_epic_email
(
recipient
.
id
,
epic
.
id
)
}
it_behaves_like
'a note email'
it_behaves_like
'an epic email starting a new thread with reply-by-email enabled'
do
let
(
:model
)
{
epic
}
end
it_behaves_like
'it should show Gmail Actions View Epic link'
it_behaves_like
'an unsubscribeable thread'
it
'has the correct subject and body'
do
prefix
=
"
#{
epic
.
group
.
name
}
| "
suffix
=
"
#{
epic
.
title
}
(
#{
epic
.
to_reference
}
)"
it_behaves_like
'an unsubscribeable thread'
aggregate_failures
do
is_expected
.
to
have_subject
[
prefix
,
suffix
].
compact
.
join
is_expected
.
to
have_body_text
(
group_epic_path
(
group
,
epic
))
end
end
it
'has the characteristics of a threaded reply'
do
context
'got deleted before notification'
do
host
=
Gitlab
.
config
.
gitlab
.
host
subject
{
described_class
.
new_epic_email
(
recipient
.
id
,
0
)
}
route_key
=
"
#{
epic
.
class
.
model_name
.
singular_route_key
}
_
#{
epic
.
id
}
"
aggregate_failures
do
it
'does not send email'
do
is_expected
.
to
have_header
(
'Message-ID'
,
/\A<.*@
#{
host
}
>\Z/
)
expect
(
subject
.
message
).
to
be_a_kind_of
ActionMailer
::
Base
::
NullMail
is_expected
.
to
have_header
(
'In-Reply-To'
,
"<
#{
route_key
}
@
#{
host
}
>"
)
end
is_expected
.
to
have_header
(
'References'
,
/\A<reply\-.*@
#{
host
}
> <
#{
route_key
}
@
#{
host
}
>\Z/
)
is_expected
.
to
have_subject
(
/^Re: /
)
end
end
end
end
context
'when reply-by-email is enabled with incoming address with %{key}'
do
context
'for epic notes'
do
it
'has a Reply-To header'
do
set
(
:note
)
{
create
(
:note
,
project:
nil
,
noteable:
epic
)
}
is_expected
.
to
have_header
'Reply-To'
,
/<reply+(.*)@
#{
Gitlab
.
config
.
gitlab
.
host
}
>\Z/
let
(
:note_author
)
{
note
.
author
}
let
(
:epic_note_path
)
{
group_epic_path
(
group
,
epic
,
anchor:
"note_
#{
note
.
id
}
"
)
}
subject
{
described_class
.
note_epic_email
(
recipient
.
id
,
note
.
id
)
}
it_behaves_like
'a note email'
it_behaves_like
'an unsubscribeable thread'
it
'has the characteristics of a threaded reply'
do
host
=
Gitlab
.
config
.
gitlab
.
host
route_key
=
"
#{
epic
.
class
.
model_name
.
singular_route_key
}
_
#{
epic
.
id
}
"
aggregate_failures
do
is_expected
.
to
have_header
(
'Message-ID'
,
/\A<.*@
#{
host
}
>\Z/
)
is_expected
.
to
have_header
(
'In-Reply-To'
,
"<
#{
route_key
}
@
#{
host
}
>"
)
is_expected
.
to
have_header
(
'References'
,
/\A<reply\-.*@
#{
host
}
> <
#{
route_key
}
@
#{
host
}
>\Z/
)
is_expected
.
to
have_subject
(
/^Re: /
)
end
end
end
end
it
{
is_expected
.
to
have_body_text
(
'View Epic'
)
}
context
'when reply-by-email is enabled with incoming address with %{key}'
do
it
'has a Reply-To header'
do
is_expected
.
to
have_header
'Reply-To'
,
/<reply+(.*)@
#{
Gitlab
.
config
.
gitlab
.
host
}
>\Z/
end
end
it
'has the correct subject and body'
do
it_behaves_like
'it should show Gmail Actions View Epic link'
prefix
=
"Re:
#{
epic
.
group
.
name
}
| "
suffix
=
"
#{
epic
.
title
}
(
#{
epic
.
to_reference
}
)"
aggregate_failures
do
it
'has the correct subject and body'
do
is_expected
.
to
have_subject
[
prefix
,
suffix
].
compact
.
join
prefix
=
"Re:
#{
epic
.
group
.
name
}
| "
is_expected
.
to
have_body_text
(
epic_note_path
)
suffix
=
"
#{
epic
.
title
}
(
#{
epic
.
to_reference
}
)"
aggregate_failures
do
is_expected
.
to
have_subject
[
prefix
,
suffix
].
compact
.
join
is_expected
.
to
have_body_text
(
epic_note_path
)
end
end
end
end
end
end
end
...
...
ee/spec/services/epics/create_service_spec.rb
View file @
c668cc55
...
@@ -9,12 +9,15 @@ describe Epics::CreateService do
...
@@ -9,12 +9,15 @@ describe Epics::CreateService do
describe
'#execute'
do
describe
'#execute'
do
it
'creates one issue correctly'
do
it
'creates one issue correctly'
do
allow
(
NewEpicWorker
).
to
receive
(
:perform_async
)
expect
{
subject
}.
to
change
{
Epic
.
count
}.
from
(
0
).
to
(
1
)
expect
{
subject
}.
to
change
{
Epic
.
count
}.
from
(
0
).
to
(
1
)
epic
=
Epic
.
last
epic
=
Epic
.
last
expect
(
epic
).
to
be_persisted
expect
(
epic
).
to
be_persisted
expect
(
epic
.
title
).
to
eq
(
'new epic'
)
expect
(
epic
.
title
).
to
eq
(
'new epic'
)
expect
(
epic
.
description
).
to
eq
(
'epic description'
)
expect
(
epic
.
description
).
to
eq
(
'epic description'
)
expect
(
NewEpicWorker
).
to
have_received
(
:perform_async
).
with
(
epic
.
id
,
user
.
id
)
end
end
end
end
end
end
ee/spec/support/shared_examples/notify_shared_examples.rb
0 → 100644
View file @
c668cc55
# frozen_string_literal: true
shared_examples
'it should show Gmail Actions View Epic link'
do
it_behaves_like
'it should have Gmail Actions links'
it
{
is_expected
.
to
have_body_text
(
'View Epic'
)
}
end
shared_examples
'an epic email starting a new thread with reply-by-email enabled'
do
include_examples
'a new thread email with reply-by-email enabled'
context
'when reply-by-email is enabled with incoming address with %{key}'
do
it
'has a Reply-To header'
do
is_expected
.
to
have_header
'Reply-To'
,
/<reply+(.*)@
#{
Gitlab
.
config
.
gitlab
.
host
}
>\Z/
end
end
context
'when reply-by-email is enabled with incoming address without %{key}'
do
include_context
'reply-by-email is enabled with incoming address without %{key}'
include_examples
'a new thread email with reply-by-email enabled'
it
'has a Reply-To header'
do
is_expected
.
to
have_header
'Reply-To'
,
/<reply@
#{
Gitlab
.
config
.
gitlab
.
host
}
>\Z/
end
end
end
ee/spec/workers/new_epic_worker_spec.rb
0 → 100644
View file @
c668cc55
# frozen_string_literal: true
require
'spec_helper'
describe
NewEpicWorker
do
describe
'#perform'
do
let
(
:worker
)
{
described_class
.
new
}
context
'when an epic not found'
do
it
'does not call Services'
do
expect
(
NotificationService
).
not_to
receive
(
:new
)
worker
.
perform
(
99
,
create
(
:user
).
id
)
end
it
'logs an error'
do
expect
(
Rails
.
logger
).
to
receive
(
:error
).
with
(
'NewEpicWorker: couldn\'t find Epic with ID=99, skipping job'
)
worker
.
perform
(
99
,
create
(
:user
).
id
)
end
end
context
'when a user not found'
do
it
'does not call Services'
do
expect
(
NotificationService
).
not_to
receive
(
:new
)
worker
.
perform
(
create
(
:epic
).
id
,
99
)
end
it
'logs an error'
do
expect
(
Rails
.
logger
).
to
receive
(
:error
).
with
(
'NewEpicWorker: couldn\'t find User with ID=99, skipping job'
)
worker
.
perform
(
create
(
:epic
).
id
,
99
)
end
end
context
'when everything is ok'
do
let
(
:mentioned
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:epic
)
{
create
(
:epic
,
description:
"epic for
#{
mentioned
.
to_reference
}
"
)
}
before
do
stub_licensed_features
(
epics:
true
)
end
it
'creates a notification for the mentioned user'
do
expect
(
Notify
).
to
receive
(
:new_epic_email
).
with
(
mentioned
.
id
,
epic
.
id
,
NotificationReason
::
MENTIONED
)
.
and_return
(
double
(
deliver_later:
true
))
worker
.
perform
(
epic
.
id
,
user
.
id
)
end
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