Skip to content

Ensure we always render mails in the context of the recipient - #27357

Merged
oliverguenther merged 3 commits into
release/17.9from
fix/notification-sender
Nov 27, 2026
Merged

oliverguenther merged 3 commits into
release/17.9from
fix/notification-sender

Conversation

@oliverguenther

Copy link
Copy Markdown
Member

Ticket

https://community.openproject.org/work_packages/SC-355

What are you trying to accomplish?

ApplicationMailer#mail now runs inside User.execute_as(recipient). All fomatted texts and references will be resolved using the recipient user.

Previously, the mailers were not consistent in selecting a user to execute with. Only MemberMailer, WorkPackageMailer and the meeting mailers already switched the user.

News, comments, forum messages, documents, announcements, project creation mails and the configurable mail header/footer rendered as whoever was current, which is the anonymous user in background jobs and the author when delivered inline.

Some of these mailers still do their own switch in a block, as that code runs BEFORE the mail method is called.

AI involvement

Collaborative – AI generated a substantial part of the code; I reviewed and understand every line.

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

ApplicationMailer#mail now runs inside User.execute_as(recipient).
All fomatted texts and references will be resolved using the recipient user.

Previously, the mailers were not consistent in selecting a user to execute with.
Only MemberMailer, WorkPackageMailer and the meeting mailers already switched the user.

News, comments, forum messages, documents, announcements, project creation mails and the configurable mail
header/footer rendered as whoever was current, which is the anonymous user in background jobs and the author when delivered inline.

Some of these mailers still do their own switch in a block, as that code runs BEFORE the mail method is called.

https://community.openproject.org/work_packages/SC-355
@github-actions github-actions Bot added the ai: Collaborative 💻 AI generated a substantial part of the code; A human reviewed and understands every line. label Nov 26, 2026
@klaustopher

Copy link
Copy Markdown
Contributor

Shall we also remove the other switches and leave the tests in place, that they still do the right thing?

MemberMailer and WorkPackageMailer switched to the recipient only to render the mail body.
ApplicationMailer#mail now does this for every mail.

The meeting mailers need the wrapper because they build the ICS in the recipient's locale before mail gets called.
@oliverguenther

Copy link
Copy Markdown
Member Author

Shall we also remove the other switches and leave the tests in place, that they still do the right thing?

We can do that for some of the calls, not for all (as some are called before mail). I've added a commit for the obvious ones where it should be fine

klaustopher
klaustopher previously approved these changes Nov 26, 2026
Backporting the fix resulted in broken specs. The release branch has no UserMailer#message_mentioned and spells the
wizard mailer ProjectArtifactsMailer
@oliverguenther
oliverguenther merged commit 6fe22bf into release/17.9 Nov 27, 2026
15 checks passed
@oliverguenther
oliverguenther deleted the fix/notification-sender branch November 27, 2026 07:42
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ai: Collaborative 💻 AI generated a substantial part of the code; A human reviewed and understands every line.

Development

Successfully merging this pull request may close these issues.

2 participants