fix: fix changing_attributes check implementation

This commit is contained in:
Zach Daniel 2024-03-29 17:31:26 -04:00
parent a7c865ed20
commit 2ef23840cc
2 changed files with 17 additions and 7 deletions

View file

@ -38,24 +38,24 @@ defmodule Ash.Policy.Check.ChangingAttributes do
{{:ok, from}, {:ok, to}} ->
if expr == true do
{:cont, expr(not (^ref(attribute) == ^from and ^atomic_ref(attribute) == ^to))}
{:cont, expr(^ref(attribute) == ^from and ^atomic_ref(attribute) == ^to)}
else
{:cont,
expr(^expr and not (^ref(attribute) == ^from and ^atomic_ref(attribute) == ^to))}
expr(^expr and ^ref(attribute) == ^from and ^atomic_ref(attribute) == ^to)}
end
{{:ok, from}, :error} ->
if expr == true do
{:cont, expr(^ref(attribute) != ^from)}
{:cont, expr(^ref(attribute) == ^from)}
else
{:cont, expr(^expr and ^ref(attribute) != ^from)}
{:cont, expr(^expr and ^ref(attribute) == ^from)}
end
{:error, {:ok, to}} ->
if expr == true do
{:cont, expr(^atomic_ref(attribute) != ^to)}
{:cont, expr(^atomic_ref(attribute) == ^to)}
else
{:cont, expr(^expr and ^atomic_ref(attribute) != ^to)}
{:cont, expr(^expr and ^atomic_ref(attribute) == ^to)}
end
end
else

View file

@ -108,8 +108,18 @@ defmodule Ash.Policy.FilterCheck do
defp try_eval(expression, %{
resource: resource,
changeset: %Ash.Changeset{action_type: :create} = changeset
changeset: %Ash.Changeset{action_type: :create} = changeset,
actor: actor
}) do
expression =
Ash.Expr.fill_template(
expression,
actor,
changeset.arguments,
changeset.context,
changeset
)
case Ash.Filter.hydrate_refs(expression, %{
resource: resource,
unknown_on_unknown_refs?: true,