From 2133e9b31bf07e8b08c1c35a88f3a81ec41f75fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kenneth=20Kostre=C5=A1evi=C4=87?= Date: Fri, 14 Feb 2025 13:09:21 +0100 Subject: [PATCH] fix: Missing actor on aggregate call (#1793) * 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 --- lib/ash/actions/read/read.ex | 2 +- lib/ash/filter/filter.ex | 1 + test/actions/calculations_referencing_aggregates_test.exs | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ash/actions/read/read.ex b/lib/ash/actions/read/read.ex index c4c4fbf75..3c30b7ceb 100644 --- a/lib/ash/actions/read/read.ex +++ b/lib/ash/actions/read/read.ex @@ -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, diff --git a/lib/ash/filter/filter.ex b/lib/ash/filter/filter.ex index 0a41f6b0d..d3b362842 100644 --- a/lib/ash/filter/filter.ex +++ b/lib/ash/filter/filter.ex @@ -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? diff --git a/test/actions/calculations_referencing_aggregates_test.exs b/test/actions/calculations_referencing_aggregates_test.exs index a162fc2cb..1e1b559d0 100644 --- a/test/actions/calculations_referencing_aggregates_test.exs +++ b/test/actions/calculations_referencing_aggregates_test.exs @@ -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 @@ -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()