mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
fix: fix changing_attributes
check implementation
This commit is contained in:
parent
a7c865ed20
commit
2ef23840cc
2 changed files with 17 additions and 7 deletions
|
@ -38,24 +38,24 @@ defmodule Ash.Policy.Check.ChangingAttributes do
|
||||||
|
|
||||||
{{:ok, from}, {:ok, to}} ->
|
{{:ok, from}, {:ok, to}} ->
|
||||||
if expr == true do
|
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
|
else
|
||||||
{:cont,
|
{: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
|
end
|
||||||
|
|
||||||
{{:ok, from}, :error} ->
|
{{:ok, from}, :error} ->
|
||||||
if expr == true do
|
if expr == true do
|
||||||
{:cont, expr(^ref(attribute) != ^from)}
|
{:cont, expr(^ref(attribute) == ^from)}
|
||||||
else
|
else
|
||||||
{:cont, expr(^expr and ^ref(attribute) != ^from)}
|
{:cont, expr(^expr and ^ref(attribute) == ^from)}
|
||||||
end
|
end
|
||||||
|
|
||||||
{:error, {:ok, to}} ->
|
{:error, {:ok, to}} ->
|
||||||
if expr == true do
|
if expr == true do
|
||||||
{:cont, expr(^atomic_ref(attribute) != ^to)}
|
{:cont, expr(^atomic_ref(attribute) == ^to)}
|
||||||
else
|
else
|
||||||
{:cont, expr(^expr and ^atomic_ref(attribute) != ^to)}
|
{:cont, expr(^expr and ^atomic_ref(attribute) == ^to)}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
@ -108,8 +108,18 @@ defmodule Ash.Policy.FilterCheck do
|
||||||
|
|
||||||
defp try_eval(expression, %{
|
defp try_eval(expression, %{
|
||||||
resource: resource,
|
resource: resource,
|
||||||
changeset: %Ash.Changeset{action_type: :create} = changeset
|
changeset: %Ash.Changeset{action_type: :create} = changeset,
|
||||||
|
actor: actor
|
||||||
}) do
|
}) do
|
||||||
|
expression =
|
||||||
|
Ash.Expr.fill_template(
|
||||||
|
expression,
|
||||||
|
actor,
|
||||||
|
changeset.arguments,
|
||||||
|
changeset.context,
|
||||||
|
changeset
|
||||||
|
)
|
||||||
|
|
||||||
case Ash.Filter.hydrate_refs(expression, %{
|
case Ash.Filter.hydrate_refs(expression, %{
|
||||||
resource: resource,
|
resource: resource,
|
||||||
unknown_on_unknown_refs?: true,
|
unknown_on_unknown_refs?: true,
|
||||||
|
|
Loading…
Reference in a new issue