mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
54 lines
1.1 KiB
Elixir
54 lines
1.1 KiB
Elixir
defmodule Ash.Test.Support.PolicyField.Ticket do
|
|
@moduledoc false
|
|
use Ash.Resource,
|
|
data_layer: Ash.DataLayer.Ets,
|
|
authorizers: [Ash.Policy.Authorizer]
|
|
|
|
ets do
|
|
private? true
|
|
end
|
|
|
|
actions do
|
|
defaults [:create, :read, :update, :destroy]
|
|
end
|
|
|
|
attributes do
|
|
uuid_primary_key :id
|
|
attribute :internal_status, :string
|
|
attribute :status, :string
|
|
attribute :name, :string
|
|
end
|
|
|
|
relationships do
|
|
belongs_to :representative, Ash.Test.Support.PolicyField.User do
|
|
allow_nil? false
|
|
attribute_writable? true
|
|
end
|
|
|
|
belongs_to :reporter, Ash.Test.Support.PolicyField.User do
|
|
allow_nil? false
|
|
attribute_writable? true
|
|
end
|
|
end
|
|
|
|
policies do
|
|
policy always() do
|
|
authorize_if always()
|
|
end
|
|
end
|
|
|
|
field_policies do
|
|
field_policy :status do
|
|
authorize_if relates_to_actor_via(:representative)
|
|
authorize_if relates_to_actor_via(:reporter)
|
|
end
|
|
|
|
field_policy :internal_status do
|
|
forbid_unless actor_attribute_equals(:role, :representative)
|
|
end
|
|
|
|
field_policy [:name, :reporter_id, :representative_id] do
|
|
authorize_if always()
|
|
end
|
|
end
|
|
end
|