ash/test/support/policy_simple/resources/car.ex

39 lines
801 B
Elixir
Raw Normal View History

2022-07-22 02:19:47 +12:00
defmodule Ash.Test.Support.PolicySimple.Car do
@moduledoc false
use Ash.Resource,
data_layer: Ash.DataLayer.Ets,
authorizers: [Ash.Policy.Authorizer]
ets do
private?(true)
end
actions do
defaults [:read, :update, :destroy]
create :create do
primary? true
argument(:users, {:array, :uuid})
change(manage_relationship(:users, type: :replace))
end
end
attributes do
uuid_primary_key(:id)
end
policies do
policy always() do
authorize_if(expr(users.id == ^actor(:id)))
end
end
relationships do
2022-07-22 02:19:47 +12:00
many_to_many :users, Ash.Test.Support.PolicySimple.User do
through(Ash.Test.Support.PolicySimple.CarUser)
source_field_on_join_table(:car_id)
destination_field_on_join_table(:user_id)
end
end
end