Skip to content

feat: clarity integration for interactive permission exploration#7

Open
barnabasJ wants to merge 1 commit intoclaude/fervent-bhabha-f3e38ffrom
claude/interesting-montalcini-4c990b
Open

feat: clarity integration for interactive permission exploration#7
barnabasJ wants to merge 1 commit intoclaude/fervent-bhabha-f3e38ffrom
claude/interesting-montalcini-4c990b

Conversation

@barnabasJ
Copy link
Copy Markdown

Summary

Stacked on top of #6. Adds an optional Clarity integration that surfaces AshGrant in the Clarity LiveView dashboard, so developers can navigate scopes/grants/field groups as first-class graph vertices and explore permissions interactively as a specific actor.

  • Vertices: Scope, Grant, FieldGroup — implement Clarity.Vertex plus the tooltip / graph-group / shape / source-location providers.
  • Introspectors: hook into Clarity.Vertex.Ash.Resource and Clarity.Vertex.Ash.Domain, emit the new vertices via AshGrant.Info / AshGrant.Domain.Info.
  • Content tabs: markdown overviews on resource + domain (resolver, scopes, grants, field groups, available permission strings) and detail pages per new vertex type.
  • Actor explorer (LiveView): accepts an actor id, calls AshGrant.Introspect.actor_permissions_by_id/3 to show allow/deny per action, and drills into AshGrant.Introspect.explain_by_identifier/1 for the full AshGrant.Explanation.to_string/2 output. Maps :actor_loader_not_implemented, :actor_not_found, and anonymous-resolver cases to inline banners.
  • Lensmaker: contributes a dedicated "Permissions" lens and enhances the built-in "Security" lens to admit the new vertex types.

Every module is wrapped in Code.ensure_loaded(Clarity) + Code.ensure_loaded(Phoenix.LiveView) guards, so AshGrant continues to compile and run unchanged when Clarity is absent. When consumers add both libraries to their app the integration activates automatically.

Dependency wiring

Published Clarity 0.4 requires igniter ~> 0.6.25, which conflicts with ash_grant's locked igniter 0.7.9. To keep hex releases unblocked, Clarity is declared through a CLARITY_VERSION env-var escape hatch (same shape as the existing ASH_VERSION / SPARK_VERSION helpers):

CLARITY_VERSION=local CLARITY_LOCAL_PATH=/path/to/clarity mix test
CLARITY_VERSION=0.4 mix deps.get

End-user consumers don't touch the env var — they add {:clarity, ...} to their own mix.exs, and the guards take care of the rest.

Test plan

  • mix compile succeeds with and without Clarity present
  • Full suite without Clarity: 1126 tests, 0 failures
  • Full suite with Clarity (CLARITY_VERSION=local): 1153 tests, 0 failures (+27 new)
  • New tests cover introspector emission, static markdown rendering, LiveView mount + event handlers (including resolver error paths), and lens enhancement

Optional Clarity integration that surfaces AshGrant's DSL in the Clarity
LiveView dashboard:

- Vertex types for scopes, grants, and field groups — rendered as first-class
  nodes beneath their resource/domain with tooltips, source locations, and
  group labels.
- Introspectors that emit those vertices for every AshGrant-enabled resource
  and AshGrant.Domain-configured domain.
- Static markdown content tabs — resource/domain permissions overview plus
  a detail page per new vertex type.
- LiveView actor explorer on resources: enter an actor id to see every
  action's allow/deny status, click "explain" to render the full
  AshGrant.Explanation output. Maps resolver errors
  (:actor_loader_not_implemented, :actor_not_found) to inline banners.
- Lensmaker that contributes a "Permissions" lens and enhances the built-in
  "Security" lens to include AshGrant vertex types.

Clarity is declared optionally via the CLARITY_VERSION environment variable
so our published hex dep keeps working with igniter 0.7; consumers who use
both libraries activate the integration via the Code.ensure_loaded guards.
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