Skip to content

Fix/annex mailer admin view - #643

Open
tsubik wants to merge 2 commits into
developfrom
fix/annex-mailer-admin-view
Open

Fix/annex mailer admin view#643
tsubik wants to merge 2 commits into
developfrom
fix/annex-mailer-admin-view

Conversation

@tsubik

@tsubik tsubik commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Fix annex mailer crash for history-only annexes

Sentry: undefined method 'name_with_fmu' for nil in document_valid.html.mjml.

Cause

When an operator uploads a new version of a document (or the document is
destroyed), OperatorDocument#disconnect_annexes drops the annex→document
join rows, keeping only the join to OperatorDocumentHistory. From then on
annex.operator_document is nil, while annex.operator still resolves via
the history — so notify_about_changes passes its operator.present? guard,
the mail is sent, and the views blow up on the nil document. Admins can still
approve/reject such annexes from the annex list, which is what triggered it.

Changes

  • OperatorDocumentAnnex#related_operator_document — the live document, or
    the last history entry. #operator and #operator_document_name now go
    through it, so the notification guard and the mail body use the same object.
  • OperatorDocumentHistory#name / #name_with_fmu, mirroring OperatorDocument.
  • Mailer assigns @operator_document / @operator_document_name once; the six
    annex mail views use them.
  • History-based documents are labelled (History version) — in the mails
    (translated: en/fr/es) and in the Documents column of the admin annex list,
    which now also links to the history record instead of rendering blank.

Tests

  • spec/mailers/operator_document_annex_mailer_spec.rb — all three mails, with
    the annex attached and history-only, plus the fr translation of the suffix.
  • spec/controllers/admin/operator_document_annexes_controller_spec.rb — the
    Documents column in both states.

@tsubik
tsubik requested a review from santostiago September 3, 2026 08:10
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.

1 participant