diff --git a/docs/requirements/Component-CentralUI.md b/docs/requirements/Component-CentralUI.md index 169100b0..94db8663 100644 --- a/docs/requirements/Component-CentralUI.md +++ b/docs/requirements/Component-CentralUI.md @@ -275,7 +275,7 @@ Per-leaf alarm rendering (leaf nodes are individual conditions for native alarms - Monitor and manage centrally-delivered notifications. The Notification Outbox dispatches every notification store-and-forwarded from sites and logs each one to the central `Notifications` table. - **KPI tiles** at the top of the page: queue depth (`Pending` + `Retrying`), stuck count, parked count, delivered in the last interval, and oldest pending age. The KPIs are central-computed on demand from the `Notifications` table. - A **queryable notification list** filterable by status, type, source site, notification list, and time range, with a **stuck-only toggle** and keyword search on subject. Each row shows the notification's status, retry count, last error, and key timestamps. -- **Retry** and **Discard** actions are available on parked notifications: Retry returns the notification to `Pending` and resets `RetryCount` / `NextAttemptAt`; Discard moves it to `Discarded`. The row is retained either way so the table stays a complete audit record. +- **Retry** and **Discard** actions are available on parked notifications: Retry returns the notification to `Pending` and resets `RetryCount` / `NextAttemptAt`; Discard moves it to `Discarded`. The row is retained either way so the table stays a complete audit record. The action re-checks site scope at click time: a system-wide user may act on any row, including one whose source site no longer resolves (deleted or renamed — such rows stay listed); a site-scoped user may act only on rows of a permitted site, and not on an unresolvable one (code review 2026-12-02 UI-11). - Each row exposes a **"View audit history"** action that opens the Audit Log page pre-filtered to `CorrelationId = NotificationId`, surfacing every operational audit event recorded for that notification. - **Stuck rows are visually badged** — a notification is stuck if it is `Pending` or `Retrying` and older than the configurable stuck-age threshold. Stuck detection is display-only; there is no automated escalation or alerting. - All queries are served from the central `Notifications` table — no remote per-site queries are needed, unlike the Parked Message Management page. @@ -292,7 +292,7 @@ Per-leaf alarm rendering (leaf nodes are individual conditions for native alarms ### Site Calls (Deployment Role) - Monitor cached calls store-and-forwarded from sites — `ExternalSystem.CachedCall()` and `Database.CachedWrite()` operations. Scoped to the `ExternalCall` and `DatabaseWrite` kinds only; notifications keep their separate Notification Outbox page and are not merged here. - A **queryable cached-call list** filterable by site, kind, status, and time range. Each row shows the call's timestamp, site, kind, target summary, status badge, retry count, and last error. -- **Retry** and **Discard** actions are available on `Parked` rows only — `Failed` rows are not actionable, since a permanent failure would simply fail again and its error was already returned synchronously to the calling script. The actions issue central→site commands to the owning site; if the site is offline the UI surfaces a "site unreachable" message. +- **Retry** and **Discard** actions are available on `Parked` rows only — `Failed` rows are not actionable, since a permanent failure would simply fail again and its error was already returned synchronously to the calling script. The actions issue central→site commands to the owning site; if the site is offline the UI surfaces a "site unreachable" message. Site scope is re-checked at click time exactly as on the Notification Outbox page: a system-wide user may act on a row whose source site no longer resolves, a site-scoped user may not (UI-11). - Each row exposes a **"View audit history"** action that opens the Audit Log page pre-filtered to `CorrelationId = TrackedOperationId`, showing every operational audit event recorded for that cached call. - Data is served from the central Site Call Audit component's `SiteCalls` table. The page is **read-mostly** — an eventually-consistent mirror of site state; the site remains the source of truth. diff --git a/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Notifications/NotificationReport.razor b/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Notifications/NotificationReport.razor index 74966258..8d15a907 100644 --- a/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Notifications/NotificationReport.razor +++ b/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/Notifications/NotificationReport.razor @@ -832,26 +832,18 @@ } /// - /// Server-side re-check for the Retry/Discard relay actions. Returns true for a - /// system-wide user, or when the row's source site resolves to a Site.Id in the - /// caller's permitted set. An unresolvable site identifier defaults to allowed - /// (legacy behaviour); the relay's own site-scope re-check is then the - /// final gate. + /// Server-side re-check for the Retry/Discard relay actions (fresh authority). + /// A system-wide user may act on any row — including one whose source site no + /// longer resolves (deleted or renamed), which the grid deliberately keeps showing + /// (code review 2026-12-02 UI-11: such rows used to be refused for everyone, even an + /// Administrator, so they could not be cleared). A site-scoped user may act only + /// when the row's site resolves to a Site.Id in their permitted set; an + /// unresolvable site is denied for them. /// - private bool IsRowSiteAllowedSync(string sourceSiteId) - { - if (_siteScopeSystemWide) - return true; - - var resolved = _allSites.FirstOrDefault(s => s.SiteIdentifier == sourceSiteId); - if (resolved is null) - return true; - - return _permittedSiteIds.Contains(resolved.Id); - } - private async Task IsRowSiteAllowedAsync(string sourceSiteId) { + if (await SiteScope.IsSystemWideAsync()) + return true; var resolved = (await SiteRepository.GetAllSitesAsync()).FirstOrDefault(s => s.SiteIdentifier == sourceSiteId); return resolved is not null && await SiteScope.IsSiteAllowedAsync(resolved.Id); } diff --git a/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/SiteCalls/SiteCallsReport.razor.cs b/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/SiteCalls/SiteCallsReport.razor.cs index e49323a9..87c62220 100644 --- a/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/SiteCalls/SiteCallsReport.razor.cs +++ b/src/ZB.MOM.WW.ScadaBridge.CentralUI/Components/Pages/SiteCalls/SiteCallsReport.razor.cs @@ -588,11 +588,17 @@ public partial class SiteCallsReport } /// - /// Server-side re-check for the Retry/Discard relay. True for a system-wide - /// user, or when the row's source site maps to a Site.Id in the permitted set. + /// Server-side re-check for the Retry/Discard relay (fresh authority). A system-wide + /// user may act on any row, including one whose source site no longer resolves + /// (deleted or renamed) — code review 2026-12-02 UI-11: such rows used to be refused + /// for everyone, even an Administrator. A site-scoped user may act only when the + /// row's site maps to a Site.Id in their permitted set; an unresolvable site is + /// denied for them. /// private async Task IsRowSiteAllowedAsync(string sourceSite) { + if (await SiteScope.IsSystemWideAsync()) + return true; var resolved = (await SiteRepository.GetAllSitesAsync()).FirstOrDefault(s => s.SiteIdentifier == sourceSite); return resolved is not null && await SiteScope.IsSiteAllowedAsync(resolved.Id); } diff --git a/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Pages/NotificationReportPageTests.cs b/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Pages/NotificationReportPageTests.cs index c7f5ca0e..41aa2243 100644 --- a/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Pages/NotificationReportPageTests.cs +++ b/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Pages/NotificationReportPageTests.cs @@ -179,6 +179,56 @@ public class NotificationReportPageTests : BunitContext }); } + /// + /// Code review 2026-12-02 UI-11: a parked row whose source site no longer resolves (site + /// deleted or renamed) stays visible; a system-wide user can Retry it, while a site-scoped + /// user is still refused (there is no Site.Id to authorize against). + /// + /// Whether the caller carries a SiteId claim (site-scoped Deployer). + [Theory] + [InlineData(false)] + [InlineData(true)] + public void Retry_OnRowFromADeletedSite_AllowedSystemWide_DeniedScoped(bool siteScoped) + { + _queryReply = _queryReply with + { + Notifications = new List + { + new("notif-cccccccc-3333", "Email", "Ops On-Call", "Orphaned alert", + "Parked", RetryCount: 5, LastError: "SMTP timeout", SourceSiteId: "deleted-site", + SourceInstanceId: "Pump-009", CreatedAt: DateTimeOffset.UtcNow.AddMinutes(-30), + DeliveredAt: null, IsStuck: false), + }, + TotalCount = 1, + }; + if (siteScoped) + { + var claims = new[] + { + new Claim(JwtTokenService.UsernameClaimType, "tester"), + new Claim(JwtTokenService.RoleClaimType, "Deployer"), + new Claim(JwtTokenService.SiteIdClaimType, "1"), + }; + Services.AddSingleton( + new TestAuthStateProvider(new ClaimsPrincipal(new ClaimsIdentity(claims, "TestAuth")))); + } + + var cut = Render(); + cut.WaitForState(() => cut.Markup.Contains("Orphaned alert")); + cut.FindAll("tbody tr").First(r => r.TextContent.Contains("Orphaned alert")) + .QuerySelectorAll("button").First(b => b.TextContent.Contains("Retry")).Click(); + + if (siteScoped) + { + cut.WaitForAssertion(() => Assert.Contains("not permitted to act on notifications", cut.Markup)); + Assert.Empty(_retryRequests); + } + else + { + cut.WaitForAssertion(() => Assert.Equal("notif-cccccccc-3333", Assert.Single(_retryRequests).NotificationId)); + } + } + /// Verifies that a query failure shows an error message. [Fact] public void QueryFailure_ShowsErrorMessage() diff --git a/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Pages/SiteCallsReportPageTests.cs b/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Pages/SiteCallsReportPageTests.cs index f90b1266..5c9c0232 100644 --- a/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Pages/SiteCallsReportPageTests.cs +++ b/tests/ZB.MOM.WW.ScadaBridge.CentralUI.Tests/Pages/SiteCallsReportPageTests.cs @@ -221,6 +221,56 @@ public class SiteCallsReportPageTests : BunitContext }); } + /// + /// Code review 2026-12-02 UI-11: a parked cached call whose source site no longer resolves + /// (site deleted or renamed) stays visible; a system-wide user can Retry it, while a + /// site-scoped user is still refused. + /// + /// Whether the caller carries a SiteId claim (site-scoped Deployer). + [Theory] + [InlineData(false)] + [InlineData(true)] + public void Retry_OnRowFromADeletedSite_AllowedSystemWide_DeniedScoped(bool siteScoped) + { + var orphanId = Guid.Parse("33333333-3333-3333-3333-333333333333"); + _queryReply = _queryReply with + { + SiteCalls = new List + { + new(orphanId, "deleted-site", "ApiOutbound", "ERP.Orphan", "Parked", + RetryCount: 5, LastError: "HTTP 503", HttpStatus: 503, + CreatedAtUtc: DateTime.UtcNow.AddMinutes(-30), UpdatedAtUtc: DateTime.UtcNow.AddMinutes(-5), + TerminalAtUtc: null, IsStuck: false), + }, + }; + if (siteScoped) + { + var claims = new[] + { + new Claim(JwtTokenService.UsernameClaimType, "tester"), + new Claim(JwtTokenService.RoleClaimType, "Deployer"), + new Claim(JwtTokenService.SiteIdClaimType, "1"), + }; + Services.AddSingleton( + new TestAuthStateProvider(new ClaimsPrincipal(new ClaimsIdentity(claims, "TestAuth")))); + } + + var cut = Render(); + cut.WaitForState(() => cut.Markup.Contains("ERP.Orphan")); + cut.FindAll("tbody tr").First(r => r.TextContent.Contains("ERP.Orphan")) + .QuerySelectorAll("button").First(b => b.TextContent.Contains("Retry")).Click(); + + if (siteScoped) + { + cut.WaitForAssertion(() => Assert.Contains("not permitted to act on cached calls", cut.Markup)); + Assert.Empty(_retryRequests); + } + else + { + cut.WaitForAssertion(() => Assert.Equal(orphanId, Assert.Single(_retryRequests).TrackedOperationId)); + } + } + /// Verifies that clicking Discard on a parked row relays the discard to the owning site. [Fact] public void ClickDiscard_OnParkedRow_RelaysDiscardToOwningSite()