improvement: add actor_present policy

This commit is contained in:
Zach Daniel 2022-08-07 01:16:50 -04:00
parent fe12f40056
commit 8a2208601c
3 changed files with 20 additions and 2 deletions

View file

@ -0,0 +1,13 @@
defmodule Ash.Policy.Check.ActorPresent do
@moduledoc false
use Ash.Policy.SimpleCheck
@impl true
def describe(_) do
"actor is present"
end
@impl true
def match?(nil, _, _opts), do: false
def match?(_, _, _opts), do: true
end

View file

@ -21,6 +21,11 @@ defmodule Ash.Policy.Check.BuiltInChecks do
{Ash.Policy.Check.Action, action: action} {Ash.Policy.Check.Action, action: action}
end end
@doc "This check is true when there is an actor specified, and false when the actor is `nil`"
def actor_present do
Ash.Policy.Check.ActorPresent
end
@doc "This check is true when the field is being selected and false when it is not" @doc "This check is true when the field is being selected and false when it is not"
def selecting(attribute) do def selecting(attribute) do
{Ash.Policy.Check.Selecting, attribute: attribute} {Ash.Policy.Check.Selecting, attribute: attribute}

View file

@ -19,10 +19,10 @@ defmodule Ash.Query.Function.Contains do
def args, def args,
do: [ do: [
[:string, :string],
[:ci_string, :ci_string], [:ci_string, :ci_string],
[:string, :ci_string], [:string, :ci_string],
[:ci_string, :string] [:ci_string, :string],
[:string, :string]
] ]
def evaluate(%{arguments: [nil, _]}), do: {:known, false} def evaluate(%{arguments: [nil, _]}), do: {:known, false}