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
@@ -286,6 +286,33 @@ public class SecuredWriteRepositoryTests : IClassFixture<MsSqlMigrationFixture>
Assert.Equal(0, await repo.CountAsync(status: "Executed", siteId: siteId));
}
/// <summary>
/// Code review 2026-12-02 UI-9: the history asks for the terminal statuses, applied in SQL
/// before paging and counting, so Pending rows neither take page slots nor inflate the
/// total that drives the pager.
/// </summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[SkippableFact]
public async Task QueryAndCount_StatusesFilter_PageAndCountOnlyThoseStatuses()
{
Skip.IfNot(_fixture.Available, _fixture.SkipReason);
var siteId = NewSiteId();
await using var context = CreateContext();
var repo = new SecuredWriteRepository(context);
for (var i = 0; i < 4; i++) await repo.AddAsync(NewRow(siteId, status: "Pending"));
await repo.AddAsync(NewRow(siteId, status: "Executed"));
await repo.AddAsync(NewRow(siteId, status: "Rejected"));
await repo.AddAsync(NewRow(siteId, status: "Expired"));
string[] terminal = ["Executed", "Failed", "Rejected", "Expired"];
var page = await repo.QueryAsync(null, siteId, skip: 0, take: 2, statuses: terminal);
Assert.Equal(2, page.Count);
Assert.All(page, r => Assert.Contains(r.Status, terminal));
Assert.Equal(3, await repo.CountAsync(null, siteId, statuses: terminal));
Assert.Equal(7, await repo.CountAsync(null, siteId));
}
/// <summary>Verifies that a query with permitted site ids returns only rows for those sites.</summary>
/// <returns>A task that represents the asynchronous operation.</returns>
[SkippableFact]