AshParc.RequestBuilder (ash_parc v0.1.0)

Copy Markdown View Source

Builds a Parc.Request from an Ash.Policy.Authorizer context wrapped changeset, query, or action input. This is the request construction half of the AshParc adapter.

Requests carry the raw Ash shared context untouched, leaving vetting to a pipeline step. The AshParc.ResetAshContext preparer may be used to uplift policy-trusted keys and drop the rest, so the decider never sees raw framework context.

Summary

Functions

Builds the Parc.Request for an Ash policy evaluation. Raises ArgumentError when context carries no recognized subject (changeset, query, or action input).

Functions

build(actor, context, opts)

@spec build(term(), map(), keyword()) :: Parc.Request.t()

Builds the Parc.Request for an Ash policy evaluation. Raises ArgumentError when context carries no recognized subject (changeset, query, or action input).

The actor becomes the request principal; the Ash subject maps onto the rest:

  • request.action.arguments: the action arguments named by the :arguments option (a list of names, default none).
  • request.resource.attributes: the instance attributes named by the :attributes option, read from the record's pre-change values; only on an update or destroy, nil otherwise.
  • request.context.ash_context: the raw Ash shared context.
  • request.context.tenant: the subject's tenant.
  • request.context.<key>: each :context projection, an argument or instance attribute lifted under its normalized key (an attribute source resolves only on update/destroy, nil otherwise).