Skip to content

Commit

Permalink
Adding warning to user page when user has prohibition (#753)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKevJoy authored Oct 30, 2023
1 parent 821e5c5 commit 5b2a6bb
Show file tree
Hide file tree
Showing 25 changed files with 208 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,25 @@
}

@section BeforeContent {
<govuk-back-link asp-page="Users"/>
<govuk-back-link asp-page="Users" />
}

<h1 class="govuk-heading-l">
@Model.Name
</h1>


@if (Model.HasProhibitions)
{
<section class="govuk-!-margin-bottom-6">
<govuk-warning-text icon-fallback-text="Warning" data-testid="user-has-prohibitions">
<span>This user has prohibitions and cannot access every service</span>
</govuk-warning-text>
</section>
}



<section class="x-govuk-summary-card govuk-!-margin-bottom-6">
<header class="x-govuk-summary-card__header">
<h2 class="x-govuk-summary-card__title">
Expand Down Expand Up @@ -126,17 +138,17 @@
<govuk-summary-list-row-value>@Model.Trn</govuk-summary-list-row-value>
</govuk-summary-list-row>
@{
if(Model.EffectiveVerificationLevel == TrnVerificationLevel.Low)
if (Model.EffectiveVerificationLevel == TrnVerificationLevel.Low)
{
<govuk-summary-list-row>
<govuk-summary-list-row>
<govuk-summary-list-row-key>TRN verification level</govuk-summary-list-row-key>
<govuk-summary-list-row-value><govuk-tag class="govuk-tag--yellow">Low</govuk-tag></govuk-summary-list-row-value>
<govuk-summary-list-row-actions>
<govuk-summary-list-row-action asp-page="ElevateUserTrnVerification" asp-route-userId="@Model.UserId" visually-hidden-text="TRN verification level">Elevate</govuk-summary-list-row-action>
<govuk-summary-list-row-action asp-page="ElevateUserTrnVerification" asp-route-userId="@Model.UserId" visually-hidden-text="TRN verification level">Elevate</govuk-summary-list-row-action>
</govuk-summary-list-row-actions>
</govuk-summary-list-row>
</govuk-summary-list-row>
}
else if(Model.EffectiveVerificationLevel == TrnVerificationLevel.Medium)
else if (Model.EffectiveVerificationLevel == TrnVerificationLevel.Medium)
{
<govuk-summary-list-row>
<govuk-summary-list-row-key>TRN verification level</govuk-summary-list-row-key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public UserModel(TeacherIdentityServerDbContext dbContext, IDqtApiClient dqtApiC

public TrnVerificationLevel? EffectiveVerificationLevel { get; set; }

public bool HasProhibitions { get; set; }

[FromRoute]
public Guid UserId { get; set; }

Expand Down Expand Up @@ -112,6 +114,7 @@ public async Task<IActionResult> OnGet()
DqtName = $"{dqtUser.FirstName} {dqtUser.LastName}";
DqtDateOfBirth = dqtUser.DateOfBirth;
DqtNationalInsuranceNumber = dqtUser.NationalInsuranceNumber;
HasProhibitions = dqtUser.Alerts.Any(y => y.AlertType == AlertType.Prohibition);
}

return Page();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Flurl;
using TeacherIdentity.AuthServer.Infrastructure.Http;

Expand All @@ -7,6 +9,14 @@ public class DqtApiClient : IDqtApiClient
{
private readonly HttpClient _client;

private static JsonSerializerOptions _serializerOptions { get; } = new JsonSerializerOptions(JsonSerializerDefaults.Web)
{
Converters =
{
new JsonStringEnumConverter(),
}
};

public DqtApiClient(HttpClient httpClient)
{
_client = httpClient;
Expand Down Expand Up @@ -34,15 +44,15 @@ public async Task<FindTeachersResponse> FindTeachers(FindTeachersRequest request

public async Task<TeacherInfo?> GetTeacherByTrn(string trn, CancellationToken cancellationToken)
{
var response = await _client.GetAsync($"/v3/teachers/{trn}?include=PendingDetailChanges", cancellationToken);
var response = await _client.GetAsync($"/v3/teachers/{trn}?include=PendingDetailChanges,Alerts", cancellationToken);

if ((int)response.StatusCode == StatusCodes.Status404NotFound)
{
return null;
}

response.HandleErrorResponse();
return await response.Content.ReadFromJsonAsync<TeacherInfo>(cancellationToken: cancellationToken);
return await response.Content.ReadFromJsonAsync<TeacherInfo>(options: _serializerOptions, cancellationToken: cancellationToken);
}

public async Task<GetIttProvidersResponse> GetIttProviders(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

namespace TeacherIdentity.AuthServer.Services.DqtApi;

public record TeacherInfo
Expand All @@ -11,4 +12,17 @@ public record TeacherInfo
public required bool PendingNameChange { get; init; }
public required bool PendingDateOfBirthChange { get; init; }
public required string? Email { get; init; }
public required IReadOnlyCollection<AlertInfo> Alerts { get; init; }
}

public record AlertInfo
{
public required AlertType AlertType { get; init; }
public required string DqtSanctionCode { get; init; }
}

public enum AlertType
{
Prohibition
}

Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public async Task ChangeOfficialDateOfBirth()
PendingDateOfBirthChange = false,
PendingNameChange = false,
Trn = user.Trn!,
Email = null
Email = null,
Alerts = Array.Empty<AlertInfo>()
};

ConfigureDqtApiGetTeacherResponse(user.Trn!, dqtTeacherInfo);
Expand Down Expand Up @@ -157,7 +158,8 @@ public async Task ChangeOfficialName()
PendingDateOfBirthChange = false,
PendingNameChange = false,
Trn = user.Trn!,
Email = null
Email = null,
Alerts = Array.Empty<AlertInfo>()
};

ConfigureDqtApiGetTeacherResponse(user.Trn!, dqtTeacherInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public async Task UserSignsInWithLowVerificationLevel_IsRedirectedToElevateJourn
NationalInsuranceNumber = nino,
PendingDateOfBirthChange = false,
PendingNameChange = false,
Trn = user.Trn!
Trn = user.Trn!,
Alerts = Array.Empty<AlertInfo>()
});

await page.SubmitElevateCheckAnswersPage();
Expand Down Expand Up @@ -171,7 +172,8 @@ public async Task AlreadySignedInUserWithLowVerificationLevel_IsRedirectedToElev
NationalInsuranceNumber = nino,
PendingDateOfBirthChange = false,
PendingNameChange = false,
Trn = user.Trn!
Trn = user.Trn!,
Alerts = Array.Empty<AlertInfo>()
});

