mirror of
https://github.com/ash-project/ash.git
synced 2024-09-21 05:53:06 +12:00
2ca0f09444
improvement: add `loading/1` built in check
37 lines
659 B
Elixir
37 lines
659 B
Elixir
defmodule Ash.Test.Support.PolicySimple.Trip do
|
|
@moduledoc false
|
|
use Ash.Resource,
|
|
data_layer: Ash.DataLayer.Ets,
|
|
authorizers: [
|
|
Ash.Policy.Authorizer
|
|
]
|
|
|
|
ets do
|
|
private?(true)
|
|
end
|
|
|
|
policies do
|
|
policy action_type(:read) do
|
|
authorize_if(expr(car.users.id == ^actor(:id)))
|
|
end
|
|
|
|
policy action(:cant_load_car) do
|
|
forbid_if loading(:car)
|
|
authorize_if always()
|
|
end
|
|
end
|
|
|
|
actions do
|
|
defaults [:create, :read, :update, :destroy]
|
|
|
|
read :cant_load_car
|
|
end
|
|
|
|
attributes do
|
|
uuid_primary_key(:id)
|
|
end
|
|
|
|
relationships do
|
|
belongs_to(:car, Ash.Test.Support.PolicySimple.Car)
|
|
end
|
|
end
|