Skip to content

Commit

Permalink
🩹 [#4320] Fix crash when rendering PDF again for cosigned submission
Browse files Browse the repository at this point in the history
The PDF was including the cosign data/component for version 1 of cosign,
which is not compatible at all with v2 (see #4308), causing crashes.

Generally this doesn't matter since the PDF is generated right after
submission is received and before its cosigned, and we don't usually
need to re-generate it except during development.
  • Loading branch information
sergei-maertens committed Dec 5, 2024
1 parent b15fb4a commit 2ac376b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/openforms/submissions/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def co_signer(self) -> str:
if not (co_sign_data := self.submission.co_sign_data):
return ""

# XXX this is something present in cosign v2 but not v1, which happens after the
# PDF is generated. Generating the PDF again after it's cosigned otherwise
# crashes.
if "cosign_date" in co_sign_data:
return ""

representation = co_sign_data.get("representation") or ""
identifier = co_sign_data["identifier"]
co_sign_auth_attribute = co_sign_data["co_sign_auth_attribute"]
Expand Down
16 changes: 16 additions & 0 deletions src/openforms/submissions/tests/test_tasks_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,19 @@ def test_incomplete_cosign_data_missing_representation(self):
),
)
self.assertIn(identifier, rendered)

def test_cosign_v2_data(self):
report = SubmissionReportFactory.create(
content="",
submission__completed=True,
submission__co_sign_data={
"plugin": "digid",
"attribute": "bsn",
"value": "123456782",
"cosign_date": "2024-01-01T17:00:00Z",
},
)

html: str = report.generate_submission_report_pdf()

self.assertNotEqual(html, "")

0 comments on commit 2ac376b

Please sign in to comment.