diff --git a/lib/resource/changes/create_new_version.ex b/lib/resource/changes/create_new_version.ex index c57f8f7..0e6eb31 100644 --- a/lib/resource/changes/create_new_version.ex +++ b/lib/resource/changes/create_new_version.ex @@ -64,10 +64,11 @@ defmodule AshPaperTrail.Resource.Changes.CreateNewVersion do changeset.resource |> Ash.Resource.Info.attributes() - {input, private} = - resource_attributes - |> Enum.filter(&(&1.name in attributes_as_attributes)) - |> Enum.reduce({%{}, %{}}, &build_inputs(&1, &2, result)) + input = + version_resource_attributes + |> Enum.filter(&(&1 in attributes_as_attributes)) + |> Enum.map(&{&1, Map.get(result, &1)}) + |> Enum.into(%{}) changes = resource_attributes @@ -104,32 +105,11 @@ defmodule AshPaperTrail.Resource.Changes.CreateNewVersion do domain: changeset.domain, skip_unknown_inputs: Map.keys(input) ) - |> Ash.Changeset.force_change_attributes(Map.take(private, version_resource_attributes)) |> Ash.create!(return_notifications?: true) notifications end - defp build_inputs(%{public?: true} = attribute, {input, private}, result) do - { - Map.put( - input, - attribute.name, - Map.get(result, attribute.name) - ), - private - } - end - - defp build_inputs(attribute, {input, private}, result) do - {input, - Map.put( - private, - attribute.name, - Map.get(result, attribute.name) - )} - end - defp build_changes(attributes, :changes_only, changeset, result) do AshPaperTrail.ChangeBuilders.ChangesOnly.build_changes(attributes, changeset, result) end diff --git a/test/support/articles/article.ex b/test/support/articles/article.ex index af4c05a..eca97f6 100644 --- a/test/support/articles/article.ex +++ b/test/support/articles/article.ex @@ -23,7 +23,7 @@ defmodule AshPaperTrail.Test.Articles.Article do end actions do - default_accept :* + default_accept [:*, :body] defaults [:create, :read, :update, :destroy] end @@ -36,7 +36,7 @@ defmodule AshPaperTrail.Test.Articles.Article do end attribute :body, :string do - public? true + public? false allow_nil? false end end