diff --git a/lib/ash/policy/check/changing_attributes.ex b/lib/ash/policy/check/changing_attributes.ex index f5b728f3..c647c55c 100644 --- a/lib/ash/policy/check/changing_attributes.ex +++ b/lib/ash/policy/check/changing_attributes.ex @@ -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 diff --git a/lib/ash/policy/filter_check.ex b/lib/ash/policy/filter_check.ex index fe1d29a2..cee4c22e 100644 --- a/lib/ash/policy/filter_check.ex +++ b/lib/ash/policy/filter_check.ex @@ -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,