GreenAsh.Actor (GreenAsh v0.3.0)

Copy Markdown View Source

Management of the console's "actor": the Ash record on whose behalf actions are executed (to exercise the policies). Stored in the HTTP session (a LiveView cannot write the session via the socket: see GreenAsh.ActorController) and re-threaded through all Ash calls.

Summary

Functions

Resolves the actor from the session (among domains), or nil.

Short label of the actor for the header (e.g. "Account:1b78…").

Resolves the actor stored in the session.

Functions

from_session(session, domains, tenant \\ nil)

Resolves the actor from the session (among domains), or nil.

Discards the reason a stored actor failed to load; prefer resolve/2, which reports it.

label(record)

Short label of the actor for the header (e.g. "Account:1b78…").

resolve(session, domains, tenant \\ nil)

Resolves the actor stored in the session.

Returns :none when no actor is set, {:ok, record} when it loads, and {:error, message} when an actor is stored but cannot be loaded.

The distinction matters: falling back to no actor without a word makes the console look like it ran as nobody on purpose. Every policy result then reads as a verdict on the policy when it is really a verdict on an actor that was never loaded. Callers are expected to surface message.

session_key()