From 8a2208601c79bbed7c7ff9e3d68683dade3c8a41 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Sun, 7 Aug 2022 01:16:50 -0400 Subject: [PATCH] improvement: add `actor_present` policy --- lib/ash/policy/check/actor_present.ex | 13 +++++++++++++ lib/ash/policy/check/built_in_checks.ex | 5 +++++ lib/ash/query/function/contains.ex | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 lib/ash/policy/check/actor_present.ex diff --git a/lib/ash/policy/check/actor_present.ex b/lib/ash/policy/check/actor_present.ex new file mode 100644 index 00000000..b35fa0e2 --- /dev/null +++ b/lib/ash/policy/check/actor_present.ex @@ -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 diff --git a/lib/ash/policy/check/built_in_checks.ex b/lib/ash/policy/check/built_in_checks.ex index e9bca17b..df318a89 100644 --- a/lib/ash/policy/check/built_in_checks.ex +++ b/lib/ash/policy/check/built_in_checks.ex @@ -21,6 +21,11 @@ defmodule Ash.Policy.Check.BuiltInChecks do {Ash.Policy.Check.Action, action: action} 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" def selecting(attribute) do {Ash.Policy.Check.Selecting, attribute: attribute} diff --git a/lib/ash/query/function/contains.ex b/lib/ash/query/function/contains.ex index 71ddbc43..51bf7ff7 100644 --- a/lib/ash/query/function/contains.ex +++ b/lib/ash/query/function/contains.ex @@ -19,10 +19,10 @@ defmodule Ash.Query.Function.Contains do def args, do: [ - [:string, :string], [:ci_string, :ci_string], [:string, :ci_string], - [:ci_string, :string] + [:ci_string, :string], + [:string, :string] ] def evaluate(%{arguments: [nil, _]}), do: {:known, false}