diff --git a/lib/resource/transformers/create_version_resource.ex b/lib/resource/transformers/create_version_resource.ex index 90ea70a..c4c5abc 100644 --- a/lib/resource/transformers/create_version_resource.ex +++ b/lib/resource/transformers/create_version_resource.ex @@ -20,18 +20,6 @@ defmodule AshPaperTrail.Resource.Transformers.CreateVersionResource do |> Ash.Resource.Info.attributes() |> Enum.filter(&(&1.name in attributes_as_attributes)) - accept = - [ - :version_action_type, - if(store_action_name?, do: :version_action_name, else: nil), - attributes |> Enum.map(& &1.name), - :version_source_id, - :changes, - belongs_to_actors |> Enum.map(&:"#{&1.name}_id") - ] - |> List.flatten() - |> Enum.reject(&is_nil/1) - sensitive_changes? = dsl_state |> Ash.Resource.Info.attributes() @@ -56,6 +44,28 @@ defmodule AshPaperTrail.Resource.Transformers.CreateVersionResource do multitenant? = not is_nil(Ash.Resource.Info.multitenancy_strategy(dsl_state)) + accept = + [ + :version_action_type, + if(store_action_name?, do: :version_action_name, else: nil), + attributes |> Enum.map(& &1.name), + :version_source_id, + :changes, + belongs_to_actors |> Enum.map(&:"#{&1.name}_id") + ] + |> List.flatten() + |> Enum.reject(&is_nil/1) + |> then(fn accept -> + case multitenant? do + true -> + multitenancy_attribute = Ash.Resource.Info.multitenancy_attribute(dsl_state) + accept |> Enum.reject(&(&1 == multitenancy_attribute)) + + false -> + accept + end + end) + mixin = case AshPaperTrail.Resource.Info.mixin(dsl_state) do {m, f, a} -> diff --git a/test/ash_paper_trail_test.exs b/test/ash_paper_trail_test.exs index b732810..4ddc3ea 100644 --- a/test/ash_paper_trail_test.exs +++ b/test/ash_paper_trail_test.exs @@ -12,10 +12,11 @@ defmodule AshPaperTrailTest do } describe "operations over resource api" do test "creates work as normal" do - assert %{subject: "subject", body: "body"} = + assert %{subject: "subject", body: "body", tenant: "acme"} = Posts.Post.create!(@valid_attrs, tenant: "acme") - assert [%{subject: "subject", body: "body"}] = Posts.Post.read!(tenant: "acme") + assert [%{subject: "subject", body: "body", tenant: "acme"}] = + Posts.Post.read!(tenant: "acme") end test "updates work as normal" do diff --git a/test/support/posts/post.ex b/test/support/posts/post.ex index 5e9ba9f..9ffc3ae 100644 --- a/test/support/posts/post.ex +++ b/test/support/posts/post.ex @@ -54,7 +54,7 @@ defmodule AshPaperTrail.Test.Posts.Post do uuid_primary_key :id, writable?: true attribute :tenant, :string do - public? true + allow_nil? false end attribute :subject, :string do