From 4086ea35384f625a56a2f6867be627249ccc82c4 Mon Sep 17 00:00:00 2001 From: Sara Gowen <9001998+dynamictulip@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:37:17 +0100 Subject: [PATCH 01/17] Add check to see if User has access to FIAT --- .../Extensions/ClaimsPrincipleExtensions.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 DfE.FindInformationAcademiesTrusts/Extensions/ClaimsPrincipleExtensions.cs diff --git a/DfE.FindInformationAcademiesTrusts/Extensions/ClaimsPrincipleExtensions.cs b/DfE.FindInformationAcademiesTrusts/Extensions/ClaimsPrincipleExtensions.cs new file mode 100644 index 000000000..d4e8aaba3 --- /dev/null +++ b/DfE.FindInformationAcademiesTrusts/Extensions/ClaimsPrincipleExtensions.cs @@ -0,0 +1,11 @@ +using System.Security.Claims; + +namespace DfE.FindInformationAcademiesTrusts.Extensions; + +public static class ClaimsPrincipleExtensions +{ + public static bool HasAccessToFiat(this ClaimsPrincipal user) + { + return user.IsInRole("User.Role.Authorised"); + } +} From 1fa6d8a098855566aadef974d2346aa3a9726ace Mon Sep 17 00:00:00 2001 From: Sara Gowen <9001998+dynamictulip@users.noreply.github.com> Date: Thu, 10 Oct 2024 17:39:05 +0100 Subject: [PATCH 02/17] Hide header and footer areas not accessible to users without FIAT access Also test BasePageModel and ContentPageModel in their own dedicated test files and only test changes to default behaviour in subclasses --- .../Pages/Shared/BasePageModel.cs | 10 ++- .../Pages/Shared/ContentPageModel.cs | 12 ++- .../Pages/Shared/_Footer.cshtml | 26 ++++--- .../Pages/Shared/_Header.cshtml | 29 ++++---- .../Mocks/MockHttpContext.cs | 7 ++ .../Pages/ErrorModelTests.cs | 9 ++- .../Pages/Shared/BasePageModelTests.cs | 74 +++++++++++++++++++ .../Pages/Shared/ContentPageModelTests.cs | 56 ++++++++++++++ .../Pages/Trusts/GovernanceModelTests.cs | 6 -- 9 files changed, 195 insertions(+), 34 deletions(-) create mode 100644 tests/DfE.FindInformationAcademiesTrusts.UnitTests/Pages/Shared/BasePageModelTests.cs create mode 100644 tests/DfE.FindInformationAcademiesTrusts.UnitTests/Pages/Shared/ContentPageModelTests.cs diff --git a/DfE.FindInformationAcademiesTrusts/Pages/Shared/BasePageModel.cs b/DfE.FindInformationAcademiesTrusts/Pages/Shared/BasePageModel.cs index 418732a67..aa9ef52b6 100644 --- a/DfE.FindInformationAcademiesTrusts/Pages/Shared/BasePageModel.cs +++ b/DfE.FindInformationAcademiesTrusts/Pages/Shared/BasePageModel.cs @@ -1,3 +1,4 @@ +using DfE.FindInformationAcademiesTrusts.Extensions; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; @@ -5,6 +6,13 @@ namespace DfE.FindInformationAcademiesTrusts.Pages.Shared; public abstract class BasePageModel : PageModel { - public bool ShowHeaderSearch { get; init; } = true; + private readonly bool _showHeaderSearch = true; + + public bool ShowHeaderSearch + { + get => _showHeaderSearch && User.HasAccessToFiat(); + init => _showHeaderSearch = value; + } + [BindProperty(SupportsGet = true)] public string? KeyWords { get; set; } = string.Empty; } diff --git a/DfE.FindInformationAcademiesTrusts/Pages/Shared/ContentPageModel.cs b/DfE.FindInformationAcademiesTrusts/Pages/Shared/ContentPageModel.cs index 976c56db5..61cf454dd 100644 --- a/DfE.FindInformationAcademiesTrusts/Pages/Shared/ContentPageModel.cs +++ b/DfE.FindInformationAcademiesTrusts/Pages/Shared/ContentPageModel.cs @@ -1,6 +1,14 @@ +using DfE.FindInformationAcademiesTrusts.Extensions; + namespace DfE.FindInformationAcademiesTrusts.Pages.Shared; -public class ContentPageModel : BasePageModel +public abstract class ContentPageModel : BasePageModel { - public bool ShowBreadcrumb { get; set; } = true; + private bool _showBreadcrumb = true; + + public bool ShowBreadcrumb + { + get => _showBreadcrumb && User.HasAccessToFiat(); + set => _showBreadcrumb = value; + } } diff --git a/DfE.FindInformationAcademiesTrusts/Pages/Shared/_Footer.cshtml b/DfE.FindInformationAcademiesTrusts/Pages/Shared/_Footer.cshtml index 4791909d8..fbc074318 100644 --- a/DfE.FindInformationAcademiesTrusts/Pages/Shared/_Footer.cshtml +++ b/DfE.FindInformationAcademiesTrusts/Pages/Shared/_Footer.cshtml @@ -1,4 +1,5 @@ @using DfE.FindInformationAcademiesTrusts.Configuration +@using DfE.FindInformationAcademiesTrusts.Extensions