AshHooks.Tenancy (AshHooks v3.3.0)

Copy Markdown View Source

Validates an operation's resource modules against a tenant.

resolve/2 takes the resource modules an entry point touches and the tenant:

  • If none declares multitenancy, the tenant passes through unchanged.
  • If all declare attribute multitenancy on the same attribute with global?: false, a tenant is required. Missing tenants return {:error, :tenant_required}.
  • Mixed declarations, different tenant attributes, context multitenancy, or global?: true return {:error, :tenancy_mismatch}.

Entry points supply every resource they read or write, including optional event-log and attempt-history resources. They reject missing or mismatched tenancy before data access. Event-log replay forwards its tenant to resend when rearming an existing terminal delivery.

Summary

Types

Errors returned when the supplied resource set or tenant is invalid.

Functions

Recovers the tenant from a stored row using its resource's tenant_from_attribute callback. Resources without attribute multitenancy return nil. Use this value for tenant options and custody canonicalization.

Validates the resources an operation touches against the caller's tenant.

Types

error()

@type error() :: :tenant_required | :tenancy_mismatch

Errors returned when the supplied resource set or tenant is invalid.

Functions

from_row(row)

@spec from_row(struct()) :: term()

Recovers the tenant from a stored row using its resource's tenant_from_attribute callback. Resources without attribute multitenancy return nil. Use this value for tenant options and custody canonicalization.

resolve(modules, tenant)

@spec resolve([module()], term()) :: {:ok, term()} | {:error, error()}

Validates the resources an operation touches against the caller's tenant.

modules is the caller-supplied resource set. Only these modules are checked. tenant is the caller-supplied tenant, or nil when absent.