AshWorkflow.Transformers.AddPolicies (AshWorkflow v0.12.0)

Copy Markdown View Source

Generates Ash policies from workflow step declarations.

Ensures workflow resources function by default when Authorizer is present by injecting five layers of policies:

  1. AshOban bypass — allows Oban-triggered actions (automatic steps, timeouts and every entities) to execute without an actor. Uses AshOban.Checks.AshObanInteraction which only matches when context.private.ash_oban? is true.

  2. Step-level policies — for each manual step with a policy field, generates a policy scoped to that step's transition actions. For example:

    step :review do
      policy actor_attribute_equals(:role, :reviewer)
      transition :approve, to: :done
      transition :reject, to: :rejected
    end

    Generates:

    policy action([:approve, :reject]) do
      authorize_if {Ash.Policy.Check.ActorAttributeEquals, ...}
    end
  3. Signal policies — for each on_signal, a policy scoped to its generated read and transition actions that authorizes signal_in(signals_module, signal), since the listener runs as the emitting actor.

  4. Undo policy — when the workflow declares undo do policy ... end, a policy scoped to the generated :undo action.

  5. Default allow — a catch-all authorize_if always() scoped to workflow transition actions, automatic step actions, timeout actions, every actions, read actions, and user-defined create actions, so workflow initialization and background execution aren't blocked by other policies on the resource.

Skips all policy generation if Authorizer is not configured on the resource.

Summary

Functions

after?(_)

Callback implementation for Spark.Dsl.Transformer.after?/1.

after_compile?()

Callback implementation for Spark.Dsl.Transformer.after_compile?/0.

before?(_)

Callback implementation for Spark.Dsl.Transformer.before?/1.

transform(dsl)

Callback implementation for Spark.Dsl.Transformer.transform/1.