diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AlertDetail.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AlertDetail.cshtml index 1cd59ef4a..fdcc9b258 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AlertDetail.cshtml +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AlertDetail.cshtml @@ -15,6 +15,15 @@ Details @Model.Alert.Details + + Link + + @if (Model.Alert.ExternalLink is not null) + { + @Model.Alert.ExternalLink + } + + Start date @Model.Alert.StartDate?.ToString("d MMMM yyyy") @@ -30,4 +39,22 @@ } + + Reason for closing alert + @Model.ChangeReason + + + Reason details + + @if (Model.ChangeReasonDetail is not null) + { + + } + else + { + + } + + + diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AlertDetail.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AlertDetail.cshtml.cs index b8c9b9a2a..eadf7c9c9 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AlertDetail.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/AlertDetail.cshtml.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using TeachingRecordSystem.Core.DataStore.Postgres; using TeachingRecordSystem.Core.DataStore.Postgres.Models; using TeachingRecordSystem.SupportUi.Infrastructure.Filters; using TeachingRecordSystem.SupportUi.Infrastructure.Security; @@ -9,19 +9,48 @@ namespace TeachingRecordSystem.SupportUi.Pages.Alerts; [CheckAlertExistsFilterFactory(requiredPermission: Permissions.Alerts.Read), ServiceFilter(typeof(RequireClosedAlertFilter))] -public class AlertDetailModel(IAuthorizationService authorizationService) : PageModel +public class AlertDetailModel( + IAuthorizationService authorizationService, + TrsDbContext dbContext) : PageModel { public Alert? Alert { get; set; } + public string? ChangeReason { get; set; } + + public string? ChangeReasonDetail { get; set; } + public bool CanEdit { get; set; } public async Task OnGet() { - Alert = HttpContext.Features.GetRequiredFeature().Alert; + Alert = HttpContext.GetCurrentAlertFeature().Alert; + var personId = HttpContext.GetCurrentPersonFeature().PersonId; + var changeReasonInfo = await dbContext.Database + .SqlQuery( + $""" + SELECT + payload ->> 'ChangeReason' as change_reason, + payload ->> 'ChangeReasonDetail' as change_reason_detail + FROM + events + WHERE + person_id = {personId} + AND event_name = 'AlertUpdatedEvent' + AND (payload #>> Array['Alert', 'AlertId'])::uuid = {Alert.AlertId} + AND payload #>> Array['Alert', 'EndDate'] is not null + AND payload #>> Array['OldAlert', 'EndDate'] is null + ORDER BY + created DESC + """) + .FirstOrDefaultAsync(); + ChangeReason = changeReasonInfo?.ChangeReason; + ChangeReasonDetail = changeReasonInfo?.ChangeReasonDetail; CanEdit = (await authorizationService.AuthorizeForAlertTypeAsync( User, Alert.AlertTypeId, Permissions.Alerts.Write)) is { Succeeded: true }; } + + private record ChangeReasonInfo(string ChangeReason, string ChangeReasonDetail); } diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/ReopenAlert/Index.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/ReopenAlert/Index.cshtml index f8401acbc..364331acf 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/ReopenAlert/Index.cshtml +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Alerts/ReopenAlert/Index.cshtml @@ -5,7 +5,7 @@ } @section BeforeContent { - Back + Back }
diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Alerts.cshtml b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Alerts.cshtml index 512ddc495..7134507b5 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Alerts.cshtml +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/PersonDetail/Alerts.cshtml @@ -50,7 +50,7 @@ @if (canWrite) { - Change + Change } @@ -65,7 +65,7 @@ @if (canWrite) { - Change + Change } @@ -81,7 +81,13 @@ End date - @alert.EndDate?.ToString("d MMMM yyyy") + + @if (canWrite) + { + + Add + + }