PhoenixKitWeb.Actor (phoenix_kit v2.40.1)

Copy Markdown View Source

Who is acting, read from a LiveView socket, a Plug.Conn or an assigns map — the one place modules ask, instead of each reading its own assign.

The admin live_session puts both :phoenix_kit_current_scope and :phoenix_kit_current_user on the socket. The scope is the canonical one (it is what permission checks read), so it wins; the bare user is the fallback for callers that only have that — a test harness, a plain controller. Modules used to pick one or the other, so the same action could log an actor in one module and none in the next.

PhoenixKit.Activity.log("crm", "crm.company_updated",
  PhoenixKitWeb.Actor.opts(socket) ++ [resource_uuid: company.uuid])

Summary

Types

Anything that knows who is acting.

Functions

[actor_uuid: uuid] for a context call that logs, or [] when nobody is signed in — so it can be appended to other options as is.

The name of the role the user is acting as (not PII), or nil — for audit metadata that wants to say which role acted. With the role switcher on, that is the active role, not the always-on roles that ride along with it; otherwise the first role held.

The acting user's uuid, or nil when nobody is signed in.

Types

source()

Anything that knows who is acting.

Functions

opts(source)

@spec opts(source()) :: keyword()

[actor_uuid: uuid] for a context call that logs, or [] when nobody is signed in — so it can be appended to other options as is.

role(scope)

@spec role(source()) :: String.t() | nil

The name of the role the user is acting as (not PII), or nil — for audit metadata that wants to say which role acted. With the role switcher on, that is the active role, not the always-on roles that ride along with it; otherwise the first role held.

uuid(assigns)

@spec uuid(source()) :: String.t() | nil

The acting user's uuid, or nil when nobody is signed in.

PhoenixKitWeb.Actor.uuid(socket)
PhoenixKitWeb.Actor.uuid(conn)
PhoenixKitWeb.Actor.uuid(scope)
PhoenixKitWeb.Actor.uuid(%{phoenix_kit_current_user: user})