Skip to content

feat: per-key audit log dialog (opt-in) + AuditPinnedFilter primitive#57

Merged
poxet merged 5 commits into
masterfrom
feature/per-key-audit-dialog
Apr 29, 2026
Merged

feat: per-key audit log dialog (opt-in) + AuditPinnedFilter primitive#57
poxet merged 5 commits into
masterfrom
feature/per-key-audit-dialog

Conversation

@poxet
Copy link
Copy Markdown
Contributor

@poxet poxet commented Apr 29, 2026

Summary

Three connected pieces that together let an admin click an API-key row and see the audit history scoped to that specific key — without juggling filters in /developer/audit.

The reusable middle piece (AuditPinnedFilter on <AuditLogView />) also unblocks future audit-for-team / audit-for-user dialogs without further plumbing.

Stack changes

1. Stable per-API-key identifier (Tharga.Team / Tharga.Team.Service)

  • New AuditEntry.CallerKeyId (Guid string of IApiKey.Key)
  • New TeamClaimTypes.ApiKeyId claim emitted by ApiKeyAuthenticationHandler for both team and system keys
  • AuditHelper.BuildEntry reads the claim and populates the entry
  • ApiKeyAuthenticationHandler.LogAuthEvent writes it directly from IApiKey.Key
  • AuditEntryEntity (Mongo) round-trips the field
  • New AuditQuery.CallerKeyId filter applied as Eq in MongoDbAuditLogger.QueryAsync

2. AuditPinnedFilter primitive (Tharga.Team.Blazor)

New public record with the dimensions worth pinning:

public sealed record AuditPinnedFilter
{
    public string CallerKeyId { get; init; }
    public AuditCallerType? CallerType { get; init; }
    public string TeamKey { get; init; }
    public string CallerIdentity { get; init; }
    public string Feature { get; init; }
    public string Action { get; init; }
}

<AuditLogView PinnedFilter=... />:

  • Force-injects pinned values into the AuditQuery (overrides any local filter state)
  • Disables the matching top-bar RadzenSelectBar controls
  • Renders an info banner above the filters showing the pinned scope

3. Opt-in row button (Tharga.Team.Blazor)

<ApiKeyView ShowAuditLogButton="true" />
<SystemApiKeyView ShowAuditLogButton="true" />

[Parameter] bool ShowAuditLogButton defaults to false — existing consumers see no UI change. When on, each row gets a manage_search icon button that opens a wide draggable Radzen dialog (90vw × 85vh, Draggable=true, Resizable=true) hosting <AuditLogView PinnedFilter="@pinned" /> with CallerKeyId + CallerType=ApiKey pinned. Actions column auto-widens by 40px when the button is shown.

4. Sample wiring

Tharga.Platform.Sample enables ShowAuditLogButton="true" on both /api-keys and /system-api-keys so the feature is testable end-to-end.

Tests

8 new (4 service-level — ApiKeyId claim emission for team + system keys, plus shape checks; 4 component-shape — AuditPinnedFilter public surface, [Parameter] declarations on the views and AuditLogView). Full suite: 263 tests passing.

Test plan

  • Build + security checks pass
  • On the sample, click the audit-log button on a row → dialog opens centered, shows the pinned-scope banner, and lists only entries for that key
  • Drag and resize the dialog
  • Disabled top-bar controls show the pinned values

poxet added 5 commits April 29, 2026 15:34
Three connected pieces:

1. Stable per-API-key identifier on every audit entry
   - AuditEntry.CallerKeyId (Guid string of IApiKey.Key)
   - TeamClaimTypes.ApiKeyId claim emitted by ApiKeyAuthenticationHandler
     for both team and system keys
   - AuditHelper.BuildEntry picks up the claim
   - AuditEntryEntity (Mongo) round-trips the field
   - AuditQuery.CallerKeyId + MongoDbAuditLogger.Eq filter

2. AuditPinnedFilter primitive on AuditLogView
   - Public record with CallerKeyId / CallerType / TeamKey /
     CallerIdentity / Feature / Action
   - [Parameter] PinnedFilter on AuditLogView
   - When set, BuildQuery force-injects the pinned values
     (overrides any local _filterX state)
   - Matching top-bar controls render disabled
   - Info banner above the filter row shows the pinned scope so the
     user always sees the context

3. Opt-in row button on ApiKeyView and SystemApiKeyView
   - [Parameter] ShowAuditLogButton (default false) — existing
     consumers see no UI change
   - When true, an additional manage_search button per row opens a
     wide Radzen dialog hosting <AuditLogView> with CallerKeyId +
     CallerType=ApiKey pinned

8 new tests; 263 total passing.
…ositioning

- ApiKeyView: actions column width now computed — base 180px,
  +40 for AdvancedMode (delete), +40 for ShowAuditLogButton
- SystemApiKeyView: actions column 220px → 260px when
  ShowAuditLogButton is on
- Dialog options switched from 'min(1100px, 95vw)' (the CSS min()
  function was being interpreted literally and pushed the dialog
  off-screen) to plain '90vw' / '85vh'. Added Draggable=true so the
  user can move the dialog if needed; Resizable=true was already set.
CodeQL scan ran successfully but upload of SARIF results to GitHub
Code Scanning failed with:
  "Requires authentication ... contents: read, security-events: write"

Workflow-level permissions are set, but the github/codeql-action/analyze
upload step doesn't always pick them up reliably. Add an explicit
permissions block on the security job:
  - contents: read
  - security-events: write
  - actions: read

Matches the recommended setup in the codeql-action README.
@poxet poxet merged commit 5af18e8 into master Apr 29, 2026
4 of 6 checks passed
@poxet poxet deleted the feature/per-key-audit-dialog branch April 29, 2026 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant