feat(notification-outbox): operator Retry/Discard emit audit rows with operator identity
Additive RequestedBy on Retry/DiscardNotificationRequest, plumbed from the Central UI. RetryAsync emits a NotifyDeliver Submitted row (records who un-parked); Discard stamps the operator on the Terminal row. Best-effort — audit failure never aborts the action.
This commit is contained in:
+5
-2
@@ -10,6 +10,7 @@
|
||||
@inject SiteScopeService SiteScope
|
||||
@inject IDialogService Dialog
|
||||
@inject ILogger<NotificationReport> Logger
|
||||
@inject AuthenticationStateProvider AuthStateProvider
|
||||
|
||||
<div class="container-fluid mt-3">
|
||||
<ToastNotification @ref="_toast" />
|
||||
@@ -481,8 +482,9 @@
|
||||
_actionInProgress = true;
|
||||
try
|
||||
{
|
||||
var requestedBy = await AuthStateProvider.GetCurrentUsernameAsync();
|
||||
var response = await CommunicationService.RetryNotificationAsync(
|
||||
new RetryNotificationRequest(Guid.NewGuid().ToString("N"), n.NotificationId));
|
||||
new RetryNotificationRequest(Guid.NewGuid().ToString("N"), n.NotificationId, requestedBy));
|
||||
if (response.Success)
|
||||
{
|
||||
_toast.ShowSuccess($"Notification {ShortId(n.NotificationId)} re-queued for delivery.");
|
||||
@@ -517,8 +519,9 @@
|
||||
_actionInProgress = true;
|
||||
try
|
||||
{
|
||||
var requestedBy = await AuthStateProvider.GetCurrentUsernameAsync();
|
||||
var response = await CommunicationService.DiscardNotificationAsync(
|
||||
new DiscardNotificationRequest(Guid.NewGuid().ToString("N"), n.NotificationId));
|
||||
new DiscardNotificationRequest(Guid.NewGuid().ToString("N"), n.NotificationId, requestedBy));
|
||||
if (response.Success)
|
||||
{
|
||||
_toast.ShowSuccess($"Notification {ShortId(n.NotificationId)} discarded.");
|
||||
|
||||
+17
-2
@@ -51,9 +51,17 @@ public record NotificationOutboxQueryResponse(
|
||||
/// <summary>
|
||||
/// Outbox UI -> Central: request to immediately retry delivery of a notification.
|
||||
/// </summary>
|
||||
/// <param name="CorrelationId">Request/response correlation id.</param>
|
||||
/// <param name="NotificationId">The notification to re-queue.</param>
|
||||
/// <param name="RequestedBy">
|
||||
/// The authenticated operator who initiated the retry, stamped as the <c>Actor</c> on
|
||||
/// the emitted audit row so an un-park is attributable (Task 13). Additive; null where
|
||||
/// no identity is available (legacy senders compile unchanged).
|
||||
/// </param>
|
||||
public record RetryNotificationRequest(
|
||||
string CorrelationId,
|
||||
string NotificationId);
|
||||
string NotificationId,
|
||||
string? RequestedBy = null);
|
||||
|
||||
/// <summary>
|
||||
/// Central -> Outbox UI: result of a <see cref="RetryNotificationRequest"/>.
|
||||
@@ -66,9 +74,16 @@ public record RetryNotificationResponse(
|
||||
/// <summary>
|
||||
/// Outbox UI -> Central: request to discard (cancel) a pending or stuck notification.
|
||||
/// </summary>
|
||||
/// <param name="CorrelationId">Request/response correlation id.</param>
|
||||
/// <param name="NotificationId">The notification to discard.</param>
|
||||
/// <param name="RequestedBy">
|
||||
/// The authenticated operator who initiated the discard, stamped as the <c>Actor</c> on
|
||||
/// the emitted terminal audit row (Task 13). Additive; null where no identity is available.
|
||||
/// </param>
|
||||
public record DiscardNotificationRequest(
|
||||
string CorrelationId,
|
||||
string NotificationId);
|
||||
string NotificationId,
|
||||
string? RequestedBy = null);
|
||||
|
||||
/// <summary>
|
||||
/// Central -> Outbox UI: result of a <see cref="DiscardNotificationRequest"/>.
|
||||
|
||||
@@ -587,12 +587,14 @@ public class NotificationOutboxActor : ReceiveActor, IWithTimers
|
||||
private async Task EmitTerminalAuditAsync(
|
||||
Notification notification,
|
||||
DateTimeOffset now,
|
||||
string? errorMessage)
|
||||
string? errorMessage,
|
||||
string? actorOverride = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var terminalStatus = MapNotificationStatusToAuditStatus(notification.Status);
|
||||
var evt = BuildNotifyDeliverEvent(notification, now, terminalStatus, errorMessage);
|
||||
var evt = BuildNotifyDeliverEvent(
|
||||
notification, now, terminalStatus, errorMessage, actorOverride: actorOverride);
|
||||
await _auditWriter.WriteAsync(evt);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -677,7 +679,8 @@ public class NotificationOutboxActor : ReceiveActor, IWithTimers
|
||||
DateTimeOffset now,
|
||||
AuditStatus status,
|
||||
string? errorMessage,
|
||||
int? durationMs = null)
|
||||
int? durationMs = null,
|
||||
string? actorOverride = null)
|
||||
{
|
||||
Guid? correlationId = Guid.TryParse(notification.NotificationId, out var parsed)
|
||||
? parsed
|
||||
@@ -688,11 +691,12 @@ public class NotificationOutboxActor : ReceiveActor, IWithTimers
|
||||
kind: AuditKind.NotifyDeliver,
|
||||
status: status,
|
||||
occurredAtUtc: now.UtcDateTime,
|
||||
// Central dispatch — a system identity per the Actor-column spec;
|
||||
// there is no per-call authenticated user here. The originating
|
||||
// script is still captured on SourceScript (and on the upstream
|
||||
// NotifySend row).
|
||||
actor: SystemActor,
|
||||
// Central dispatch is a system identity per the Actor-column spec —
|
||||
// there is no per-call authenticated user for automatic delivery. An
|
||||
// operator-initiated transition (Retry/Discard) passes actorOverride
|
||||
// so the row is attributable to the person who un-parked/cancelled it
|
||||
// (Task 13). The originating script is still captured on SourceScript.
|
||||
actor: actorOverride ?? SystemActor,
|
||||
target: notification.ListName,
|
||||
correlationId: correlationId,
|
||||
// ExecutionId: the originating script execution's id,
|
||||
@@ -973,9 +977,41 @@ public class NotificationOutboxActor : ReceiveActor, IWithTimers
|
||||
notification.LastError = null;
|
||||
await repository.UpdateAsync(notification);
|
||||
|
||||
// Operator re-queued a parked notification. Emit a Submitted NotifyDeliver
|
||||
// row attributing the un-park to the operator — otherwise the lifecycle
|
||||
// reads Parked → Attempted → Delivered with no record of who un-parked it
|
||||
// (Task 13). Best-effort: audit failure never aborts the retry.
|
||||
await EmitRetrySubmittedAuditAsync(notification, DateTimeOffset.UtcNow, request.RequestedBy);
|
||||
|
||||
return new RetryNotificationResponse(request.CorrelationId, Success: true, ErrorMessage: null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Emits a single <see cref="AuditKind.NotifyDeliver"/> row with
|
||||
/// <see cref="AuditStatus.Submitted"/> recording that <paramref name="actorOverride"/>
|
||||
/// re-queued a parked notification. Best-effort with the same
|
||||
/// audit-never-affects-the-action shape as <see cref="EmitTerminalAuditAsync"/>.
|
||||
/// </summary>
|
||||
private async Task EmitRetrySubmittedAuditAsync(
|
||||
Notification notification,
|
||||
DateTimeOffset now,
|
||||
string? actorOverride)
|
||||
{
|
||||
try
|
||||
{
|
||||
var evt = BuildNotifyDeliverEvent(
|
||||
notification, now, AuditStatus.Submitted, errorMessage: null, actorOverride: actorOverride);
|
||||
await _auditWriter.WriteAsync(evt);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
ex,
|
||||
"Failed to emit Submitted (operator retry) audit row for notification {NotificationId}.",
|
||||
notification.NotificationId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles a manual discard request. Only a <c>Parked</c> notification can be discarded;
|
||||
/// it is moved to the terminal <c>Discarded</c> status.
|
||||
@@ -1018,7 +1054,10 @@ public class NotificationOutboxActor : ReceiveActor, IWithTimers
|
||||
// Emit a Discarded NotifyDeliver row to match the dispatcher's
|
||||
// Delivered/Parked emissions; the row carries no error message because
|
||||
// the discard is an operator-driven cancellation, not a delivery error.
|
||||
await EmitTerminalAuditAsync(notification, DateTimeOffset.UtcNow, errorMessage: null);
|
||||
// The operator identity is stamped as Actor so the cancellation is
|
||||
// attributable (Task 13).
|
||||
await EmitTerminalAuditAsync(
|
||||
notification, DateTimeOffset.UtcNow, errorMessage: null, actorOverride: request.RequestedBy);
|
||||
|
||||
return new DiscardNotificationResponse(request.CorrelationId, Success: true, ErrorMessage: null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user