Skip to content

[17.0][ADD] mail_attachment_xml_preview: preview XML attachments as a collapsible tree - #257

Merged
OCA-git-bot merged 1 commit into
OCA:17.0from
Jarsa-dev:17.0-add-mail_attachment_xml_preview
Aug 26, 2026
Merged

OCA-git-bot merged 1 commit into
OCA:17.0from
Jarsa-dev:17.0-add-mail_attachment_xml_preview

Conversation

@alan196

@alan196 alan196 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Replaces OCA/knowledge#636: moved here and renamed after @pedrobaeza's suggestion, since the module is about mail attachments and is not a derivative of attachment_preview.

Summary

New module that renders XML attachments in the standard file viewer as an indented, collapsible tree instead of a wall of raw text.

Context

ir.attachment._check_contents neutralizes xml-like mimetypes to text/plain for every user without write access on views, so XML attachments end up in the plain-text branch of the FileViewer. Machine-generated XML (electronic invoices such as CFDI or UBL, bank statements, EDI messages) is usually serialized on a single line, which makes that preview unreadable.

How it works

  • A JS patch on the mail Attachment model adds isXml (by extension, or by mimetype when it survives), removes those files from the isText branch and keeps them viewable.
  • XmlViewer fetches the attachment, parses it with DOMParser and renders the tree with plain <details>/<summary> elements, so collapsing is native HTML: no library, no server-side conversion, no external service.
  • Malformed XML, or content over 5 MB, falls back to the raw text instead of showing nothing.
  • No Python code and no new dependencies: the module ships assets only.

Test plan

  • QUnit tests on the parser (hierarchy, attributes, comments, text-only nodes, malformed input), run in CI through an HttpCase that loads the module suite in a real browser.
  • Manually validated on 17.0 with a single-line CFDI 4.0 attached to a chatter: the tree renders and every branch collapses; a deliberately malformed XML falls back to raw text.

@pedrobaeza pedrobaeza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging as already approved in the previous repository.

/ocabot merge nobump

@OCA-git-bot

Copy link
Copy Markdown
Contributor

On my way to merge this fine PR!
Prepared branch 17.0-ocabot-merge-pr-257-by-pedrobaeza-bump-nobump, awaiting test results.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

@pedrobaeza your merge command was aborted due to failed check(s), which you can inspect on this commit of 17.0-ocabot-merge-pr-257-by-pedrobaeza-bump-nobump.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

@pedrobaeza

Copy link
Copy Markdown
Member

/ocabot merge nobump

@OCA-git-bot

Copy link
Copy Markdown
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 17.0-ocabot-merge-pr-257-by-pedrobaeza-bump-nobump, awaiting test results.

@OCA-git-bot
OCA-git-bot merged commit 810f92d into OCA:17.0 Aug 26, 2026
9 of 13 checks passed
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at f7cd230. Thanks a lot for contributing to OCA. ❤️

@alan196
alan196 deleted the 17.0-add-mail_attachment_xml_preview branch August 26, 2026 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants