fix: don't require primary actions if disabled

This commit is contained in:
Zach Daniel 2021-10-19 05:25:33 -04:00
parent 6155af2de1
commit a4fef11c6e

View file

@ -14,6 +14,8 @@ defmodule Ash.Resource.Transformers.SetPrimaryActions do
@extension Ash.Resource.Dsl
def transform(resource, dsl_state) do
primary_actions? = Ash.Resource.Info.primary_actions?(resource)
dsl_state
|> Transformer.get_entities([:actions])
|> Enum.group_by(& &1.type)
@ -48,6 +50,7 @@ defmodule Ash.Resource.Transformers.SetPrimaryActions do
)}}
{type, actions}, {:ok, dsl_state} ->
if primary_actions? && !(primary_actions? == :only_read && type != :read) do
case min(Enum.count(actions, & &1.primary?), 2) do
0 ->
{:halt,
@ -72,6 +75,9 @@ defmodule Ash.Resource.Transformers.SetPrimaryActions do
path: [:actions, type]
)}}
end
else
{:cont, {:ok, dsl_state}}
end
end)
end
end