mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
chore: wrap up private attribtue acceptance feature
This commit is contained in:
parent
b1c7c01701
commit
ae5a9609ac
2 changed files with 11 additions and 21 deletions
|
@ -1822,8 +1822,8 @@ defmodule Ash.Changeset do
|
|||
argument = get_action_argument(action, name) ->
|
||||
do_set_argument(changeset, argument.name, value, true)
|
||||
|
||||
attr = Ash.Resource.Info.public_attribute(changeset.resource, name) ->
|
||||
if attr.writable? do
|
||||
attr = Ash.Resource.Info.attribute(changeset.resource, name) ->
|
||||
if attr.writable? && attr.name in changeset.action.accept do
|
||||
do_change_attribute(changeset, attr.name, value, true)
|
||||
else
|
||||
cond do
|
||||
|
|
|
@ -7,29 +7,22 @@ defmodule Ash.Resource.Verifiers.ValidateAccept do
|
|||
|
||||
@impl true
|
||||
def verify(dsl_state) do
|
||||
{public_attributes, private_attributes} =
|
||||
attributes =
|
||||
dsl_state
|
||||
|> Verifier.get_entities([:attributes])
|
||||
|> Enum.split_with(& &1.public?)
|
||||
|
||||
public_attribute_names = MapSet.new(public_attributes, & &1.name)
|
||||
private_attribute_names = MapSet.new(private_attributes, & &1.name)
|
||||
attribute_names = MapSet.new(attributes, & &1.name)
|
||||
|
||||
initial_errors = %{private: [], not_attribute: []}
|
||||
initial_errors = %{not_attribute: []}
|
||||
|
||||
result =
|
||||
Verifier.get_entities(dsl_state, [:actions])
|
||||
|> Enum.reduce(%{}, fn
|
||||
%{name: action_name, accept: accept}, acc ->
|
||||
validate_attribute_name = fn attribute_name ->
|
||||
cond do
|
||||
MapSet.member?(private_attribute_names, attribute_name) ->
|
||||
:private
|
||||
|
||||
MapSet.member?(public_attribute_names, attribute_name) ->
|
||||
if MapSet.member?(attribute_names, attribute_name) do
|
||||
:ok
|
||||
|
||||
true ->
|
||||
else
|
||||
:not_attribute
|
||||
end
|
||||
end
|
||||
|
@ -38,16 +31,13 @@ defmodule Ash.Resource.Verifiers.ValidateAccept do
|
|||
Enum.reduce(
|
||||
accept,
|
||||
initial_errors,
|
||||
fn attribute, %{private: private, not_attribute: not_attribute} = acc ->
|
||||
fn attribute, %{not_attribute: not_attribute} = acc ->
|
||||
case validate_attribute_name.(attribute) do
|
||||
:ok ->
|
||||
acc
|
||||
|
||||
:private ->
|
||||
%{private: [attribute | private], not_attribute: not_attribute}
|
||||
|
||||
:not_attribute ->
|
||||
%{private: private, not_attribute: [attribute | not_attribute]}
|
||||
%{not_attribute: [attribute | not_attribute]}
|
||||
end
|
||||
end
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue