Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HEEDLS-465 - Made Support page redirect to home if permissions don't … #460

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public static class ControllerContextHelper
public const int AdminId = 7;
public const int DelegateId = 2;
public const string EmailAddress = "email";
public const bool IsCentreAdmin = false;
public const bool IsFrameworkDeveloper = false;

public static T WithDefaultContext<T>(this T controller) where T : Controller
{
Expand Down Expand Up @@ -44,7 +46,9 @@ public static T WithMockUser<T>(
int centreId = CentreId,
int? adminId = AdminId,
int? delegateId = DelegateId,
string? emailAddress = EmailAddress
string? emailAddress = EmailAddress,
bool isCentreAdmin = IsCentreAdmin,
bool isFrameworkDeveloper = IsFrameworkDeveloper
) where T : Controller
{
var authenticationType = isAuthenticated ? "mock" : string.Empty;
Expand All @@ -58,6 +62,8 @@ public static T WithMockUser<T>(
new Claim(CustomClaimTypes.UserAdminId, adminId?.ToString() ?? "False"),
new Claim(CustomClaimTypes.LearnCandidateId, delegateId?.ToString() ?? "False"),
new Claim(ClaimTypes.Email, emailAddress ?? string.Empty),
new Claim(CustomClaimTypes.UserCentreAdmin, isCentreAdmin.ToString()),
new Claim(CustomClaimTypes.IsFrameworkDeveloper, isFrameworkDeveloper.ToString())
},
authenticationType
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
namespace DigitalLearningSolutions.Web.Tests.Controllers.Support
{
using DigitalLearningSolutions.Web.Controllers.Support;
using DigitalLearningSolutions.Web.Tests.ControllerHelpers;
using FluentAssertions.AspNetCore.Mvc;
using NUnit.Framework;

public class SupportControllerTests
{
private SupportController controller = null!;

[SetUp]
public void SetUp()
[Test]
public void Frameworks_Support_page_should_be_shown_for_valid_claims()
{
controller = new SupportController();
}
// Given
var controller = new SupportController()
.WithDefaultContext()
.WithMockUser(true, isCentreAdmin: false, isFrameworkDeveloper: true);

[TestCase("TrackingSystem")]
[TestCase("Frameworks")]
public void Support_page_should_be_shown_for_valid_application_names(string applicationName)
{
// When
var result = controller.Index(applicationName);
var result = controller.Index("Frameworks");

// Then
result.Should().BeViewResult().WithViewName("Support");
Expand All @@ -28,11 +25,46 @@ public void Support_page_should_be_shown_for_valid_application_names(string appl
[Test]
public void Invalid_application_name_should_redirect_to_404_page()
{
// Given
var controller = new SupportController()
.WithDefaultContext()
.WithMockUser(true, isCentreAdmin: true, isFrameworkDeveloper: true);

// When
var result = controller.Index("Main");

// Then
result.Should().BeNotFoundResult();
}

[Test]
public void Home_page_should_be_shown_when_accessing_tracking_system_support_without_appropriate_claims()
{
// Given
var controller = new SupportController()
.WithDefaultContext()
.WithMockUser(true, isCentreAdmin: false, isFrameworkDeveloper: true);

// When
var result = controller.Index("TrackingSystem");

// Then
result.Should().BeRedirectToActionResult().WithControllerName("Home").WithActionName("Index");
}

[Test]
public void Home_page_should_be_shown_when_accessing_frameworks_support_without_appropriate_claims()
{
// Given
var controller = new SupportController()
.WithDefaultContext()
.WithMockUser(true, isCentreAdmin: true, isFrameworkDeveloper: false);

// When
var result = controller.Index("Frameworks");

// Then
result.Should().BeRedirectToActionResult().WithControllerName("Home").WithActionName("Index");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ public class SupportController : Controller
[Authorize(Policy = CustomPolicies.UserCentreAdminOrFrameworksAdmin)]
public IActionResult Index(ApplicationType application)
{
if (ApplicationType.TrackingSystem.Equals(application) ||
ApplicationType.Frameworks.Equals(application))
if (!ApplicationType.TrackingSystem.Equals(application) &&
!ApplicationType.Frameworks.Equals(application))
{
return NotFound();
}

if (ApplicationType.TrackingSystem.Equals(application) && User.HasCentreAdminPermissions() ||
ApplicationType.Frameworks.Equals(application) && User.HasFrameworksAdminPermissions())
{
var model = new SupportViewModel(application, SupportPage.Support);
return View("Support", model);
}

return NotFound();
return RedirectToAction("Index", "Home");
}
}
}
2 changes: 1 addition & 1 deletion DigitalLearningSolutions.Web/Styles/support/support.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@import "~nhsuk-frontend/packages/core/all";

ol>li {
@include nhsuk-responsive-margin(5, "bottom");
margin-bottom: nhsuk-spacing(6)
}