Commit 466b768bb34730ee6a24d950333c232009c34bbd
1 parent
772f2f1a
Exists in
spb-stable
and in
2 other branches
Send notification emails to the "project", and put people in Cc
This fixes email threading in Mail.app, that doesn't like when a thread doesn't have stable recipients. For instance, here is a possible sender-recipient combinations before: From: A To: Me New issue From: B To: Me Reply on new issue From: A To: Me Another reply Mail.app doesn't see B as a participant to the original email thread, and decides to break the thread: it will group all messages from A together, and separately all messages from B. This commit makes the thread look like this: From: A To: gitlab/project Cc: Me New issue From: B To: gitlab/project Cc: Me Reply on new issue From: A To: gitlab/project Cc: Me Another reply Mail.app sees a common recipient, and group the thread correctly.
Showing
11 changed files
with
38 additions
and
24 deletions
Show diff stats
app/mailers/emails/groups.rb
@@ -4,7 +4,7 @@ module Emails | @@ -4,7 +4,7 @@ module Emails | ||
4 | @membership = UsersGroup.find(user_group_id) | 4 | @membership = UsersGroup.find(user_group_id) |
5 | @group = @membership.group | 5 | @group = @membership.group |
6 | @target_url = group_url(@group) | 6 | @target_url = group_url(@group) |
7 | - mail(to: @membership.user.email, | 7 | + mail(cc: @membership.user.email, |
8 | subject: subject("Access to group was granted")) | 8 | subject: subject("Access to group was granted")) |
9 | end | 9 | end |
10 | end | 10 | end |
app/mailers/emails/issues.rb
@@ -6,7 +6,7 @@ module Emails | @@ -6,7 +6,7 @@ module Emails | ||
6 | @target_url = project_issue_url(@project, @issue) | 6 | @target_url = project_issue_url(@project, @issue) |
7 | set_message_id("issue_#{issue_id}") | 7 | set_message_id("issue_#{issue_id}") |
8 | mail(from: sender(@issue.author_id), | 8 | mail(from: sender(@issue.author_id), |
9 | - to: recipient(recipient_id), | 9 | + cc: recipient(recipient_id), |
10 | subject: subject("#{@issue.title} (##{@issue.iid})")) | 10 | subject: subject("#{@issue.title} (##{@issue.iid})")) |
11 | end | 11 | end |
12 | 12 | ||
@@ -17,7 +17,7 @@ module Emails | @@ -17,7 +17,7 @@ module Emails | ||
17 | @target_url = project_issue_url(@project, @issue) | 17 | @target_url = project_issue_url(@project, @issue) |
18 | set_reference("issue_#{issue_id}") | 18 | set_reference("issue_#{issue_id}") |
19 | mail(from: sender(updated_by_user_id), | 19 | mail(from: sender(updated_by_user_id), |
20 | - to: recipient(recipient_id), | 20 | + cc: recipient(recipient_id), |
21 | subject: subject("#{@issue.title} (##{@issue.iid})")) | 21 | subject: subject("#{@issue.title} (##{@issue.iid})")) |
22 | end | 22 | end |
23 | 23 | ||
@@ -28,7 +28,7 @@ module Emails | @@ -28,7 +28,7 @@ module Emails | ||
28 | @target_url = project_issue_url(@project, @issue) | 28 | @target_url = project_issue_url(@project, @issue) |
29 | set_reference("issue_#{issue_id}") | 29 | set_reference("issue_#{issue_id}") |
30 | mail(from: sender(updated_by_user_id), | 30 | mail(from: sender(updated_by_user_id), |
31 | - to: recipient(recipient_id), | 31 | + cc: recipient(recipient_id), |
32 | subject: subject("#{@issue.title} (##{@issue.iid})")) | 32 | subject: subject("#{@issue.title} (##{@issue.iid})")) |
33 | end | 33 | end |
34 | 34 | ||
@@ -40,7 +40,7 @@ module Emails | @@ -40,7 +40,7 @@ module Emails | ||
40 | @target_url = project_issue_url(@project, @issue) | 40 | @target_url = project_issue_url(@project, @issue) |
41 | set_reference("issue_#{issue_id}") | 41 | set_reference("issue_#{issue_id}") |
42 | mail(from: sender(updated_by_user_id), | 42 | mail(from: sender(updated_by_user_id), |
43 | - to: recipient(recipient_id), | 43 | + cc: recipient(recipient_id), |
44 | subject: subject("#{@issue.title} (##{@issue.iid})")) | 44 | subject: subject("#{@issue.title} (##{@issue.iid})")) |
45 | end | 45 | end |
46 | end | 46 | end |
app/mailers/emails/merge_requests.rb
@@ -6,7 +6,7 @@ module Emails | @@ -6,7 +6,7 @@ module Emails | ||
6 | @target_url = project_merge_request_url(@project, @merge_request) | 6 | @target_url = project_merge_request_url(@project, @merge_request) |
7 | set_message_id("merge_request_#{merge_request_id}") | 7 | set_message_id("merge_request_#{merge_request_id}") |
8 | mail(from: sender(@merge_request.author_id), | 8 | mail(from: sender(@merge_request.author_id), |
9 | - to: recipient(recipient_id), | 9 | + cc: recipient(recipient_id), |
10 | subject: subject("#{@merge_request.title} (##{@merge_request.iid})")) | 10 | subject: subject("#{@merge_request.title} (##{@merge_request.iid})")) |
11 | end | 11 | end |
12 | 12 | ||
@@ -17,7 +17,7 @@ module Emails | @@ -17,7 +17,7 @@ module Emails | ||
17 | @target_url = project_merge_request_url(@project, @merge_request) | 17 | @target_url = project_merge_request_url(@project, @merge_request) |
18 | set_reference("merge_request_#{merge_request_id}") | 18 | set_reference("merge_request_#{merge_request_id}") |
19 | mail(from: sender(updated_by_user_id), | 19 | mail(from: sender(updated_by_user_id), |
20 | - to: recipient(recipient_id), | 20 | + cc: recipient(recipient_id), |
21 | subject: subject("#{@merge_request.title} (##{@merge_request.iid})")) | 21 | subject: subject("#{@merge_request.title} (##{@merge_request.iid})")) |
22 | end | 22 | end |
23 | 23 | ||
@@ -28,7 +28,7 @@ module Emails | @@ -28,7 +28,7 @@ module Emails | ||
28 | @target_url = project_merge_request_url(@project, @merge_request) | 28 | @target_url = project_merge_request_url(@project, @merge_request) |
29 | set_reference("merge_request_#{merge_request_id}") | 29 | set_reference("merge_request_#{merge_request_id}") |
30 | mail(from: sender(updated_by_user_id), | 30 | mail(from: sender(updated_by_user_id), |
31 | - to: recipient(recipient_id), | 31 | + cc: recipient(recipient_id), |
32 | subject: subject("#{@merge_request.title} (##{@merge_request.iid})")) | 32 | subject: subject("#{@merge_request.title} (##{@merge_request.iid})")) |
33 | end | 33 | end |
34 | 34 | ||
@@ -38,7 +38,7 @@ module Emails | @@ -38,7 +38,7 @@ module Emails | ||
38 | @target_url = project_merge_request_url(@project, @merge_request) | 38 | @target_url = project_merge_request_url(@project, @merge_request) |
39 | set_reference("merge_request_#{merge_request_id}") | 39 | set_reference("merge_request_#{merge_request_id}") |
40 | mail(from: sender(updated_by_user_id), | 40 | mail(from: sender(updated_by_user_id), |
41 | - to: recipient(recipient_id), | 41 | + cc: recipient(recipient_id), |
42 | subject: subject("#{@merge_request.title} (##{@merge_request.iid})")) | 42 | subject: subject("#{@merge_request.title} (##{@merge_request.iid})")) |
43 | end | 43 | end |
44 | end | 44 | end |
app/mailers/emails/notes.rb
@@ -6,7 +6,7 @@ module Emails | @@ -6,7 +6,7 @@ module Emails | ||
6 | @project = @note.project | 6 | @project = @note.project |
7 | @target_url = project_commit_url(@project, @commit, anchor: "note_#{@note.id}") | 7 | @target_url = project_commit_url(@project, @commit, anchor: "note_#{@note.id}") |
8 | mail(from: sender(@note.author_id), | 8 | mail(from: sender(@note.author_id), |
9 | - to: recipient(recipient_id), | 9 | + cc: recipient(recipient_id), |
10 | subject: subject("#{@commit.title} (#{@commit.short_id})")) | 10 | subject: subject("#{@commit.title} (#{@commit.short_id})")) |
11 | end | 11 | end |
12 | 12 | ||
@@ -17,7 +17,7 @@ module Emails | @@ -17,7 +17,7 @@ module Emails | ||
17 | @target_url = project_issue_url(@project, @issue, anchor: "note_#{@note.id}") | 17 | @target_url = project_issue_url(@project, @issue, anchor: "note_#{@note.id}") |
18 | set_reference("issue_#{@issue.id}") | 18 | set_reference("issue_#{@issue.id}") |
19 | mail(from: sender(@note.author_id), | 19 | mail(from: sender(@note.author_id), |
20 | - to: recipient(recipient_id), | 20 | + cc: recipient(recipient_id), |
21 | subject: subject("#{@issue.title} (##{@issue.iid})")) | 21 | subject: subject("#{@issue.title} (##{@issue.iid})")) |
22 | end | 22 | end |
23 | 23 | ||
@@ -28,7 +28,7 @@ module Emails | @@ -28,7 +28,7 @@ module Emails | ||
28 | @target_url = project_merge_request_url(@project, @merge_request, anchor: "note_#{@note.id}") | 28 | @target_url = project_merge_request_url(@project, @merge_request, anchor: "note_#{@note.id}") |
29 | set_reference("merge_request_#{@merge_request.id}") | 29 | set_reference("merge_request_#{@merge_request.id}") |
30 | mail(from: sender(@note.author_id), | 30 | mail(from: sender(@note.author_id), |
31 | - to: recipient(recipient_id), | 31 | + cc: recipient(recipient_id), |
32 | subject: subject("#{@merge_request.title} (##{@merge_request.iid})")) | 32 | subject: subject("#{@merge_request.title} (##{@merge_request.iid})")) |
33 | end | 33 | end |
34 | 34 | ||
@@ -37,7 +37,7 @@ module Emails | @@ -37,7 +37,7 @@ module Emails | ||
37 | @project = @note.project | 37 | @project = @note.project |
38 | @target_url = project_wall_url(@note.project, anchor: "note_#{@note.id}") | 38 | @target_url = project_wall_url(@note.project, anchor: "note_#{@note.id}") |
39 | mail(from: sender(@note.author_id), | 39 | mail(from: sender(@note.author_id), |
40 | - to: recipient(recipient_id), | 40 | + cc: recipient(recipient_id), |
41 | subject: subject("Note on wall")) | 41 | subject: subject("Note on wall")) |
42 | end | 42 | end |
43 | end | 43 | end |
app/mailers/emails/projects.rb
@@ -4,7 +4,7 @@ module Emails | @@ -4,7 +4,7 @@ module Emails | ||
4 | @users_project = UsersProject.find user_project_id | 4 | @users_project = UsersProject.find user_project_id |
5 | @project = @users_project.project | 5 | @project = @users_project.project |
6 | @target_url = project_url(@project) | 6 | @target_url = project_url(@project) |
7 | - mail(to: @users_project.user.email, | 7 | + mail(cc: @users_project.user.email, |
8 | subject: subject("Access to project was granted")) | 8 | subject: subject("Access to project was granted")) |
9 | end | 9 | end |
10 | 10 | ||
@@ -12,7 +12,7 @@ module Emails | @@ -12,7 +12,7 @@ module Emails | ||
12 | @user = User.find user_id | 12 | @user = User.find user_id |
13 | @project = Project.find project_id | 13 | @project = Project.find project_id |
14 | @target_url = project_url(@project) | 14 | @target_url = project_url(@project) |
15 | - mail(to: @user.email, | 15 | + mail(cc: @user.email, |
16 | subject: subject("Project was moved")) | 16 | subject: subject("Project was moved")) |
17 | end | 17 | end |
18 | 18 | ||
@@ -30,7 +30,7 @@ module Emails | @@ -30,7 +30,7 @@ module Emails | ||
30 | end | 30 | end |
31 | 31 | ||
32 | mail(from: sender(author_id), | 32 | mail(from: sender(author_id), |
33 | - to: recipient, | 33 | + cc: recipient, |
34 | subject: subject("New push to repository")) | 34 | subject: subject("New push to repository")) |
35 | end | 35 | end |
36 | end | 36 | end |
app/mailers/notify.rb
1 | class Notify < ActionMailer::Base | 1 | class Notify < ActionMailer::Base |
2 | + include ActionDispatch::Routing::PolymorphicRoutes | ||
3 | + | ||
2 | include Emails::Issues | 4 | include Emails::Issues |
3 | include Emails::MergeRequests | 5 | include Emails::MergeRequests |
4 | include Emails::Notes | 6 | include Emails::Notes |
@@ -16,6 +18,7 @@ class Notify < ActionMailer::Base | @@ -16,6 +18,7 @@ class Notify < ActionMailer::Base | ||
16 | default_url_options[:script_name] = Gitlab.config.gitlab.relative_url_root | 18 | default_url_options[:script_name] = Gitlab.config.gitlab.relative_url_root |
17 | 19 | ||
18 | default from: Proc.new { default_sender_address.format } | 20 | default from: Proc.new { default_sender_address.format } |
21 | + default to: Proc.new { project_sender_address.format } | ||
19 | default reply_to: "noreply@#{Gitlab.config.gitlab.host}" | 22 | default reply_to: "noreply@#{Gitlab.config.gitlab.host}" |
20 | 23 | ||
21 | # Just send email with 2 seconds delay | 24 | # Just send email with 2 seconds delay |
@@ -32,6 +35,17 @@ class Notify < ActionMailer::Base | @@ -32,6 +35,17 @@ class Notify < ActionMailer::Base | ||
32 | address | 35 | address |
33 | end | 36 | end |
34 | 37 | ||
38 | + # The default email address to send emails to. Includes the project name if possible. | ||
39 | + def project_sender_address | ||
40 | + if @project | ||
41 | + address = default_sender_address | ||
42 | + address.display_name = @project.name_with_namespace | ||
43 | + address | ||
44 | + else | ||
45 | + default_sender_address | ||
46 | + end | ||
47 | + end | ||
48 | + | ||
35 | # Return an email address that displays the name of the sender. | 49 | # Return an email address that displays the name of the sender. |
36 | # Only the displayed name changes; the actual email address is always the same. | 50 | # Only the displayed name changes; the actual email address is always the same. |
37 | def sender(sender_id) | 51 | def sender(sender_id) |
spec/mailers/notify_spec.rb
@@ -10,7 +10,7 @@ describe Notify do | @@ -10,7 +10,7 @@ describe Notify do | ||
10 | 10 | ||
11 | shared_examples 'a multiple recipients email' do | 11 | shared_examples 'a multiple recipients email' do |
12 | it 'is sent to the given recipient' do | 12 | it 'is sent to the given recipient' do |
13 | - should deliver_to recipient.email | 13 | + should cc_to recipient.email |
14 | end | 14 | end |
15 | end | 15 | end |
16 | 16 | ||
@@ -141,7 +141,7 @@ describe Notify do | @@ -141,7 +141,7 @@ describe Notify do | ||
141 | end | 141 | end |
142 | 142 | ||
143 | it 'is sent to the assignee' do | 143 | it 'is sent to the assignee' do |
144 | - should deliver_to assignee.email | 144 | + should cc_to assignee.email |
145 | end | 145 | end |
146 | end | 146 | end |
147 | 147 | ||
@@ -394,7 +394,7 @@ describe Notify do | @@ -394,7 +394,7 @@ describe Notify do | ||
394 | end | 394 | end |
395 | 395 | ||
396 | it 'is sent to the given recipient' do | 396 | it 'is sent to the given recipient' do |
397 | - should deliver_to recipient.email | 397 | + should cc_to recipient.email |
398 | end | 398 | end |
399 | 399 | ||
400 | it 'contains the message from the note' do | 400 | it 'contains the message from the note' do |
@@ -538,7 +538,7 @@ describe Notify do | @@ -538,7 +538,7 @@ describe Notify do | ||
538 | end | 538 | end |
539 | 539 | ||
540 | it 'is sent to recipient' do | 540 | it 'is sent to recipient' do |
541 | - should deliver_to 'devs@company.name' | 541 | + should cc_to 'devs@company.name' |
542 | end | 542 | end |
543 | 543 | ||
544 | it 'has the correct subject' do | 544 | it 'has the correct subject' do |
spec/services/issues/close_service_spec.rb
@@ -22,7 +22,7 @@ describe Issues::CloseService do | @@ -22,7 +22,7 @@ describe Issues::CloseService do | ||
22 | 22 | ||
23 | it 'should send email to user2 about assign of new issue' do | 23 | it 'should send email to user2 about assign of new issue' do |
24 | email = ActionMailer::Base.deliveries.last | 24 | email = ActionMailer::Base.deliveries.last |
25 | - email.to.first.should == user2.email | 25 | + email.cc.first.should == user2.email |
26 | email.subject.should include(issue.title) | 26 | email.subject.should include(issue.title) |
27 | end | 27 | end |
28 | 28 |
spec/services/issues/update_service_spec.rb
@@ -31,7 +31,7 @@ describe Issues::UpdateService do | @@ -31,7 +31,7 @@ describe Issues::UpdateService do | ||
31 | 31 | ||
32 | it 'should send email to user2 about assign of new issue' do | 32 | it 'should send email to user2 about assign of new issue' do |
33 | email = ActionMailer::Base.deliveries.last | 33 | email = ActionMailer::Base.deliveries.last |
34 | - email.to.first.should == user2.email | 34 | + email.cc.first.should == user2.email |
35 | email.subject.should include(issue.title) | 35 | email.subject.should include(issue.title) |
36 | end | 36 | end |
37 | 37 |
spec/services/merge_requests/close_service_spec.rb
@@ -22,7 +22,7 @@ describe MergeRequests::CloseService do | @@ -22,7 +22,7 @@ describe MergeRequests::CloseService do | ||
22 | 22 | ||
23 | it 'should send email to user2 about assign of new merge_request' do | 23 | it 'should send email to user2 about assign of new merge_request' do |
24 | email = ActionMailer::Base.deliveries.last | 24 | email = ActionMailer::Base.deliveries.last |
25 | - email.to.first.should == user2.email | 25 | + email.cc.first.should == user2.email |
26 | email.subject.should include(merge_request.title) | 26 | email.subject.should include(merge_request.title) |
27 | end | 27 | end |
28 | 28 |
spec/services/merge_requests/update_service_spec.rb
@@ -31,7 +31,7 @@ describe MergeRequests::UpdateService do | @@ -31,7 +31,7 @@ describe MergeRequests::UpdateService do | ||
31 | 31 | ||
32 | it 'should send email to user2 about assign of new merge_request' do | 32 | it 'should send email to user2 about assign of new merge_request' do |
33 | email = ActionMailer::Base.deliveries.last | 33 | email = ActionMailer::Base.deliveries.last |
34 | - email.to.first.should == user2.email | 34 | + email.cc.first.should == user2.email |
35 | email.subject.should include(merge_request.title) | 35 | email.subject.should include(merge_request.title) |
36 | end | 36 | end |
37 | 37 |