-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
countable_actions.ex
37 lines (33 loc) · 1.04 KB
/
countable_actions.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
defmodule Ash.Resource.Verifiers.CountableActions do
@moduledoc """
Ensures that countable paginated actions do not exist for resources that are not countable
"""
use Spark.Dsl.Verifier
alias Spark.Dsl.Verifier
# sobelow_skip ["DOS.BinToAtom"]
def verify(dsl_state) do
dsl_state
|> Verifier.get_entities([:actions])
|> Enum.filter(fn action ->
action.type == :read && action.pagination && action.pagination.countable
end)
|> case do
[] ->
:ok
[action | _] ->
data_layer = Verifier.get_persisted(dsl_state, :data_layer)
resource = Verifier.get_persisted(dsl_state, :module)
if data_layer && data_layer.can?(resource, {:query_aggregate, :count}) do
:ok
else
{:error,
Spark.Error.DslError.exception(
module: resource,
path: [:actions, action.name],
message:
"Action cannot be countable, as the datalayer does not support counting queries"
)}
end
end
end
end