Commit 70947fedda4f955f69d928ad0309b3f042056582
1 parent
61824973
Exists in
master
and in
4 other branches
inslude author & assignee to note notification recipients
Showing
2 changed files
with
61 additions
and
28 deletions
Show diff stats
app/services/notification_service.rb
| ... | ... | @@ -106,12 +106,14 @@ class NotificationService |
| 106 | 106 | |
| 107 | 107 | if note.commit_id |
| 108 | 108 | opts.merge!(commit_id: note.commit_id) |
| 109 | + recipients = [note.commit_author] | |
| 109 | 110 | else |
| 110 | 111 | opts.merge!(noteable_id: note.noteable_id) |
| 112 | + recipients = [note.noteable.try(:author), note.noteable.try(:assignee)] | |
| 111 | 113 | end |
| 112 | 114 | |
| 113 | 115 | # Get users who left comment in thread |
| 114 | - recipients = User.where(id: Note.where(opts).pluck(:author_id)) | |
| 116 | + recipients = recipients.concat(User.where(id: Note.where(opts).pluck(:author_id))) | |
| 115 | 117 | |
| 116 | 118 | # Merge project watchers |
| 117 | 119 | recipients = recipients.concat(project_watchers(note.project)).compact.uniq | ... | ... |
spec/services/notification_service_spec.rb
| ... | ... | @@ -21,40 +21,71 @@ describe NotificationService do |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | 23 | describe 'Notes' do |
| 24 | - let(:note) { create :note_on_commit } | |
| 24 | + context 'issue note' do | |
| 25 | + let(:issue) { create(:issue, assignee: create(:user)) } | |
| 26 | + let(:note) { create(:note_on_issue, noteable: issue, project_id: issue.project_id) } | |
| 25 | 27 | |
| 26 | - before do | |
| 27 | - build_team(note.project) | |
| 28 | - end | |
| 29 | - | |
| 30 | - describe :new_note do | |
| 31 | - it do | |
| 32 | - should_email(@u_watcher.id) | |
| 33 | - should_not_email(note.author_id) | |
| 34 | - should_not_email(@u_participating.id) | |
| 35 | - should_not_email(@u_disabled.id) | |
| 36 | - notification.new_note(note) | |
| 28 | + before do | |
| 29 | + build_team(note.project) | |
| 37 | 30 | end |
| 38 | 31 | |
| 39 | - it do | |
| 40 | - create(:note_on_commit, | |
| 41 | - author: @u_participating, | |
| 42 | - project_id: note.project_id, | |
| 43 | - commit_id: note.commit_id) | |
| 32 | + describe :new_note do | |
| 33 | + it do | |
| 34 | + should_email(@u_watcher.id) | |
| 35 | + should_email(note.noteable.author_id) | |
| 36 | + should_email(note.noteable.assignee_id) | |
| 37 | + should_not_email(note.author_id) | |
| 38 | + should_not_email(@u_participating.id) | |
| 39 | + should_not_email(@u_disabled.id) | |
| 40 | + notification.new_note(note) | |
| 41 | + end | |
| 44 | 42 | |
| 45 | - should_email(@u_watcher.id) | |
| 46 | - should_email(@u_participating.id) | |
| 47 | - should_not_email(note.author_id) | |
| 48 | - should_not_email(@u_disabled.id) | |
| 49 | - notification.new_note(note) | |
| 50 | - end | |
| 43 | + def should_email(user_id) | |
| 44 | + Notify.should_receive(:note_issue_email).with(user_id, note.id) | |
| 45 | + end | |
| 51 | 46 | |
| 52 | - def should_email(user_id) | |
| 53 | - Notify.should_receive(:note_commit_email).with(user_id, note.id) | |
| 47 | + def should_not_email(user_id) | |
| 48 | + Notify.should_not_receive(:note_issue_email).with(user_id, note.id) | |
| 49 | + end | |
| 54 | 50 | end |
| 51 | + end | |
| 55 | 52 | |
| 56 | - def should_not_email(user_id) | |
| 57 | - Notify.should_not_receive(:note_commit_email).with(user_id, note.id) | |
| 53 | + context 'commit note' do | |
| 54 | + let(:note) { create :note_on_commit } | |
| 55 | + | |
| 56 | + before do | |
| 57 | + build_team(note.project) | |
| 58 | + end | |
| 59 | + | |
| 60 | + describe :new_note do | |
| 61 | + it do | |
| 62 | + should_email(@u_watcher.id) | |
| 63 | + should_not_email(note.author_id) | |
| 64 | + should_not_email(@u_participating.id) | |
| 65 | + should_not_email(@u_disabled.id) | |
| 66 | + notification.new_note(note) | |
| 67 | + end | |
| 68 | + | |
| 69 | + it do | |
| 70 | + create(:note_on_commit, | |
| 71 | + author: @u_participating, | |
| 72 | + project_id: note.project_id, | |
| 73 | + commit_id: note.commit_id) | |
| 74 | + | |
| 75 | + should_email(@u_watcher.id) | |
| 76 | + should_email(@u_participating.id) | |
| 77 | + should_not_email(note.author_id) | |
| 78 | + should_not_email(@u_disabled.id) | |
| 79 | + notification.new_note(note) | |
| 80 | + end | |
| 81 | + | |
| 82 | + def should_email(user_id) | |
| 83 | + Notify.should_receive(:note_commit_email).with(user_id, note.id) | |
| 84 | + end | |
| 85 | + | |
| 86 | + def should_not_email(user_id) | |
| 87 | + Notify.should_not_receive(:note_commit_email).with(user_id, note.id) | |
| 88 | + end | |
| 58 | 89 | end |
| 59 | 90 | end |
| 60 | 91 | end | ... | ... |