fix: evaluate templates to unknown at ref

This commit is contained in:
Zach Daniel 2024-02-14 14:33:45 -05:00
parent f23f0a29fe
commit 1171e9fb03
4 changed files with 21 additions and 9 deletions

View file

@ -109,6 +109,8 @@ defmodule Ash.Error.Forbidden.Policy do
must_pass_strict_check? = must_pass_strict_check? =
if opts[:must_pass_strict_check?] do if opts[:must_pass_strict_check?] do
""" """
Breakdown
Scenario must pass strict check only, meaning `runtime` policies cannot be checked. Scenario must pass strict check only, meaning `runtime` policies cannot be checked.
This requirement is generally used for filtering on related resources, when we can't fetch those This requirement is generally used for filtering on related resources, when we can't fetch those

View file

@ -413,6 +413,15 @@ defmodule Ash.Filter.Runtime do
end end
end end
defp resolve_expr({:_actor, _}, _, _, _, _), do: :unknown
defp resolve_expr({:_arg, _}, _, _, _, _), do: :unknown
defp resolve_expr({:_ref, _}, _, _, _, _), do: :unknown
defp resolve_expr({:_ref, _, _}, _, _, _, _), do: :unknown
defp resolve_expr({:_parent, _}, _, _, _, _), do: :unknown
defp resolve_expr({:_parent, _, _}, _, _, _, _), do: :unknown
defp resolve_expr({:_atomic_ref, _}, _, _, _, _), do: :unknown
defp resolve_expr({:_context, _}, _, _, _, _), do: :unknown
defp resolve_expr( defp resolve_expr(
%Ash.Filter{expression: expression}, %Ash.Filter{expression: expression},
record, record,
@ -720,15 +729,6 @@ defmodule Ash.Filter.Runtime do
end) end)
end end
defp resolve_expr({:_actor, _}, _, _, _, _), do: :unknown
defp resolve_expr({:_arg, _}, _, _, _, _), do: :unknown
defp resolve_expr({:_ref, _}, _, _, _, _), do: :unknown
defp resolve_expr({:_ref, _, _}, _, _, _, _), do: :unknown
defp resolve_expr({:_parent, _}, _, _, _, _), do: :unknown
defp resolve_expr({:_parent, _, _}, _, _, _, _), do: :unknown
defp resolve_expr({:_atomic_ref, _}, _, _, _, _), do: :unknown
defp resolve_expr({:_context, _}, _, _, _, _), do: :unknown
defp resolve_expr(other, _, _, _, _), do: {:ok, other} defp resolve_expr(other, _, _, _, _), do: {:ok, other}
defp try_cast_arguments(:var_args, args) do defp try_cast_arguments(:var_args, args) do

View file

@ -2,6 +2,7 @@ defmodule Ash.Filter.TemplateHelpers do
@moduledoc "Helpers for building filter templates" @moduledoc "Helpers for building filter templates"
@deprecated "Use `expr?/1` instead, which is not a guard" @deprecated "Use `expr?/1` instead, which is not a guard"
defguard is_expr(value) defguard is_expr(value)
when is_struct(value, Ash.Query.Not) or is_struct(value, Ash.Query.BooleanExpression) or when is_struct(value, Ash.Query.Not) or is_struct(value, Ash.Query.BooleanExpression) or
is_struct(value, Ash.Query.Call) or is_struct(value, Ash.Query.Ref) or is_struct(value, Ash.Query.Call) or is_struct(value, Ash.Query.Ref) or
@ -9,6 +10,14 @@ defmodule Ash.Filter.TemplateHelpers do
is_struct(value, Ash.Query.Parent) or is_struct(value, Ash.Query.Parent) or
(is_struct(value) and is_map_key(value, :__predicate__?)) (is_struct(value) and is_map_key(value, :__predicate__?))
def expr?({:_actor, _}), do: true
def expr?({:_arg, _}), do: true
def expr?({:_ref, _, _}), do: true
def expr?({:_parent, _, _}), do: true
def expr?({:_parent, _}), do: true
def expr?({:_atomic_ref, _}), do: true
def expr?({:_context, _}), do: true
def expr?(value) def expr?(value)
when is_struct(value, Ash.Query.Not) or is_struct(value, Ash.Query.BooleanExpression) or when is_struct(value, Ash.Query.Not) or is_struct(value, Ash.Query.BooleanExpression) or
is_struct(value, Ash.Query.Call) or is_struct(value, Ash.Query.Ref) or is_struct(value, Ash.Query.Call) or is_struct(value, Ash.Query.Ref) or

View file

@ -89,6 +89,7 @@ defmodule Ash.Policy.FilterCheckWithContext do
}) do }) do
case Ash.Filter.hydrate_refs(expression, %{ case Ash.Filter.hydrate_refs(expression, %{
resource: resource, resource: resource,
unknown_on_unknown_refs?: true,
aggregates: %{}, aggregates: %{},
calculations: %{}, calculations: %{},
public?: false public?: false