Skip to content

Commit

Permalink
Ensure evidence file names don't exceed limit
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad committed Dec 1, 2023
1 parent 457c0c8 commit 0bfa429
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<IActionResult> OnPost()
var teacherDobChangeRequest = new TeacherDateOfBirthChangeRequest()
{
DateOfBirth = DateOfBirth!.Value,
EvidenceFileName = FileName!,
EvidenceFileName = FileName!.Truncate(DqtApiClient.MaxEvidenceFileNameLength),
EvidenceFileUrl = sasUri,
Trn = User.GetTrn()!
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Humanizer;

Check failure on line 1 in dotnet-authserver/src/TeacherIdentity.AuthServer/Pages/Account/OfficialName/Confirm.cshtml.cs

View workflow job for this annotation

GitHub Actions / Build & test

Using directive is unnecessary.
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.RazorPages;
Expand Down Expand Up @@ -68,7 +69,7 @@ public async Task<IActionResult> OnPost()
FirstName = FirstName!,
MiddleName = MiddleName,
LastName = LastName!,
EvidenceFileName = FileName!,
EvidenceFileName = FileName!.Truncate(DqtApiClient.MaxEvidenceFileNameLength),
EvidenceFileUrl = sasUri,
Trn = User.GetTrn()!
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace TeacherIdentity.AuthServer.Services.DqtApi;

public class DqtApiClient : IDqtApiClient
{
public const int MaxEvidenceFileNameLength = 100;

private readonly HttpClient _client;

private static JsonSerializerOptions _serializerOptions { get; } = new JsonSerializerOptions(JsonSerializerDefaults.Web)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ namespace TeacherIdentity.AuthServer;
public static class StringExtensions
{
public static string? ToNullIfEmpty(this string? value) => string.IsNullOrWhiteSpace(value) ? null : value;

public static string Truncate(this string value, int maxLength) => value.Length > maxLength ? value[..maxLength] : value;
}

0 comments on commit 0bfa429

Please sign in to comment.