From d350e2ae4852627eb5a977d839403b42fd58acb6 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 27 Jan 2026 11:49:19 +0100 Subject: [PATCH] Add envelope validation to BurnAnnotsToPDF function Retrieve envelope by ID before burning annotations. Throw an exception if not found, and return the original PDF if the envelope is read-only. This adds validation and early exit logic before processing signatures and annotations. --- .../Jobs/FinalizeDocument/PDFBurner.vb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/PDFBurner.vb b/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/PDFBurner.vb index b3329496..781615ac 100644 --- a/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/PDFBurner.vb +++ b/EnvelopeGenerator.CommonServices/Jobs/FinalizeDocument/PDFBurner.vb @@ -37,6 +37,15 @@ Namespace Jobs.FinalizeDocument Public Function BurnAnnotsToPDF(pSourceBuffer As Byte(), pInstantJSONList As List(Of String), envelopeId As Integer) As Byte() 'read the elements of envelope with their annotations Using scope = Factory.Shared.ScopeFactory.CreateScope() + + Dim envRepo = scope.ServiceProvider.Repository(Of Envelope)() + Dim envelope = envRepo.Where(Function(env) env.Id = envelopeId).FirstOrDefault() + If envelope Is Nothing Then + Throw New BurnAnnotationException($"Envelope with Id {envelopeId} not found.") + ElseIf envelope.ReadOnly Then + Return pSourceBuffer + End If + Dim sigRepo = scope.ServiceProvider.Repository(Of Signature)() Dim elements = sigRepo _ .Where(Function(sig) sig.Document.EnvelopeId = envelopeId) _