await page.SubmitElevateCheckAnswersPage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public async Task NewTeacherUser_WithTrnToken_CreatesUserAndCompletesFlow()
NationalInsuranceNumber = Faker.Identification.UkNationalInsuranceNumber(),
PendingDateOfBirthChange = false,
PendingNameChange = false,
Email = trnToken.Email
Email = trnToken.Email,
Alerts = Array.Empty<AlertInfo>()
});

await using var context = await _hostFixture.CreateBrowserContext();
Expand Down Expand Up @@ -92,7 +93,8 @@ public async Task NewTeacherUser_WithTrnTokenForDqtRecordWithMissingDateOfBirth_
NationalInsuranceNumber = Faker.Identification.UkNationalInsuranceNumber(),
PendingDateOfBirthChange = false,
PendingNameChange = false,
Email = trnToken.Email
Email = trnToken.Email,
Alerts = Array.Empty<AlertInfo>()
});

await using var context = await _hostFixture.CreateBrowserContext();
Expand Down Expand Up @@ -143,7 +145,8 @@ public async Task NewTeacherUser_WithTrnTokenChangesEmail_CreatesUserAndComplete
NationalInsuranceNumber = Faker.Identification.UkNationalInsuranceNumber(),
PendingDateOfBirthChange = false,
PendingNameChange = false,
Email = trnToken.Email
Email = trnToken.Email,
Alerts = Array.Empty<AlertInfo>()
});

