-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
loading.ex
38 lines (30 loc) · 999 Bytes
/
loading.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
defmodule Ash.Policy.Check.Loading do
@moduledoc "This check is true when the field or relationship, or path to field, is being loaded and false when it is not."
use Ash.Policy.SimpleCheck
require Logger
@impl true
def describe(opts) do
"loading #{opts[:field]}"
end
@impl true
def requires_original_data?(_, _), do: false
@impl true
def match?(_actor, %{query: %Ash.Query{} = query}, opts) do
Logger.warning(
"`loading/1` check is deprecated! Use field policies to secure field access instead."
)
Ash.Query.loading?(query, opts[:field])
end
def match?(_actor, %{changeset: %Ash.Changeset{} = query}, opts) do
Logger.warning(
"`loading/1` check is deprecated! Use field policies to secure field access instead."
)
Ash.Changeset.loading?(query, opts[:field])
end
def match?(_, _, _) do
Logger.warning(
"`loading/1` check is deprecated! Use field policies to secure field access instead."
)
false
end
end