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:
+46
-3
@@ -139,6 +139,47 @@ public class NotificationOutboxRepositoryIntegrationTests : IClassFixture<MsSqlM
|
||||
Assert.Equal("Wanted", row.Subject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Code review 2026-12-02 UI-7: the permitted-sites filter is applied in the query, so the
|
||||
/// page AND the total count cover only rows the scoped caller may see (pre-fix the count
|
||||
/// included every site and pages came back partly or wholly empty after client filtering).
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[SkippableFact]
|
||||
public async Task QueryAsync_SourceSiteIdsFilter_PagesAndCountsInScopeRowsOnly()
|
||||
{
|
||||
Skip.IfNot(_fixture.Available, _fixture.SkipReason);
|
||||
|
||||
var mine = "site-ui7-" + Guid.NewGuid().ToString("N")[..8];
|
||||
var other = "site-ui7-" + Guid.NewGuid().ToString("N")[..8];
|
||||
await using (var context = CreateContext())
|
||||
{
|
||||
var repo = new NotificationOutboxRepository(context);
|
||||
for (var i = 0; i < 3; i++)
|
||||
await repo.InsertIfNotExistsAsync(MakeNotification(Guid.NewGuid().ToString(), sourceSiteId: mine, minutes: i));
|
||||
for (var i = 0; i < 7; i++)
|
||||
await repo.InsertIfNotExistsAsync(MakeNotification(Guid.NewGuid().ToString(), sourceSiteId: other, minutes: 10 + i));
|
||||
}
|
||||
|
||||
await using var queryContext = CreateContext();
|
||||
var queryRepo = new NotificationOutboxRepository(queryContext);
|
||||
var (rows, totalCount) = await queryRepo.QueryAsync(
|
||||
new NotificationOutboxFilter(SourceSiteIds: new[] { mine }), pageNumber: 1, pageSize: 2);
|
||||
|
||||
Assert.Equal(3, totalCount);
|
||||
Assert.Equal(2, rows.Count);
|
||||
Assert.All(rows, r => Assert.Equal(mine, r.SourceSiteId));
|
||||
|
||||
var (page2, _) = await queryRepo.QueryAsync(
|
||||
new NotificationOutboxFilter(SourceSiteIds: new[] { mine }), pageNumber: 2, pageSize: 2);
|
||||
Assert.Equal(mine, Assert.Single(page2).SourceSiteId);
|
||||
|
||||
var (none, noneCount) = await queryRepo.QueryAsync(
|
||||
new NotificationOutboxFilter(SourceSiteIds: Array.Empty<string>()), pageNumber: 1, pageSize: 50);
|
||||
Assert.Empty(none);
|
||||
Assert.Equal(0, noneCount);
|
||||
}
|
||||
|
||||
// --- helpers ------------------------------------------------------------
|
||||
|
||||
private ScadaBridgeDbContext CreateContext()
|
||||
@@ -152,7 +193,9 @@ public class NotificationOutboxRepositoryIntegrationTests : IClassFixture<MsSqlM
|
||||
private static Notification MakeNotification(
|
||||
string id,
|
||||
NotificationStatus status = NotificationStatus.Pending,
|
||||
string subject = "Subject")
|
||||
string subject = "Subject",
|
||||
string sourceSiteId = "site-cd015",
|
||||
int minutes = 0)
|
||||
{
|
||||
return new Notification(
|
||||
id,
|
||||
@@ -160,10 +203,10 @@ public class NotificationOutboxRepositoryIntegrationTests : IClassFixture<MsSqlM
|
||||
"Ops List",
|
||||
subject,
|
||||
"Body",
|
||||
"site-cd015")
|
||||
sourceSiteId)
|
||||
{
|
||||
Status = status,
|
||||
CreatedAt = new DateTimeOffset(2026, 5, 20, 10, 0, 0, TimeSpan.Zero),
|
||||
CreatedAt = new DateTimeOffset(2026, 5, 20, 10, 0, 0, TimeSpan.Zero).AddMinutes(minutes),
|
||||
SiteEnqueuedAt = new DateTimeOffset(2026, 5, 20, 9, 59, 0, TimeSpan.Zero),
|
||||
};
|
||||
}
|
||||
|
||||
+40
@@ -489,6 +489,46 @@ public class SiteCallAuditRepositoryTests : IClassFixture<MsSqlMigrationFixture>
|
||||
Assert.All(rows, r => Assert.Equal(siteA, r.SourceSite));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Code review 2026-12-02 UI-7: a site-scoped caller's permitted set is applied in the
|
||||
/// query, so keyset paging runs over in-scope rows only. Mixed data where the OTHER site
|
||||
/// produces most of the traffic must still yield full in-scope pages and a cursor that
|
||||
/// reaches every in-scope row.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[SkippableFact]
|
||||
public async Task QueryAsync_SourceSitesFilter_PagesOverInScopeRowsOnly()
|
||||
{
|
||||
Skip.IfNot(_fixture.Available, _fixture.SkipReason);
|
||||
|
||||
var mine = NewSiteId();
|
||||
var other = NewSiteId();
|
||||
await using var context = CreateContext();
|
||||
var repo = new SiteCallAuditRepository(context);
|
||||
|
||||
// Newest-first order: 6 rows of the other site sit ON TOP of 5 of mine, interleaved.
|
||||
var t0 = new DateTime(2026, 6, 1, 10, 0, 0, DateTimeKind.Utc);
|
||||
for (var i = 0; i < 5; i++)
|
||||
await repo.UpsertAsync(NewRow(TrackedOperationId.New(), sourceSite: mine, createdAtUtc: t0.AddMinutes(i)));
|
||||
for (var i = 0; i < 6; i++)
|
||||
await repo.UpsertAsync(NewRow(TrackedOperationId.New(), sourceSite: other, createdAtUtc: t0.AddMinutes(10 + i)));
|
||||
|
||||
var scope = new SiteCallQueryFilter(SourceSites: new[] { mine });
|
||||
var page1 = await repo.QueryAsync(scope, new SiteCallPaging(PageSize: 3));
|
||||
Assert.Equal(3, page1.Count); // full page, not 0 (pre-fix: other site's rows)
|
||||
Assert.All(page1, r => Assert.Equal(mine, r.SourceSite));
|
||||
|
||||
var last = page1[^1];
|
||||
var page2 = await repo.QueryAsync(scope, new SiteCallPaging(
|
||||
PageSize: 3, AfterCreatedAtUtc: last.CreatedAtUtc, AfterId: last.TrackedOperationId));
|
||||
Assert.Equal(2, page2.Count);
|
||||
Assert.All(page2, r => Assert.Equal(mine, r.SourceSite));
|
||||
|
||||
// Empty permitted set matches nothing (fail closed), and composes with SourceSite.
|
||||
Assert.Empty(await repo.QueryAsync(new SiteCallQueryFilter(SourceSites: Array.Empty<string>()), new SiteCallPaging(PageSize: 50)));
|
||||
Assert.Empty(await repo.QueryAsync(new SiteCallQueryFilter(SourceSite: other, SourceSites: new[] { mine }), new SiteCallPaging(PageSize: 50)));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that filtering by tracked operation id returns exactly that row.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[SkippableFact]
|
||||
|
||||
Reference in New Issue
Block a user