Skip to content

feat: optional one-line subject for chatter_post - #76

Open
bitclicklabs wants to merge 1 commit into
erpipe-org:mainfrom
bitclicklabs:feat/chatter-post-subject
Open

bitclicklabs wants to merge 1 commit into
erpipe-org:mainfrom
bitclicklabs:feat/chatter-post-subject

Conversation

@bitclicklabs

Copy link
Copy Markdown

Summary

chatter_post accepts an optional subject, passed to message_post(subject=...).

Without a subject, Odoo titles the notification email of a chatter comment with the record name (for example INV/2026/00036). Callers that send customer-facing messages (a comment with the Discussions subtype, addressed to a partner via partner_ids) therefore had to fall back to an allow-listed <model>.message_post call through execute_method. With a subject they can stay on chatter_post and its approval gate.

The subject is:

  • one line: Unicode control characters (Cc) and line/paragraph separators (Zl, Zp) become spaces, and whitespace runs collapse. This also rules out email header injection (\r\nBcc: ...).
  • bounded: at most 200 characters after normalization; longer values are rejected with a clear error rather than truncated.
  • plain text, not HTML-escaped: mail.message.subject is a Char field (Odoo 19 mail_message.py). Odoo escapes it when rendering the chatter and uses it as the email Subject header, so HTML-escaping it here would show &amp; to recipients. The compose smoke checks it is stored verbatim.
  • covered by the approval token: it is part of the canonical payload, so changing or dropping it after preview invalidates the token. A blank subject is treated as absent, and subject-less posts keep exactly the previous token.

Recipients: partner_ids and subtype_xmlid were already supported. For a comment, followers of the subtype are notified too, as in the Odoo UI; that is now stated in the tool docstring.

Coverage

  • Odoo versions tested: 16.0, 19.0 (live, Docker Compose)
  • Transports tested: stdio MCP over xmlrpc and json2 (Odoo 19), xmlrpc (Odoo 16)

Verification

uv run python -m ruff check .
uv run python -m mypy src
uv run python -m pytest
uv run --with import-linter lint-imports
uv run python scripts/odoo_compose_smoke.py --versions 19.0 16.0 --timeout 420
  • New tests/test_chatter_subject.py: no subject; subject passed with partner_ids and subtype_xmlid; multi-line / control-character subject flattened to one line and not HTML-escaped; blank subject treated as absent (same token); length limit; token invalidated when the subject changes or is dropped.
  • The compose smoke now posts a subject containing & and <b> and checks the stored mail.message.subject matches exactly. Passed on 19.0 and 16.0.
  • ruff, mypy, lint-imports clean. pytest: only the pre-existing Windows-only test_from_path_rejects_file_swapped_for_symlink_after_root_check fails, as it does on main.

Independent of #72, #73 and #74; it touches chatter_post near #74, so whichever lands second needs a small rebase.

Without a subject, Odoo titles the notification email of a chatter comment
with the record name (for example "INV/2026/00036"), so callers that send
customer-facing messages had to fall back to an allow-listed
<model>.message_post instead of chatter_post.

chatter_post now takes an optional subject, passed to message_post(subject=).
It is plain text on one line, at most 200 characters: control characters
and line breaks become spaces (this also rules out email header
injection) and whitespace runs collapse. It is not HTML-escaped, because
mail.message.subject is a Char field that Odoo escapes at render time.

The subject is part of the canonical payload, so the approval token covers
it. Subject-less posts keep their previous token. The compose smoke now
posts a subject with & and <b> and checks it is stored verbatim.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants