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
59bfa080
Commit
59bfa080
authored
8 years ago
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Send notification emails when users are newly mentioned in issue edits
parent
b2828d41
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
111 additions
and
3 deletions
+111
-3
app/mailers/emails/issues.rb
app/mailers/emails/issues.rb
+5
-0
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+2
-1
app/services/issues/update_service.rb
app/services/issues/update_service.rb
+6
-1
app/services/notification_service.rb
app/services/notification_service.rb
+23
-1
app/views/notify/new_mention_in_issue_email.html.haml
app/views/notify/new_mention_in_issue_email.html.haml
+9
-0
app/views/notify/new_mention_in_issue_email.text.erb
app/views/notify/new_mention_in_issue_email.text.erb
+7
-0
spec/services/issues/update_service_spec.rb
spec/services/issues/update_service_spec.rb
+33
-0
spec/services/notification_service_spec.rb
spec/services/notification_service_spec.rb
+26
-0
No files found.
app/mailers/emails/issues.rb
View file @
59bfa080
...
...
@@ -6,6 +6,11 @@ module Emails
mail_new_thread
(
@issue
,
issue_thread_options
(
@issue
.
author_id
,
recipient_id
))
end
def
new_mention_in_issue_email
(
recipient_id
,
issue_id
,
updated_by_user_id
)
setup_issue_mail
(
issue_id
,
recipient_id
)
mail_answer_thread
(
@issue
,
issue_thread_options
(
updated_by_user_id
,
recipient_id
))
end
def
reassigned_issue_email
(
recipient_id
,
issue_id
,
previous_assignee_id
,
updated_by_user_id
)
setup_issue_mail
(
issue_id
,
recipient_id
)
...
...
This diff is collapsed.
Click to expand it.
app/services/issuable_base_service.rb
View file @
59bfa080
...
...
@@ -104,11 +104,12 @@ class IssuableBaseService < BaseService
change_subscription
(
issuable
)
filter_params
old_labels
=
issuable
.
labels
.
to_a
old_mentioned_users
=
issuable
.
mentioned_users
.
to_a
if
params
.
present?
&&
update_issuable
(
issuable
,
params
)
issuable
.
reset_events_cache
handle_common_system_notes
(
issuable
,
old_labels:
old_labels
)
handle_changes
(
issuable
,
old_labels:
old_labels
)
handle_changes
(
issuable
,
old_labels:
old_labels
,
old_mentioned_users:
old_mentioned_users
)
issuable
.
create_new_cross_references!
(
current_user
)
execute_hooks
(
issuable
,
'update'
)
end
...
...
This diff is collapsed.
Click to expand it.
app/services/issues/update_service.rb
View file @
59bfa080
...
...
@@ -4,7 +4,7 @@ module Issues
update
(
issue
)
end
def
handle_changes
(
issue
,
old_labels:
[])
def
handle_changes
(
issue
,
old_labels:
[]
,
old_mentioned_users:
[]
)
if
has_changes?
(
issue
,
old_labels:
old_labels
)
todo_service
.
mark_pending_todos_as_done
(
issue
,
current_user
)
end
...
...
@@ -32,6 +32,11 @@ module Issues
if
added_labels
.
present?
notification_service
.
relabeled_issue
(
issue
,
added_labels
,
current_user
)
end
added_mentions
=
issue
.
mentioned_users
-
old_mentioned_users
if
added_mentions
.
present?
notification_service
.
new_mentions_in_issue
(
issue
,
added_mentions
,
current_user
)
end
end
def
reopen_service
...
...
This diff is collapsed.
Click to expand it.
app/services/notification_service.rb
View file @
59bfa080
...
...
@@ -35,6 +35,20 @@ class NotificationService
new_resource_email
(
issue
,
issue
.
project
,
:new_issue_email
)
end
# When issue text is updated, we should send an email to:
#
# * newly mentioned project team members with notification level higher than Participating
#
def
new_mentions_in_issue
(
issue
,
new_mentioned_users
,
current_user
)
new_mentions_in_resource_email
(
issue
,
issue
.
project
,
new_mentioned_users
,
current_user
,
:new_mention_in_issue_email
)
end
# When we close an issue we should send an email to:
#
# * issue author if their notification level is not Disabled
...
...
@@ -177,7 +191,7 @@ class NotificationService
# build notify method like 'note_commit_email'
notify_method
=
"note_
#{
note
.
noteable_type
.
underscore
}
_email"
.
to_sym
recipients
.
each
do
|
recipient
|
mailer
.
send
(
notify_method
,
recipient
.
id
,
note
.
id
).
deliver_later
end
...
...
@@ -471,6 +485,14 @@ class NotificationService
end
end
def
new_mentions_in_resource_email
(
target
,
project
,
new_mentioned_users
,
current_user
,
method
)
recipients
=
build_recipients
(
target
,
project
,
current_user
)
&
new_mentioned_users
recipients
.
each
do
|
recipient
|
mailer
.
send
(
method
,
recipient
.
id
,
target
.
id
,
current_user
.
id
).
deliver_later
end
end
def
close_resource_email
(
target
,
project
,
current_user
,
method
)
action
=
method
==
:merged_merge_request_email
?
"merge"
:
"close"
recipients
=
build_recipients
(
target
,
project
,
current_user
,
action:
action
)
...
...
This diff is collapsed.
Click to expand it.
app/views/notify/new_mention_in_issue_email.html.haml
0 → 100644
View file @
59bfa080
-
if
current_application_settings
.
email_author_in_body
%div
#{
link_to
@issue
.
author_name
,
user_url
(
@issue
.
author
)
}
wrote:
-
if
@issue
.
description
=
markdown
(
@issue
.
description
,
pipeline: :email
,
author:
@issue
.
author
)
-
if
@issue
.
assignee_id
.
present?
%p
Assignee:
#{
@issue
.
assignee_name
}
This diff is collapsed.
Click to expand it.
app/views/notify/new_mention_in_issue_email.text.erb
0 → 100644
View file @
59bfa080
You have been mentioned in an issue.
Issue
<%=
@issue
.
iid
%>
:
<%=
url_for
(
namespace_project_issue_url
(
@issue
.
project
.
namespace
,
@issue
.
project
,
@issue
))
%>
Author:
<%=
@issue
.
author_name
%>
Assignee:
<%=
@issue
.
assignee_name
%>
<%=
@issue
.
description
%>
This diff is collapsed.
Click to expand it.
spec/services/issues/update_service_spec.rb
View file @
59bfa080
...
...
@@ -319,5 +319,38 @@ describe Issues::UpdateService, services: true do
end
end
end
context
'updated user mentions'
do
let
(
:user4
)
{
create
(
:user
)
}
before
do
project
.
team
<<
[
user4
,
:developer
]
end
context
"in title"
do
before
do
perform_enqueued_jobs
{
update_issue
(
title:
user4
.
to_reference
)
}
end
it
"should email only the newly-mentioned user"
do
should_not_email
(
user
)
should_not_email
(
user2
)
should_not_email
(
user3
)
should_email
(
user4
)
end
end
context
"in description"
do
before
do
perform_enqueued_jobs
{
update_issue
(
description:
user4
.
to_reference
)
}
end
it
"should email only the newly-mentioned user"
do
should_not_email
(
user
)
should_not_email
(
user2
)
should_not_email
(
user3
)
should_email
(
user4
)
end
end
end
end
end
This diff is collapsed.
Click to expand it.
spec/services/notification_service_spec.rb
View file @
59bfa080
...
...
@@ -399,6 +399,32 @@ describe NotificationService, services: true do
end
end
describe
'#new_mentions_in_issue'
do
def
send_notifications
(
*
new_mentions
)
ActionMailer
::
Base
.
deliveries
.
clear
notification
.
new_mentions_in_issue
(
issue
,
new_mentions
,
@u_disabled
)
end
it
"should not email anyone unless they are newly mentioned"
do
send_notifications
()
expect
(
ActionMailer
::
Base
.
deliveries
).
to
eq
[]
end
it
"should email new mentions with a watch level higher than participant"
do
send_notifications
(
@u_watcher
,
@u_participant_mentioned
)
should_email
(
@u_watcher
)
should_email
(
@u_participant_mentioned
)
expect
(
ActionMailer
::
Base
.
deliveries
.
count
).
to
eq
2
end
it
"should not email new mentions with a watch level equal to or less than participant"
do
send_notifications
(
@u_participating
,
@u_mentioned
)
expect
(
ActionMailer
::
Base
.
deliveries
).
to
eq
[]
end
end
describe
'#reassigned_issue'
do
before
do
update_custom_notification
(
:reassign_issue
,
@u_guest_custom
,
project
)
...
...
This diff is collapsed.
Click to expand it.
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