Skip to content

Commit

Permalink
fix: properly move maps & lists to expression paths
Browse files Browse the repository at this point in the history
fix: set tenant when running authorization queries

closes: #812
  • Loading branch information
zachdaniel committed Dec 23, 2023
1 parent bb5aa43 commit 0f8bb66
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/ash/api/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ defmodule Ash.Api do
{:ok, true}
end

%Ash.Changeset{data: data, action_type: type, resource: resource}
%Ash.Changeset{data: data, action_type: type, resource: resource, tenant: tenant}
when type in [:update, :destroy] ->
pkey = Ash.Resource.Info.primary_key(resource)
pkey_value = Map.take(data, pkey)
Expand All @@ -1061,6 +1061,7 @@ defmodule Ash.Api do
else
query
|> Ash.Query.do_filter(pkey_value)
|> Ash.Query.set_tenant(tenant)
|> Ash.Query.data_layer_query()
|> case do
{:ok, data_layer_query} ->
Expand Down
9 changes: 9 additions & 0 deletions lib/ash/filter/filter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3463,6 +3463,15 @@ defmodule Ash.Filter do
%__MODULE__{expression: expression} = filter ->
%{filter | expression: move_to_relationship_path(expression, relationship_path)}

list when is_list(list) ->
Enum.map(list, &move_to_relationship_path(&1, relationship_path))

value when is_map(value) and not is_struct(value) ->
Map.new(value, fn {key, value} ->
{move_to_relationship_path(key, relationship_path),
move_to_relationship_path(value, relationship_path)}
end)

other ->
other
end
Expand Down

0 comments on commit 0f8bb66

Please sign in to comment.