From 10af11f4fe71e46d4decd2ab428e9b2b38e2d463 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Mon, 15 Aug 2016 15:15:20 +0100 Subject: [PATCH] Allow people to subscribe to mentions in updated MRs and Issues This slightly changes the semantics of the 'New Issue' and 'New MR' events to include new mentions in edited Mentionables. An alternative would be to introduce 'Issue updated' and 'MR updated' events, but that would lead to questions about why those events were only available to new mentions, and not existing mentions as well, so hold off for now. --- app/services/notification_service.rb | 3 ++- doc/workflow/notifications.md | 7 ++++++- spec/services/notification_service_spec.rb | 12 ++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index 01f95281170..2291bc0f127 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -500,7 +500,8 @@ class NotificationService 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 = build_recipients(target, project, current_user, action: "new") + recipients = recipients & new_mentioned_users recipients.each do |recipient| mailer.send(method, recipient.id, target.id, current_user.id).deliver_later diff --git a/doc/workflow/notifications.md b/doc/workflow/notifications.md index b4a9c2f3d3e..1b49a5c385f 100644 --- a/doc/workflow/notifications.md +++ b/doc/workflow/notifications.md @@ -67,7 +67,7 @@ In all of the below cases, the notification will be sent to: - Participants: - the author and assignee of the issue/merge request - authors of comments on the issue/merge request - - anyone mentioned by `@username` in the issue/merge request description + - anyone mentioned by `@username` in the issue/merge request title or description - anyone mentioned by `@username` in any of the comments on the issue/merge request ...with notification level "Participating" or higher @@ -89,6 +89,11 @@ In all of the below cases, the notification will be sent to: | Merge merge request | | | New comment | The above, plus anyone mentioned by `@username` in the comment, with notification level "Mention" or higher | + +In addition, if the title or description of an Issue or Merge Request is +changed, notifications will be sent to any **new** mentions by `@username` as +if they had been mentioned in the original text. + You won't receive notifications for Issues, Merge Requests or Milestones created by yourself. You will only receive automatic notifications when somebody else comments or adds changes to the ones that you've created or diff --git a/spec/services/notification_service_spec.rb b/spec/services/notification_service_spec.rb index 2fa0d9f1ac2..fbca28bbb17 100644 --- a/spec/services/notification_service_spec.rb +++ b/spec/services/notification_service_spec.rb @@ -411,12 +411,13 @@ describe NotificationService, services: true do end it "should email new mentions with a watch level higher than participant" do - send_notifications(@u_watcher, @u_participant_mentioned) + send_notifications(@u_watcher, @u_participant_mentioned, @u_custom_global) should_email(@u_watcher) should_email(@u_participant_mentioned) + should_email(@u_custom_global) - expect(ActionMailer::Base.deliveries.count).to eq 2 + expect(ActionMailer::Base.deliveries.count).to eq 3 end it "should not email new mentions with a watch level equal to or less than participant" do @@ -726,6 +727,8 @@ describe NotificationService, services: true do before do build_team(merge_request.target_project) add_users_with_subscription(merge_request.target_project, merge_request) + update_custom_notification(:new_merge_request, @u_guest_custom, project) + update_custom_notification(:new_merge_request, @u_custom_global) ActionMailer::Base.deliveries.clear end @@ -801,12 +804,13 @@ describe NotificationService, services: true do end it "should email new mentions with a watch level higher than participant" do - send_notifications(@u_watcher, @u_participant_mentioned) + send_notifications(@u_watcher, @u_participant_mentioned, @u_custom_global) should_email(@u_watcher) should_email(@u_participant_mentioned) + should_email(@u_custom_global) - expect(ActionMailer::Base.deliveries.count).to eq 2 + expect(ActionMailer::Base.deliveries.count).to eq 3 end it "should not email new mentions with a watch level equal to or less than participant" do -- GitLab