ash/test/support/policy_field/resources/ticket.ex

55 lines
1.1 KiB
Elixir
Raw Normal View History

defmodule Ash.Test.Support.PolicyField.Ticket do
2023-06-23 06:19:40 +12:00
@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