await using var context = await _hostFixture.CreateBrowserContext();
Expand Down Expand Up @@ -769,7 +772,8 @@ public async Task NewTeacherUser_WithTrnTokenChangesToInstitutionEmail_CreatesUs
NationalInsuranceNumber = Faker.Identification.UkNationalInsuranceNumber(),
PendingDateOfBirthChange = false,
PendingNameChange = false,
Email = trnToken.Email
Email = trnToken.Email,
Alerts = Array.Empty<AlertInfo>()
});

var invalidEmailSuffix = "invalid.sch.uk";
Expand Down Expand Up @@ -929,7 +933,8 @@ private async Task<TrnTokenModel> CreateValidTrnToken(
NationalInsuranceNumber = Faker.Identification.UkNationalInsuranceNumber(),
PendingDateOfBirthChange = false,
PendingNameChange = false,
Email = email
Email = email,
Alerts = Array.Empty<AlertInfo>()
});

return await _hostFixture.TestData.GenerateTrnToken(trn, email: email);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using TeacherIdentity.AuthServer.Models;
using TeacherIdentity.AuthServer.Services.DqtApi;

namespace TeacherIdentity.AuthServer.Tests.EndpointTests.Account.DateOfBirth;

public class DateOfBirthTests : TestBase
Expand Down Expand Up @@ -189,7 +191,8 @@ private void MockDqtApiResponse(User user, bool hasDobConflict, bool hasPendingD
Trn = user.Trn!,
PendingNameChange = false,
PendingDateOfBirthChange = hasPendingDobChange,
Email = null
Email = null,
Alerts = Array.Empty<AlertInfo>()
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ public async Task Get_ValidRequestForUserWithTrn_ShowsOfficialNames(bool hasPref
Trn = user.Trn!,
PendingNameChange = false,
PendingDateOfBirthChange = false,
Email = null
Email = null,
Alerts = Array.Empty<AlertInfo>()
});

var request = new HttpRequestMessage(HttpMethod.Get, "/account");
Expand Down Expand Up @@ -186,7 +187,8 @@ public async Task Get_ValidRequestForUser_ShowsCorrectDobSummaryRowElements(
Trn = user.Trn!,
PendingNameChange = false,
PendingDateOfBirthChange = hasPendingReview,
Email = null
Email = null,
Alerts = Array.Empty<AlertInfo>()
});

var request = new HttpRequestMessage(HttpMethod.Get, "/account");
Expand Down Expand Up @@ -218,7 +220,8 @@ public async Task Get_ValidRequestForUserWithPendingNameChange_DoesShowPendingTa
Trn = user.Trn!,
PendingNameChange = true,
PendingDateOfBirthChange = false,
Email = null
Email = null,
Alerts = Array.Empty<AlertInfo>()
});

