Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add Mail Headers to shared_work_package mail

Aaron Contrerasd520f40f33a8
diff --git a/app/mailers/sharing_mailer.rb b/app/mailers/sharing_mailer.rb
index 27bf0aa7d13..80ce2cee311 100644
--- a/app/mailers/sharing_mailer.rb
+++ b/app/mailers/sharing_mailer.rb
@@ -10,9 +10,11 @@ class SharingMailer < ApplicationMailer
role = membership.roles.first
@role_rights = derive_role_rights(role)
@allowed_work_package_actions = derive_allowed_work_package_actions(role)
-
recipient = membership.principal
+ set_open_project_headers(@work_package)
+ message_id(membership, sharer)
+
with_locale_for(recipient) do
mail to: recipient.mail,
subject: I18n.t('mail.sharing.work_packages.subject',
@@ -52,4 +54,10 @@ class SharingMailer < ApplicationMailer
allowed_actions.to_sentence
end
+
+ def set_open_project_headers(work_package)
+ open_project_headers 'Project' => work_package.project.identifier,
+ 'WorkPackage-Id' => work_package.id,
+ 'Type' => 'WorkPackage'
+ end
end
diff --git a/spec/mailers/sharing_mailer_spec.rb b/spec/mailers/sharing_mailer_spec.rb
index 508268458c5..089798891f8 100644
--- a/spec/mailers/sharing_mailer_spec.rb
+++ b/spec/mailers/sharing_mailer_spec.rb
@@ -35,6 +35,7 @@ RSpec.describe SharingMailer do
let(:work_package) do
build_stubbed(:work_package,
type: build_stubbed(:type_standard),
+ author: build_stubbed(:user),
project:)
end
let(:shared_with_user) { build_stubbed(:user) }
@@ -63,5 +64,27 @@ RSpec.describe SharingMailer do
.to eq(I18n.t('mail.sharing.work_packages.subject',
id: work_package.id))
end
+
+ it 'has a project header' do
+ expect(mail['X-OpenProject-Project'].value)
+ .to eq(project.identifier)
+ end
+
+ it 'has a work package id header' do
+ expect(mail['X-OpenProject-WorkPackage-Id'].value)
+ .to eq(work_package.id.to_s)
+ end
+
+ it 'has a type header' do
+ expect(mail['X-OpenProject-Type'].value)
+ .to eq('WorkPackage')
+ end
+
+ it 'has a message id header' do
+ Timecop.freeze(Time.current) do
+ expect(mail.message_id)
+ .to eq("op.member-#{work_package_member.id}.#{Time.current.strftime('%Y%m%d%H%M%S')}.#{current_user.id}@example.net")
+ end
+ end
end
end