From b2d93c3a00fe27e5e020347a8761f6663105c06b Mon Sep 17 00:00:00 2001 From: Kabiru Mwenja Date: Tue, 2 Jun 2026 09:55:45 +0300 Subject: [PATCH] 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/ 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 --- app/mailers/sharing_mailer.rb | 3 +-- .../shared_work_package.text.erb | 6 +++--- spec/mailers/sharing_mailer_spec.rb | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/mailers/sharing_mailer.rb b/app/mailers/sharing_mailer.rb index af5f409d15c..ca9dbbb9df2 100644 --- a/app/mailers/sharing_mailer.rb +++ b/app/mailers/sharing_mailer.rb @@ -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) diff --git a/app/views/sharing_mailer/shared_work_package.text.erb b/app/views/sharing_mailer/shared_work_package.text.erb index 4e48dd1f14a..e5f9d2cdb84 100644 --- a/app/views/sharing_mailer/shared_work_package.text.erb +++ b/app/views/sharing_mailer/shared_work_package.text.erb @@ -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) %> diff --git a/spec/mailers/sharing_mailer_spec.rb b/spec/mailers/sharing_mailer_spec.rb index ca0e658230e..1820ebdd7e7 100644 --- a/spec/mailers/sharing_mailer_spec.rb +++ b/spec/mailers/sharing_mailer_spec.rb @@ -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