Skip to content

Commit

Permalink
chore: add authorize? to context that is carried through on load
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Nov 5, 2024
1 parent 3fea900 commit e5f0d95
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/ash/query/calculation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ defmodule Ash.Query.Calculation do
type: :any,
doc: "The tenant performing the calculation."
],
authorize?: [
type: :boolean,
doc: "Whether or not authorization is being performed"
],
tracer: [
type: :any,
doc: "The tracer or tracers used in the calculation."
Expand Down Expand Up @@ -98,10 +102,18 @@ defmodule Ash.Query.Calculation do
) do
with {:ok, opts} <- Opts.validate(opts),
{:ok, calc_opts} <- module.init(calc_opts) do
authorize? =
if :authorize? in opts.__set__ do
opts.authorize?
else
opts.source_context[:private][:authorize?]
end

context = %Ash.Resource.Calculation.Context{
arguments: opts.arguments,
type: type,
constraints: constraints,
authorize?: authorize?,
actor: opts.actor || opts.source_context[:private][:actor],
tenant: opts.tenant || opts.source_context[:private][:tenant],
tracer: opts.tracer || opts.source_context[:private][:tracer],
Expand Down

0 comments on commit e5f0d95

Please sign in to comment.