2023-06-23 04:28:39 +12:00
|
|
|
defmodule Ash.Test.Support.PolicyField.User do
|
2023-06-23 06:19:40 +12:00
|
|
|
@moduledoc false
|
2023-06-23 04:28:39 +12:00
|
|
|
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 :role, :atom do
|
|
|
|
constraints one_of: [:user, :representative]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
policies do
|
|
|
|
policy always() do
|
|
|
|
authorize_if always()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
field_policies do
|
|
|
|
field_policy :role do
|
|
|
|
authorize_if actor_attribute_equals(:role, :representative)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|