var request = new HttpRequestMessage(HttpMethod.Get, "/account");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ private void MockDqtApiResponse(User user, bool hasDobConflict, bool hasPendingD
Trn = user.Trn!,
PendingDateOfBirthChange = hasPendingDateOfBirthChange,
PendingNameChange = false,
Email = null
Email = null,
Alerts = Array.Empty<AlertInfo>()
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using TeacherIdentity.AuthServer.Services.DqtApi;
using User = TeacherIdentity.AuthServer.Models.User;

namespace TeacherIdentity.AuthServer.Tests.EndpointTests.Account.OfficialDateOfBirth;
Expand Down Expand Up @@ -180,7 +181,8 @@ private void MockDqtApiResponse(User user, bool hasDobConflict, bool hasPendingD
Trn = user.Trn!,
PendingDateOfBirthChange = hasPendingDateOfBirthChange,
PendingNameChange = false,
Email = null
Email = null,
Alerts = Array.Empty<AlertInfo>()
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using TeacherIdentity.AuthServer.Services.DqtApi;
using User = TeacherIdentity.AuthServer.Models.User;

namespace TeacherIdentity.AuthServer.Tests.EndpointTests.Account.OfficialDateOfBirth;
Expand Down Expand Up @@ -179,7 +180,8 @@ private void MockDqtApiResponse(User user, bool hasDobConflict, bool hasPendingD
Trn = user.Trn!,
PendingDateOfBirthChange = hasPendingDateOfBirthChange,
PendingNameChange = false,
Email = null
Email = null,
Alerts = Array.Empty<AlertInfo>()
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TeacherIdentity.AuthServer.Models;
using TeacherIdentity.AuthServer.Services.DqtApi;

namespace TeacherIdentity.AuthServer.Tests.EndpointTests.Account.OfficialDateOfBirth;

Expand Down Expand Up @@ -61,7 +62,8 @@ private void MockDqtApiResponse(User user, bool hasDobConflict, bool hasPendingD
Trn = user.Trn!,
PendingDateOfBirthChange = hasPendingDateOfBirthChange,
PendingNameChange = false,
Email = null
Email = null,
Alerts = Array.Empty<AlertInfo>()
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ private void MockDqtApiResponse(User user, bool hasPendingNameChange)
Trn = user.Trn!,
PendingDateOfBirthChange = false,
PendingNameChange = hasPendingNameChange,
Email = null
Email = null,
Alerts = Array.Empty<AlertInfo>()
});
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using TeacherIdentity.AuthServer.Services.DqtApi;
using User = TeacherIdentity.AuthServer.Models.User;

namespace TeacherIdentity.AuthServer.Tests.EndpointTests.Account.OfficialName;
Expand Down Expand Up @@ -203,7 +204,8 @@ private void MockDqtApiResponse(User user, bool hasPendingNameChange, string mid
Trn = user.Trn!,
PendingDateOfBirthChange = false,
PendingNameChange = hasPendingNameChange,
Email = null
Email = null,
Alerts = Array.Empty<AlertInfo>()
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.RegularExpressions;
using TeacherIdentity.AuthServer.Models;
using TeacherIdentity.AuthServer.Services.DqtApi;
using User = TeacherIdentity.AuthServer.Models.User;

namespace TeacherIdentity.AuthServer.Tests.EndpointTests.Account.OfficialName;
Expand Down Expand Up @@ -226,7 +227,8 @@ private void MockDqtApiResponse(User user, bool hasPendingNameChange)
Trn = user.Trn!,
PendingDateOfBirthChange = false,
PendingNameChange = hasPendingNameChange,
Email = null
Email = null,
Alerts = Array.Empty<AlertInfo>()
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TeacherIdentity.AuthServer.Models;
using TeacherIdentity.AuthServer.Services.DqtApi;

namespace TeacherIdentity.AuthServer.Tests.EndpointTests.Account.OfficialName;

Expand Down Expand Up @@ -62,7 +63,8 @@ private void MockDqtApiResponse(User user, bool hasPendingNameChange)
Trn = user.Trn!,
PendingDateOfBirthChange = false,
PendingNameChange = hasPendingNameChange,
Email = null
Email = null,
Alerts = Array.Empty<AlertInfo>()
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,8 @@ private void ConfigureDqtApiMock(
Trn = trn,
PendingNameChange = false,
PendingDateOfBirthChange = false,
Email = email ?? Faker.Internet.Email()
Email = email ?? Faker.Internet.Email(),
Alerts = Array.Empty<AlertInfo>()
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ private void ConfigureDqtApiMock(
Trn = trn,
PendingNameChange = false,
PendingDateOfBirthChange = false,
Email = email ?? Faker.Internet.Email()
Email = email ?? Faker.Internet.Email(),
Alerts = Array.Empty<AlertInfo>()
});
}
}
Loading

0 comments on commit 5b2a6bb

Please sign in to comment.