fix(audit): scope audit reads by site identifier, not numeric site id (MGT-2, UI-5, WP1 task 1.6)
PermittedSiteIds / SiteId claims are numeric Site.Id values while AuditLog.SourceSiteId holds the site identifier. /api/audit/query and /export compared the two (a scoped query was always empty, an explicit --site of one's own site was a 403), /api/audit/tree and Flow Debugger Replay dropped every site-side node, and the Central UI Audit Log grid applied no scope at all. New Commons AuditSiteScope: translate permitted ids to identifiers (Administrator / no claims = unscoped; unresolvable = fail closed) and apply them to a filter (never an empty SourceSiteIds, which the repository reads as unfiltered). Used by AuditEndpoints (query, export, tree), FlowDebugRunner.ReplayAsync, and AuditLogQueryService (grid QueryAsync - pushed into the query before paging - and the tree). ApplySiteScope gains the Administrator exemption. Tests: scoped query filters by identifier, own-site explicit filter allowed and foreign one 403, admin with claims unscoped, tree/replay get identifiers, UI grid scoped/out-of-scope/unscoped, tree per-call scope.
This commit is contained in:
@@ -336,6 +336,7 @@ Per-leaf alarm rendering (leaf nodes are individual conditions for native alarms
|
||||
- **"Copy as cURL"** action on `ApiOutbound` and `ApiInbound` rows.
|
||||
- **"Show all events for this operation"** link — re-applies the current view filtered by the row's `CorrelationId`.
|
||||
- **Export** button on the page header streams a server-side CSV of the current filter (default cap 100k rows; larger exports go through the CLI). Requires the `AuditExport` permission.
|
||||
- **Site scope (code review 2026-12-02 UI-5).** The grid, every drill-in that reuses `AuditLogQueryService.QueryAsync`, and the Execution Tree apply the caller's site scope exactly as `/api/audit/query` and `/api/audit/tree` do: the numeric `SiteId` claims are translated to site identifiers (`AuditSiteScope`, the value `AuditLog.SourceSiteId` holds) and pushed into the query before paging; an Administrator, or a user with no `SiteId` claims, is unscoped; an explicit site filter outside the caller's sites returns no rows. Before this the grid showed a scoped user every site's rows and the tree compared numeric ids to identifiers, dropping the user's own site-side nodes.
|
||||
|
||||
### Configuration Audit Log Viewer (Admin Role)
|
||||
- Pre-existing viewer for the `IAuditService` configuration-change log (template / instance / site / etc. before-after edits). Lives under the same **Audit** nav group as the operational Audit Log above.
|
||||
|
||||
@@ -80,7 +80,7 @@ In addition to `/management`, the Management Service exposes a dedicated REST su
|
||||
- `GET /api/audit/query` — keyset-paged JSON query over the central `AuditLog` table. Authenticated via HTTP Basic Auth (shared with `/management`); gated on the `OperationalAudit` permission (Admin / Audit / AuditReadOnly roles).
|
||||
- `GET /api/audit/export` — server-side streaming bulk export (CSV or JSONL) of the filtered rows. Gated on the `AuditExport` permission (Admin / Audit).
|
||||
|
||||
Both endpoints honour any site-scope rules attached to the caller's audit role by intersecting the caller-supplied `sourceSiteId` filter with the user's `PermittedSiteIds` (out-of-scope requests yield HTTP 403). Permission denial returns HTTP 403 with the same envelope shape used by `/management`.
|
||||
Both endpoints honour any site-scope rules attached to the caller's audit role by intersecting the caller-supplied `sourceSiteId` filter with the user's permitted sites (out-of-scope requests yield HTTP 403). `PermittedSiteIds` are numeric `Site.Id` values while `AuditLog.SourceSiteId` holds the site **identifier**, so the permitted ids are translated to identifiers first (shared `Commons.Types.Audit.AuditSiteScope`, also used by `/api/audit/tree`, Flow Debugger Replay and the Central UI Audit Log grid/tree); an Administrator is unscoped, as on every other scope check; and a scoped caller none of whose sites resolve is refused rather than handed an empty — i.e. unfiltered — site list. Before code review 2026-12-02 MGT-2 the raw numeric ids were compared against identifiers, so a scoped `audit query` always came back empty, `--site <own site>` was a 403, and `audit tree` dropped every site-side node. Permission denial returns HTTP 403 with the same envelope shape used by `/management`.
|
||||
|
||||
**Filter parsing is strict on the enum dimensions** (`channel`, `kind`, `status`; register row 99). Values are matched **case-insensitively** against the enum member names, and an unrecognised value returns **HTTP 400** `{ error, code: "BAD_REQUEST" }` naming the full valid set — it is not silently dropped. Silently dropping a filter would leave that dimension unconstrained and hand the caller a plausible, complete-looking page that does not answer the question they asked (the same failure row 88 fixed for `deploy status`). **Ordinals are rejected**: a filter is a name-based contract, so `status=3` is an error even though `Enum.TryParse` would accept it and `3` is a real member. The `correlationId`/`executionId`/`parentExecutionId`/date dimensions stay **lax** (unparseable values are dropped).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user