Skip to content

Commit

Permalink
fix: Missing actor on aggregate call (#1793)
Browse files Browse the repository at this point in the history
* Put actor for read action in aggregate_field_with_related_filters

* Add empty map argument so that options end in options for read in add_aggregate_path_authorization

* Expand aggregates test with actor authorization
  • Loading branch information
ken-kost authored Feb 14, 2025
1 parent dca82c5 commit 2133e9b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/ash/actions/read/read.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3242,7 +3242,7 @@ defmodule Ash.Actions.Read do
Ash.Resource.Info.primary_action!(agg_related_resource, :read).name

with %{valid?: true} = aggregate_query <-
Ash.Query.for_read(agg_related_resource, read_action),
Ash.Query.for_read(agg_related_resource, read_action, %{}, actor: actor),
%{valid?: true} = aggregate_query <-
Ash.Query.Aggregate.build_query(
aggregate_query,
Expand Down
1 change: 1 addition & 0 deletions lib/ash/filter/filter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,7 @@ defmodule Ash.Filter do
Ash.Query.for_read(
last_relationship.destination,
Ash.Resource.Info.primary_action(last_relationship.destination, :read).name,
%{},
actor: actor,
tenant: tenant,
authorize?: authorize?
Expand Down
8 changes: 6 additions & 2 deletions test/actions/calculations_referencing_aggregates_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ defmodule Ash.Test.Actions.CalculationsReferenceAggregatesTest do
defmodule Domain do
use Ash.Domain

authorization do
require_actor? true
end

resources do
resource One
resource Two
Expand All @@ -116,8 +120,8 @@ defmodule Ash.Test.Actions.CalculationsReferenceAggregatesTest do

test "loading calculations that reference aggregates" do
Four
|> Ash.create!(%{})
|> Ash.load!(:total_quantity)
|> Ash.create!(%{}, actor: nil)
|> Ash.load!(:total_quantity, actor: nil)
|> Map.get(:total_quantity)
|> Kernel.==(0)
|> assert()
Expand Down

0 comments on commit 2133e9b

Please sign in to comment.