From 8d8757810c5452dea68335bc000ab30ef3e5830e Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 18 Sep 2025 16:15:33 +0200 Subject: [PATCH] refactor(EnvelopeController): move rejection and signing check to Main-endpoint --- .../Controllers/EnvelopeController.cs | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs b/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs index 2c64d0c2..d3df2949 100644 --- a/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs +++ b/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs @@ -75,6 +75,24 @@ public class EnvelopeController : ViewControllerBase if (er is null) return this.ViewEnvelopeNotFound(); + #region rejected or signed + //check rejection + var rejRcvrs = await _historyService.ReadRejectingReceivers(er.Envelope!.Id); + if (rejRcvrs.Any()) + { + await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); + ViewBag.IsExt = !rejRcvrs.Contains(er.Receiver); //external if the current user is not rejected + return View("EnvelopeRejected", er); + } + + //check if it has already signed + if (await _historyService.IsSigned(envelopeId: er.Envelope!.Id, userReference: er.Receiver!.EmailAddress)) + { + await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); + return View("EnvelopeSigned"); + } + #endregion + bool accessCodeAlreadyRequested = await _historyService.AccessCodeAlreadyRequested(envelopeId: er.Envelope!.Id, userReference: er.Receiver!.EmailAddress); if (!accessCodeAlreadyRequested) { @@ -146,23 +164,7 @@ public class EnvelopeController : ViewControllerBase _logger.LogInformation("Envelope UUID: [{uuid}]\nReceiver Signature: [{signature}]", uuid, signature); - //check rejection - var rejRcvrs = await _historyService.ReadRejectingReceivers(er.Envelope!.Id); - if (rejRcvrs.Any()) - { - await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); - ViewBag.IsExt = !rejRcvrs.Contains(er.Receiver); //external if the current user is not rejected - return View("EnvelopeRejected", er); - } - - //check if it has already signed - if (await _historyService.IsSigned(envelopeId: er.Envelope!.Id, userReference: er.Receiver!.EmailAddress)) - { - await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); - return View("EnvelopeSigned"); - } - - if (er.Envelope.Documents?.FirstOrDefault() is DocumentDto doc && doc.ByteData is not null) + if (er.Envelope!.Documents?.FirstOrDefault() is DocumentDto doc && doc.ByteData is not null) { ViewData["DocumentBytes"] = doc.ByteData; }