fix(ui): apply site scope and the history status filter in the server query, before paging (UI-7, UI-9, UI-10, WP1 task 1.7)

UI-7: Site Calls and the Notification report sent an unscoped query and
dropped other sites' rows client-side after paging - Site Calls pages
went short (Next disabled, own rows hidden), Notifications showed other
sites' counts and empty pages. New additive SourceSitesFilter on
SiteCallQueryRequest / NotificationOutboxQueryRequest (+ SourceSites /
SourceSiteIds on the repository filters; OPENJSON IN-list in the
SiteCalls keyset SQL, Contains in EF) carries the permitted identifiers;
an empty set matches nothing. Next is gated on the server page size.

UI-9: Secured Writes history paged over every status and filtered
terminal rows client-side. Additive ListSecuredWritesCommand.Statuses
reaches the repository query and count.

UI-10: Notification KPIs per-site table is narrowed to the caller's
sites (SiteScopeService.Resolve on the principal).

Tests: MSSQL mixed-site keyset/offset paging + count for both repos and
the secured-write status set; handler forwards Statuses; UI pages send
the permitted set (scoped) / none (system-wide); history requests the
terminal statuses; KPI per-site rows narrowed.
This commit is contained in:
Joseph Doherty
2026-12-03 10:21:01 -05:00
parent 2162fad8e9
commit 5a052c6327
29 changed files with 415 additions and 44 deletions
@@ -51,6 +51,10 @@ public interface ISecuredWriteRepository
/// to <paramref name="siteId"/>. Used by the ManagementActor to constrain an unfiltered
/// list to a site-scoped caller's permitted sites at the query level (arch-review R2 N3),
/// so paging and totals stay correct.</param>
/// <param name="statuses">When non-null, only rows whose <c>Status</c> is in the set match
/// (code review 2026-12-02 UI-9: the Secured Writes history asks for the terminal statuses
/// so paging and the total count run over them in SQL). Applied IN ADDITION to
/// <paramref name="status"/>; an empty set matches nothing.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>A task that resolves to a page of matching rows, newest submission first.</returns>
Task<IReadOnlyList<PendingSecuredWrite>> QueryAsync(
@@ -59,6 +63,7 @@ public interface ISecuredWriteRepository
int skip,
int take,
IReadOnlyCollection<string>? permittedSiteIds = null,
IReadOnlyCollection<string>? statuses = null,
CancellationToken ct = default);
/// <summary>
@@ -146,12 +151,17 @@ public interface ISecuredWriteRepository
/// to <paramref name="siteId"/>. Used by the ManagementActor to constrain an unfiltered
/// list to a site-scoped caller's permitted sites at the query level (arch-review R2 N3),
/// so paging and totals stay correct.</param>
/// <param name="statuses">When non-null, only rows whose <c>Status</c> is in the set match
/// (code review 2026-12-02 UI-9: the Secured Writes history asks for the terminal statuses
/// so paging and the total count run over them in SQL). Applied IN ADDITION to
/// <paramref name="status"/>; an empty set matches nothing.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>A task that resolves to the count of matching rows.</returns>
Task<int> CountAsync(
string? status,
string? siteId,
IReadOnlyCollection<string>? permittedSiteIds = null,
IReadOnlyCollection<string>? statuses = null,
CancellationToken ct = default);
/// <summary>
@@ -27,6 +27,12 @@ namespace ZB.MOM.WW.ScadaBridge.Commons.Messages.Audit;
/// Flow Debugger / Audit Log); <c>null</c> = no filter. Additive, trailing
/// optional so existing positional callers are unaffected.
/// </param>
/// <param name="SourceSitesFilter">
/// Restrict to rows from ANY of these source sites (site identifiers) — the caller's
/// permitted set for a site-scoped user, so the scope is applied in the query BEFORE paging
/// (code review 2026-12-02 UI-7). <c>null</c> = no constraint; an EMPTY list matches nothing
/// (fail closed). Composes (AND) with <see cref="SourceSiteFilter"/>. Additive.
/// </param>
public sealed record SiteCallQueryRequest(
string CorrelationId,
string? StatusFilter,
@@ -40,7 +46,8 @@ public sealed record SiteCallQueryRequest(
Guid? AfterId,
int PageSize,
string? SourceNodeFilter = null,
Guid? TrackedOperationIdFilter = null);
Guid? TrackedOperationIdFilter = null,
IReadOnlyList<string>? SourceSitesFilter = null);
/// <summary>
/// A single <c>SiteCalls</c> row summarised for the Site Calls UI grid. Carries
@@ -60,7 +60,14 @@ public record RejectSecuredWriteCommand(long Id, string? Comment);
/// <param name="SiteId">Site id filter; <c>null</c> matches every site.</param>
/// <param name="Skip">Number of rows to skip (offset paging); clamped to &gt;= 0 server-side.</param>
/// <param name="Take">Maximum rows to return; clamped to 1..500 server-side. Default 200.</param>
public record ListSecuredWritesCommand(string? Status, string? SiteId, int Skip = 0, int Take = 200);
/// <param name="Statuses">
/// Additive (code review 2026-12-02 UI-9): when non-null, only rows whose status is in the set
/// match — the Central UI history asks for the terminal statuses so paging and the total
/// count run over them in SQL instead of filtering a mixed page client-side. Composes (AND)
/// with <paramref name="Status"/>. <c>null</c> = no constraint.
/// </param>
public record ListSecuredWritesCommand(string? Status, string? SiteId, int Skip = 0, int Take = 200,
IReadOnlyList<string>? Statuses = null);
/// <summary>
/// Result projection of a single pending secured write row, mirroring the
@@ -11,6 +11,12 @@ namespace ZB.MOM.WW.ScadaBridge.Commons.Messages.Notification;
/// Flow Debugger / Audit Log. Additive; <c>null</c> means "no filter" (legacy senders
/// compile unchanged).
/// </param>
/// <param name="SourceSitesFilter">
/// Restrict to rows from ANY of these source sites — the caller's permitted set for a
/// site-scoped user, so the scope applies in the query before paging AND counting (code
/// review 2026-12-02 UI-7). <c>null</c> = no constraint; an EMPTY list matches nothing.
/// Composes (AND) with <see cref="SourceSiteFilter"/>. Additive.
/// </param>
public record NotificationOutboxQueryRequest(
string CorrelationId,
string? StatusFilter,
@@ -24,7 +30,8 @@ public record NotificationOutboxQueryRequest(
int PageNumber,
int PageSize,
string? SourceNodeFilter = null,
string? NotificationIdFilter = null);
string? NotificationIdFilter = null,
IReadOnlyList<string>? SourceSitesFilter = null);
/// <summary>
/// A single notification row summarised for outbox UI display.
@@ -37,6 +37,10 @@ namespace ZB.MOM.WW.ScadaBridge.Commons.Types.Audit;
/// <c>null</c> means "do not constrain". AND-combined with every other field,
/// so a mismatching <see cref="SourceSite"/> (etc.) still yields no rows.
/// </param>
/// <param name="SourceSites">
/// Restrict to rows from ANY of these source sites (the site-scoped caller's permitted set,
/// code review 2026-12-02 UI-7). <c>null</c> = no constraint; an EMPTY list matches nothing.
/// </param>
public sealed record SiteCallQueryFilter(
string? Channel = null,
string? SourceSite = null,
@@ -46,4 +50,5 @@ public sealed record SiteCallQueryFilter(
DateTime? ToUtc = null,
DateTime? StuckCutoffUtc = null,
string? SourceNode = null,
Guid? TrackedOperationId = null);
Guid? TrackedOperationId = null,
IReadOnlyList<string>? SourceSites = null);
@@ -27,6 +27,10 @@ namespace ZB.MOM.WW.ScadaBridge.Commons.Types.Notifications;
/// Exact match on a single <c>NotificationId</c> — the <c>?correlationId=</c> deep link
/// from the Flow Debugger / Audit Log. <c>null</c> means "do not constrain".
/// </param>
/// <param name="SourceSiteIds">
/// Restrict to notifications from ANY of these sites (the site-scoped caller's permitted set,
/// code review 2026-12-02 UI-7). <c>null</c> = no constraint; an EMPTY list matches nothing.
/// </param>
public record NotificationOutboxFilter(
NotificationStatus? Status = null,
NotificationType? Type = null,
@@ -38,4 +42,5 @@ public record NotificationOutboxFilter(
DateTimeOffset? From = null,
DateTimeOffset? To = null,
string? SourceNode = null,
string? NotificationId = null);
string? NotificationId = null,
IReadOnlyList<string>? SourceSiteIds = null);