From 7b25b167f3839316f1fce844f56e60888bde09e2 Mon Sep 17 00:00:00 2001 From: Rohit Shrivastava Date: Thu, 28 Aug 2025 09:21:56 +0100 Subject: [PATCH] TD-6108 Updating ServiceFilter Logic To Exclude Other Areas --- .../RequireProcessAgreementFilter .cs | 69 ++++++++++--------- 1 file changed, 36 insertions(+), 33 deletions(-) diff --git a/DigitalLearningSolutions.Web/ServiceFilter/RequireProcessAgreementFilter .cs b/DigitalLearningSolutions.Web/ServiceFilter/RequireProcessAgreementFilter .cs index 2328fab15f..67e11614a0 100644 --- a/DigitalLearningSolutions.Web/ServiceFilter/RequireProcessAgreementFilter .cs +++ b/DigitalLearningSolutions.Web/ServiceFilter/RequireProcessAgreementFilter .cs @@ -24,47 +24,50 @@ public void OnActionExecuted(ActionExecutedContext context) { } public void OnActionExecuting(ActionExecutingContext context) { - if (!(context.Controller is Controller controller)) + if (context.HttpContext.Request.Path.ToString().Contains("/LearningPortal/SelfAssessment/")) { - return; - } + if (!(context.Controller is Controller controller)) + { + return; + } - if (!context.ActionArguments.ContainsKey("selfAssessmentId")) - { - return; - } + if (!context.ActionArguments.ContainsKey("selfAssessmentId")) + { + return; + } - var selfAssessmentId = int.Parse(context.ActionArguments["selfAssessmentId"].ToString()!); - var delegateUserId = controller.User.GetUserIdKnownNotNull(); + var selfAssessmentId = int.Parse(context.ActionArguments["selfAssessmentId"].ToString()!); + var delegateUserId = controller.User.GetUserIdKnownNotNull(); - var selfAssessment = selfAssessmentService.GetSelfAssessmentForCandidateById(delegateUserId, selfAssessmentId); + var selfAssessment = selfAssessmentService.GetSelfAssessmentForCandidateById(delegateUserId, selfAssessmentId); - if (selfAssessment == null) - { - logger.LogWarning( - $"Attempt to access self assessment {selfAssessmentId} by user {delegateUserId}, but no such assessment found" - ); - context.Result = new RedirectToActionResult("StatusCode", "LearningSolutions", new { code = 403 }); - return; - } + if (selfAssessment == null) + { + logger.LogWarning( + $"Attempt to access self assessment {selfAssessmentId} by user {delegateUserId}, but no such assessment found" + ); + context.Result = new RedirectToActionResult("StatusCode", "LearningSolutions", new { code = 403 }); + return; + } - var actionName = context.RouteData.Values["action"]?.ToString(); - if (actionName == "AgreeSelfAssessmentProcess" || actionName == "ProcessAgreed") - { - return; - } + var actionName = context.RouteData.Values["action"]?.ToString(); + if (actionName == "AgreeSelfAssessmentProcess" || actionName == "ProcessAgreed") + { + return; + } - if (!selfAssessment.SelfAssessmentProcessAgreed && selfAssessment.IsSupervised) - { - logger.LogInformation( - $"Redirecting user {delegateUserId} to agree process page for self assessment {selfAssessmentId}" - ); + if (!selfAssessment.SelfAssessmentProcessAgreed && selfAssessment.IsSupervised) + { + logger.LogInformation( + $"Redirecting user {delegateUserId} to agree process page for self assessment {selfAssessmentId}" + ); - context.Result = new RedirectToActionResult( - "AgreeSelfAssessmentProcess", - "LearningPortal", - new { selfAssessmentId } - ); + context.Result = new RedirectToActionResult( + "AgreeSelfAssessmentProcess", + "LearningPortal", + new { selfAssessmentId } + ); + } } } }