<commit_before>﻿using System.Net;
using System.Web;
using System.Web.Mvc;
using SFA.DAS.ProviderApprenticeshipsService.Web.Extensions;
using SFA.DAS.ProviderApprenticeshipsService.Web.Services;

namespace SFA.DAS.ProviderApprenticeshipsService.Web.Attributes
{
    public class RoatpCourseManagementCheckActionFilter : IActionFilter
    {
        private readonly IGetRoatpBetaProviderService _roatpProviderService;
        
        public RoatpCourseManagementCheckActionFilter(IGetRoatpBetaProviderService roatpProviderService)
        {
            _roatpProviderService = roatpProviderService;
        }

        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var ukprn = filterContext.HttpContext.GetClaimValue("http://schemas.portal.com/ukprn");
            
             if (string.IsNullOrEmpty(ukprn) || !int.TryParse(ukprn, out var ukprnValue ))
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "Missing provider id");
            }

             var isRoatpCourseManagementLinkEnabled = _roatpProviderService.IsUkprnEnabled(ukprnValue);
             if (!HttpContext.Current.Items.Contains(RoatpConstants.IsCourseManagementLinkEnabled))
                    HttpContext.Current.Items.Add(RoatpConstants.IsCourseManagementLinkEnabled, isRoatpCourseManagementLinkEnabled);
        }

        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
        }
    }
}<commit_msg>CSP-220 comment added as required by SonarCloud<commit_after>﻿using System.Net;
using System.Web;
using System.Web.Mvc;
using SFA.DAS.ProviderApprenticeshipsService.Web.Extensions;
using SFA.DAS.ProviderApprenticeshipsService.Web.Services;

namespace SFA.DAS.ProviderApprenticeshipsService.Web.Attributes
{
    public class RoatpCourseManagementCheckActionFilter : IActionFilter
    {
        private readonly IGetRoatpBetaProviderService _roatpProviderService;
        
        public RoatpCourseManagementCheckActionFilter(IGetRoatpBetaProviderService roatpProviderService)
        {
            _roatpProviderService = roatpProviderService;
        }

        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var ukprn = filterContext.HttpContext.GetClaimValue("http://schemas.portal.com/ukprn");
            
             if (string.IsNullOrEmpty(ukprn) || !int.TryParse(ukprn, out var ukprnValue ))
            {
                throw new HttpException((int)HttpStatusCode.BadRequest, "Missing provider id");
            }

             var isRoatpCourseManagementLinkEnabled = _roatpProviderService.IsUkprnEnabled(ukprnValue);
             if (!HttpContext.Current.Items.Contains(RoatpConstants.IsCourseManagementLinkEnabled))
                    HttpContext.Current.Items.Add(RoatpConstants.IsCourseManagementLinkEnabled, isRoatpCourseManagementLinkEnabled);
        }

        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
            // No code required for OnActionExecuted, but method required by IActionFilter
            // SonarCloud wanted a comment
        }
    }
}
{'fraction_non_alphanumeric': 0.06819630337794774, 'fraction_numerical': 0.0009560229445506692, 'mean_word_length': 3.196524064171123, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3962237', 'n_tokens_mistral': 872, 'n_tokens_neox': 844, 'n_words': 130}