Whether a user has a subscription that gives access now: a policy check for the host's own
resources, and subscribed?/3 for code and templates. Members-only posts and files sold by
plan are its first use.
policies do
policy action(:read_members_post) do
authorize_if {MishkaPay.Ash.Subscribed, resource: MyApp.Pay.Subscription}
end
policy action(:download_pro_file) do
authorize_if {MishkaPay.Ash.Subscribed,
resource: MyApp.Pay.Subscription, product: ["prod_pro", "prod_team"]}
end
endIt reads resource (a kind :subscription resource with belongs_to_user) for a row of the
user with a status that gives access, in one query each time, so a cancel or a failed renewal
the webhooks brought counts at once. The row's user comes from the checkout's owner
(MishkaPay.Ash.Owner).
Options
:resource: the subscription resource. Required.:price,:product: a provider price or product id, or a list of them; the user needs a subscription to one of them. Left out, any subscription counts.:statuses: the statuses that give access,[:active, :trialing]unless named. A trialing row counts until itstrial_end. Add:past_dueto keep access while the provider retries a failed renewal.:tenant: the site, forsubscribed?/3; the check takes the action's tenant. A resource with Ash multitenancy reads in that tenant, any other compares its:tenantattribute.
The check fails closed: no actor, an actor that is not a resource record, or a read that fails, and access is refused.
Summary
Functions
Callback implementation for Ash.Policy.Check.eager_evaluate?/0.
Callback implementation for Ash.Policy.Check.prefer_expanded_description?/0.
Callback implementation for Ash.Policy.Check.requires_original_data?/2.
Callback implementation for Ash.Policy.Check.strict_check/3.
Whether user (a record of the host's user resource, or its id) has a subscription in
resource that gives access now. Takes the options of the check.
Callback implementation for Ash.Policy.Check.type/0.
Functions
Callback implementation for Ash.Policy.Check.eager_evaluate?/0.
Callback implementation for Ash.Policy.Check.prefer_expanded_description?/0.
Callback implementation for Ash.Policy.Check.requires_original_data?/2.
Callback implementation for Ash.Policy.Check.strict_check/3.
@spec subscribed?(Ash.Resource.t(), term(), keyword()) :: boolean()
Whether user (a record of the host's user resource, or its id) has a subscription in
resource that gives access now. Takes the options of the check.
Callback implementation for Ash.Policy.Check.type/0.