Fix - Notification template cache shared between users #22104
+248 −13
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Checklist before requesting a review
Please delete options that are not relevant.
Description
Fixes an issue where notification template caching was shared between users of the same type and language, preventing plugins from generating user-specific data (like unique tokens or URLs) for each recipient.
This is a less invasive alternative to #20186 which was closed because the solution was too impactful.
Problem
When multiple users receive the same notification (e.g., two observers on a ticket), the template is cached based only on language and additional options. Plugins using the
ITEM_GET_DATAhook (like ApprovalByMail) cannot generate unique data per recipient becausegetForTemplate()is only called once per language.As a result, all recipients receive identical tokens/URLs in their emails.
Solution
Following @cedric-anne's suggestion from #20186:
users_idoremail) in template cache key$user_infostogetForTemplate()and store it in a newcurrent_user_infosproperty onNotificationTarget$target->current_user_infosduringITEM_GET_DATAhook to identify the current recipientChanges
src/NotificationTemplate.php: Add user identifier to cache key, pass user_infos in optionssrc/NotificationTarget.php: Addcurrent_user_infosproperty, populate it ingetForTemplate().phpstan-baseline.php: Remove obsolete entries (return type is now correctlystring)Related