[FIX] mail_notification_custom_subject: read templates with sudo#186
Open
sanderlienaerts wants to merge 1 commit intoOCA:18.0from
Open
Conversation
The mail.thread override searches mail.message.custom.subject with sudo and then explicitly drops back to the caller's env with .sudo(False). When iterating the resulting recordset, field reads trigger ACL checks against the caller. Portal and public users are allowed to trigger message_post through portal controllers (which typically call record.sudo().message_post), but they lack read access to mail.message.custom.subject — an internal-only ACL. The resulting AccessError is silently caught by the per-template try/except, but the custom subject is never applied for those users, and the raw AccessError can leak when field access is triggered outside the try block (e.g. via prefetch on related fields). Templates are admin-managed configuration records, akin to mail.template. They should be read with sudo, while rendering still honors the caller's permissions on the business record via res_ids. Add a test that reproduces the portal-user path: runs as a portal user (asserts base.group_portal / not base.group_user), posts via partner.sudo().message_post(..., author_id=portal_user.partner_id) — the exact pattern used by portal controllers. Without the fix the subject falls back to the default "Re: <name>"; with the fix it is rendered from the template.
Contributor
|
Hi @yajo, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
mail.thread.message_postoverride in this module does:The
.sudo(False)explicitly drops back to the caller's environment. When a non-internal user (portal or public) triggersmessage_post— typically via a portal controller that doesrecord.sudo().message_post(...)— the subsequent field reads check ACL against the caller. The module's ACL only grantsbase.group_userread andbase.group_systemfull access onmail.message.custom.subject, so portal/public users get anAccessError.The per-template
try/except Exceptioncatches the error, so the message gets posted without the custom subject being applied (silent degradation). However theAccessErrorcan also leak from places outside the try block — e.g. prefetch on related fields triggered by iteration — and surfaces to the caller as a hard failure.Fix (this PR)
Read the templates with sudo and drop the
.sudo(False)switch-back. These templates are admin-managed configuration records, analogous tomail.template/ir.sequence, and should always be readable by whoever invokesmessage_post. Template rendering itself still honors the caller's permissions on the business record viares_ids, so evaluating{{object.xxx}}expressions remains bounded by the user's access on the business model.Alternative approach considered
Instead of the code change, the ACL could be extended with explicit portal and public read access:
This preserves the
.sudo(False)pattern and makes permissions explicit. Trade-offs vs. the current PR:base.group_portalandbase.group_public; the pattern remains inconsistent — the.sudo()before.search(domain)already acknowledges that all matching templates must be found regardless of caller permissions, so it is odd to then flip back to.sudo(False)only for the reads that follow.mail.templateis handled in Odoo core (admin-managed rendering config, always read with sudo during message flows).Happy to switch to the ACL approach if maintainers prefer that.
Test
Added
test_email_subject_template_portal_userthat:base.group_portaluser.partner.sudo().message_post(...)— the exact pattern used by portal controllers.Without this fix the test fails (subject falls back to
Re: Test partner 1); with the fix it passes.