AshBilling.Checks.Subscribed (ash_billing v0.7.0)

Copy Markdown View Source

An Ash policy check that authorizes if the current actor has an active billing subscription.

Can be used as a simple check without options, or with a :price option to require a specific tier.

Loaded actors are snapshots: this check does not reload their subscriptions or deletion tombstone. Refresh the actor and its subscriptions at a trusted request or job boundary when revocation freshness matters. Reuse that snapshot for checks within the operation; no extra database query is added to each authorization. This check does not replace ownership or tenant policies on the target resource.

Usage

policies do
  # Authorize any active subscription
  policy action(:generate_report) do
    authorize_if AshBilling.Checks.Subscribed
  end

  # Authorize only users subscribed to a specific price/tier
  policy action(:export_enterprise_data) do
    authorize_if {AshBilling.Checks.Subscribed, price: "price_enterprise_annual"}
  end
end

Options

  • :price - An optional price identifier to require.
  • :domain - The Ash domain to use when lazy-loading subscriptions (defaults to the domain in context).

Summary

Functions

eager_evaluate?()

Callback implementation for Ash.Policy.Check.eager_evaluate?/0.

init(opts)

Callback implementation for Ash.Policy.Check.init/1.

prefer_expanded_description?()

Callback implementation for Ash.Policy.Check.prefer_expanded_description?/0.

requires_original_data?(_, _)

Callback implementation for Ash.Policy.Check.requires_original_data?/2.

strict_check(actor, context, opts)

Callback implementation for Ash.Policy.Check.strict_check/3.

type()

Callback implementation for Ash.Policy.Check.type/0.