Skip to content

Commit

Permalink
Ensure alert links are pointing at appropriate endpoints (#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
hortha authored Oct 30, 2024
1 parent 8a71697 commit 6c74266
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
<govuk-summary-list-row-key>Details</govuk-summary-list-row-key>
<govuk-summary-list-row-value use-empty-fallback>@Model.Alert.Details</govuk-summary-list-row-value>
</govuk-summary-list-row>
<govuk-summary-list-row>
<govuk-summary-list-row-key>Link</govuk-summary-list-row-key>
<govuk-summary-list-row-value use-empty-fallback>
@if (Model.Alert.ExternalLink is not null)
{
<a href="@Model.Alert.ExternalLink" rel="noopener noreferrer" class="govuk-link">@Model.Alert.ExternalLink</a>
}
</govuk-summary-list-row-value>
</govuk-summary-list-row>
<govuk-summary-list-row>
<govuk-summary-list-row-key>Start date</govuk-summary-list-row-key>
<govuk-summary-list-row-value use-empty-fallback>@Model.Alert.StartDate?.ToString("d MMMM yyyy")</govuk-summary-list-row-value>
Expand All @@ -30,4 +39,22 @@
</govuk-summary-list-row-actions>
}
</govuk-summary-list-row>
<govuk-summary-list-row>
<govuk-summary-list-row-key>Reason for closing alert</govuk-summary-list-row-key>
<govuk-summary-list-row-value use-empty-fallback>@Model.ChangeReason</govuk-summary-list-row-value>
</govuk-summary-list-row>
<govuk-summary-list-row>
<govuk-summary-list-row-key>Reason details</govuk-summary-list-row-key>
<govuk-summary-list-row-value>
@if (Model.ChangeReasonDetail is not null)
{
<multi-line-text text="@Model.ChangeReasonDetail" />
}
else
{
<span use-empty-fallback></span>
}
</govuk-summary-list-row-value>
</govuk-summary-list-row>

</govuk-summary-list>
Original file line number Diff line number Diff line change
@@ -1,27 +1,56 @@
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;

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<CurrentAlertFeature>().Alert;
Alert = HttpContext.GetCurrentAlertFeature().Alert;
var personId = HttpContext.GetCurrentPersonFeature().PersonId;
var changeReasonInfo = await dbContext.Database
.SqlQuery<ChangeReasonInfo>(
$"""
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}

@section BeforeContent {
<govuk-back-link href="@LinkGenerator.AlertDetail(Model.AlertId)">Back</govuk-back-link>
<govuk-back-link href="@(Model.FromCheckAnswers == true ? LinkGenerator.AlertReopenCheckAnswers(Model.AlertId, Model.JourneyInstance!.InstanceId) : LinkGenerator.AlertDetail(Model.AlertId))">Back</govuk-back-link>
}

<div class="govuk-grid-row">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
@if (canWrite)
{
<govuk-summary-list-row-actions>
<govuk-summary-list-row-action href="#" visually-hidden-text="details">Change</govuk-summary-list-row-action>
<govuk-summary-list-row-action href="@LinkGenerator.AlertEditDetails(alert.AlertId, journeyInstanceId: null)" visually-hidden-text="details">Change</govuk-summary-list-row-action>
</govuk-summary-list-row-actions>
}
</govuk-summary-list-row>
Expand All @@ -65,7 +65,7 @@
@if (canWrite)
{
<govuk-summary-list-row-actions>
<govuk-summary-list-row-action href="#" visually-hidden-text="link">Change</govuk-summary-list-row-action>
<govuk-summary-list-row-action href="@LinkGenerator.AlertEditLink(alert.AlertId, journeyInstanceId: null)" visually-hidden-text="link">Change</govuk-summary-list-row-action>
</govuk-summary-list-row-actions>
}
</govuk-summary-list-row>
Expand All @@ -81,7 +81,13 @@
</govuk-summary-list-row>
<govuk-summary-list-row>
<govuk-summary-list-row-key>End date</govuk-summary-list-row-key>
<govuk-summary-list-row-value use-empty-fallback>@alert.EndDate?.ToString("d MMMM yyyy")</govuk-summary-list-row-value>
<govuk-summary-list-row-value use-empty-fallback></govuk-summary-list-row-value>
@if (canWrite)
{
<govuk-summary-list-row-actions>
<govuk-summary-list-row-action href="@LinkGenerator.AlertClose(alert.AlertId, journeyInstanceId: null)" visually-hidden-text="end date">Add</govuk-summary-list-row-action>
</govuk-summary-list-row-actions>
}
</govuk-summary-list-row>
</govuk-summary-list>
</govuk-summary-card>
Expand Down

0 comments on commit 6c74266

Please sign in to comment.