AshGrant.Transformers.AddDefaultPolicies (AshGrant v0.14.1)

Copy Markdown View Source

Spark DSL transformer that auto-generates policies when default_policies is enabled.

This transformer runs at compile time and automatically generates the standard AshGrant policy configuration, reducing boilerplate for common use cases.

Configuration

Enable in your resource's ash_grant block:

ash_grant do
  resolver MyApp.PermissionResolver
  default_policies true  # or :all, :read, :write
end

Options

ValueDescription
falseNo policies generated (default)
true or :allGenerate read, write, and generic action policies
:readOnly generate filter_check() policy for read actions
:writeOnly generate check() policy for write and generic actions

Generated Policies

When default_policies: true or :all:

policies do
  policy action_type(:read) do
    authorize_if AshGrant.filter_check()
  end

  policy action_type([:create, :update, :destroy]) do
    authorize_if AshGrant.check()
  end

  policy action_type(:action) do
    authorize_if AshGrant.check()
  end
end

Implementation Details

This transformer:

See Also

Summary

Functions

after_compile?()

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