mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
improvement: add actor_present
policy
This commit is contained in:
parent
fe12f40056
commit
8a2208601c
3 changed files with 20 additions and 2 deletions
13
lib/ash/policy/check/actor_present.ex
Normal file
13
lib/ash/policy/check/actor_present.ex
Normal 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
|
|
@ -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}
|
||||||
|
|
|
@ -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}
|
||||||
|
|
Loading…
Reference in a new issue