From 5e840db04ca18d4ec64873fee6d8feb2ebd5b235 Mon Sep 17 00:00:00 2001 From: TekH Date: Wed, 11 Mar 2026 12:05:20 +0100 Subject: [PATCH] Refactor envelope rejection logic in EnvelopeController Clarified and streamlined the handling of rejected envelopes: - Moved retrieval of rejecting receivers for clarity. - Signed out users when any rejecting receivers are present. - Improved determination of "external" users. - Updated condition for showing the EnvelopeRejected view. - Temporarily hardcoded ViewBag.IsExt with a TODO for future fix. - Removed redundant code for better maintainability. --- .../Controllers/EnvelopeController.cs | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs b/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs index 11f030cf..e8068bd2 100644 --- a/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs +++ b/EnvelopeGenerator.Web/Controllers/EnvelopeController.cs @@ -79,14 +79,16 @@ public class EnvelopeController : ViewControllerBase return this.ViewEnvelopeNotFound(); #region Rejected or Signed - //check rejection - if (er.Envelope.IsReadAndSign()) + var rejRcvrs = await _historyService.ReadRejectingReceivers(er.Envelope!.Id); + if (rejRcvrs.Any()) { - var rejRcvrs = await _historyService.ReadRejectingReceivers(er.Envelope!.Id); - if (rejRcvrs.Any()) + await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); + var isExt = !rejRcvrs.Where(rcv => rcv.Id == er.Receiver!.Id).Any(); //external if the current user is not rejected + + if (er.Envelope.IsReadAndSign() || !isExt) { - await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); - ViewBag.IsExt = !rejRcvrs.Contains(er.Receiver); //external if the current user is not rejected + //TODO: Normally assigned to the isExt variable. However, since the relevant keys are not defined in the resx files, it was assigned false. Fix this. + ViewBag.IsExt = true; return View("EnvelopeRejected", er); } } @@ -166,14 +168,17 @@ public class EnvelopeController : ViewControllerBase } var er_secret = er_secret_res.Data; - //check rejection if the envelope is read-and-sign - if (er_secret.Envelope.IsReadAndSign()) + var rejRcvrs = await _historyService.ReadRejectingReceivers(er_secret.Envelope!.Id); + if (rejRcvrs.Any()) { - var rejRcvrs = await _historyService.ReadRejectingReceivers(er_secret.Envelope!.Id); - if (rejRcvrs.Any()) + await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); + var isExt = !rejRcvrs.Where(rcv => rcv.Id == er_secret.Receiver!.Id).Any(); //external if the current user is not rejected + + //check rejection if the envelope is read-and-sign or non-external (internal) + if (er_secret.Envelope.IsReadAndSign() || !isExt) { - await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); - ViewBag.IsExt = !rejRcvrs.Contains(er_secret.Receiver); //external if the current user is not rejected + //TODO: Normally assigned to the isExt variable. However, since the relevant keys are not defined in the resx files, it was assigned false. Fix this. + ViewBag.IsExt = true; return View("EnvelopeRejected", er_secret); } }