Use semantic work package identifier in sharing email links

The shared-work-package email built its "Open work package" link and its
text-part heading from the numeric primary key, so recipients on a
semantic-identifier instance still landed on /work_packages/<numeric-id>
rather than the semantic URL.

Pass the work package itself to the URL helper so to_param yields the
display id, and render the text heading with formatted_id to match the
other work package mailers. Also drops an unused @notification_url that
carried the same numeric-id problem.

STC-747
This commit is contained in:
Kabiru Mwenja
2026-06-02 09:55:45 +03:00
parent ffd69cd874
commit b2d93c3a00
3 changed files with 22 additions and 5 deletions
+1 -2
View File
@@ -40,8 +40,7 @@ class SharingMailer < ApplicationMailer
@work_package = membership.entity
role = membership.roles.first
@url = optionally_activated_url(work_package_url(@work_package.id), @invitation_token)
@notification_url = optionally_activated_url(details_notifications_url(@work_package.id, tab: :activity), @invitation_token)
@url = optionally_activated_url(work_package_url(@work_package), @invitation_token)
set_open_project_headers(@work_package)
message_id(membership, sharer)
@@ -18,9 +18,9 @@
%>
<%= "-" * 100 %>
<%= "=" * (("# " + @work_package.id.to_s + @work_package.subject).length + 4) %>
= #<%= @work_package.id %> <%= @work_package.subject %> =
<%= "=" * (("# " + @work_package.id.to_s + @work_package.subject).length + 4) %>
<%= "=" * ("#{@work_package.formatted_id} #{@work_package.subject}".length + 4) %>
= <%= @work_package.formatted_id %> <%= @work_package.subject %> =
<%= "=" * ("#{@work_package.formatted_id} #{@work_package.subject}".length + 4) %>
<%= I18n.t("mail.work_packages.reason.shared") %>:
<%= t("mail.sharing.work_packages.allowed_actions_html", allowed_actions: @allowed_work_package_actions.to_sentence) %>
+18
View File
@@ -64,6 +64,11 @@ RSpec.describe SharingMailer do
expect(mail.subject)
.to eq(I18n.t("mail.sharing.work_packages.subject", id: "##{work_package.id}"))
end
it "links to the work package by its numeric id" do
expect(mail.html_part.body.encoded).to include("/work_packages/#{work_package.id}")
expect(mail.text_part.body.encoded).to include("/work_packages/#{work_package.id}")
end
end
context "with semantic mode",
@@ -81,6 +86,19 @@ RSpec.describe SharingMailer do
expect(mail.subject)
.to eq(I18n.t("mail.sharing.work_packages.subject", id: "PROJ-42"))
end
it "links to the work package by its semantic identifier, not the numeric id" do
expect(mail.html_part.body.encoded).to include("/work_packages/PROJ-42")
expect(mail.html_part.body.encoded).not_to include("/work_packages/#{work_package.id}")
expect(mail.text_part.body.encoded).to include("/work_packages/PROJ-42")
expect(mail.text_part.body.encoded).not_to include("/work_packages/#{work_package.id}")
end
it "renders the text-part heading with the semantic identifier, not the numeric id" do
expect(mail.text_part.body.encoded).to include("= PROJ-42 #{work_package.subject} =")
expect(mail.text_part.body.encoded).not_to include("##{work_package.id}")
end
end
it "has a project header" do