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
@@ -348,6 +348,15 @@ VALUES
query = query.Where(n => n.SourceSiteId == filter.SourceSiteId);
}
// Code review 2026-12-02 UI-7: a site-scoped caller's permitted set, applied in the
// query so the page AND the total count cover only rows the caller may see. An
// empty set matches nothing (fail closed).
if (filter.SourceSiteIds is { } sourceSiteIds)
{
var permitted = sourceSiteIds.ToList();
query = query.Where(n => permitted.Contains(n.SourceSiteId));
}
// SourceNode is exact-match like SourceSiteId. Rows with NULL
// SourceNode (legacy / unconfigured) are excluded when the filter is set.
if (!string.IsNullOrEmpty(filter.SourceNode))
@@ -58,6 +58,7 @@ public class SecuredWriteRepository : ISecuredWriteRepository
int skip,
int take,
IReadOnlyCollection<string>? permittedSiteIds = null,
IReadOnlyCollection<string>? statuses = null,
CancellationToken ct = default)
{
IQueryable<PendingSecuredWrite> query = _context.Set<PendingSecuredWrite>()
@@ -78,6 +79,11 @@ public class SecuredWriteRepository : ISecuredWriteRepository
query = query.Where(p => permittedSiteIds.Contains(p.SiteId));
}
if (statuses is not null)
{
query = query.Where(p => statuses.Contains(p.Status));
}
return await query
.OrderByDescending(p => p.SubmittedAtUtc)
.ThenByDescending(p => p.Id)
@@ -166,6 +172,7 @@ WHERE Id = {id}
string? status,
string? siteId,
IReadOnlyCollection<string>? permittedSiteIds = null,
IReadOnlyCollection<string>? statuses = null,
CancellationToken ct = default)
{
IQueryable<PendingSecuredWrite> query = _context.Set<PendingSecuredWrite>()
@@ -186,6 +193,11 @@ WHERE Id = {id}
query = query.Where(p => permittedSiteIds.Contains(p.SiteId));
}
if (statuses is not null)
{
query = query.Where(p => statuses.Contains(p.Status));
}
return await query.CountAsync(ct);
}
@@ -425,6 +425,9 @@ SELECT TOP (@PageSize)
FROM dbo.SiteCalls
WHERE (@Channel IS NULL OR Channel = @Channel)
AND (@SourceSite IS NULL OR SourceSite = @SourceSite)
-- Code review 2026-12-02 UI-7: a site-scoped caller's permitted set (JSON array), applied
-- here so keyset paging runs over rows the caller may see; '[]' matches nothing.
AND (@SourceSites IS NULL OR SourceSite IN (SELECT CAST([value] AS varchar(8000)) FROM OPENJSON(@SourceSites)))
AND (@SourceNode IS NULL OR SourceNode = @SourceNode)
AND (@Status IS NULL OR Status = @Status)
AND (@Target IS NULL OR Target = @Target)
@@ -449,6 +452,8 @@ OPTION (RECOMPILE);";
Param("@PageSize", SqlDbType.Int, paging.PageSize),
Param("@Channel", SqlDbType.VarChar, filter.Channel),
Param("@SourceSite", SqlDbType.VarChar, filter.SourceSite),
Param("@SourceSites", SqlDbType.NVarChar,
filter.SourceSites is null ? null : System.Text.Json.JsonSerializer.Serialize(filter.SourceSites)),
Param("@SourceNode", SqlDbType.VarChar, filter.SourceNode),
Param("@Status", SqlDbType.VarChar, filter.Status),
Param("@Target", SqlDbType.VarChar, filter.Target),