ash/test/support/policy_simple/resources/car.ex
Zach Daniel 2f3fcbad13 improvement: optimize various solver boolean optimizations
improvement: more comprehensively remove unnecessary clauses
fix: resolve issue with `authorize_unless` and filter checks
improvement: prevent changing attributes and arguments after action validation

We allow for these changes inside of `before_action` calls, but otherwise
require that `force_change_attribute` is used, for example. This prevents
accidentally validating a changeset and then changing an attribute.
2022-11-23 03:39:00 -05:00

46 lines
1,019 B
Elixir

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: :append_and_remove))
end
create :authorize_unless
end
attributes do
uuid_primary_key(:id)
end
policies do
policy action(:authorize_unless) do
authorize_if never()
authorize_unless never()
authorize_if never()
end
policy action_type([:read, :update, :destroy]) do
authorize_if expr(users.id == ^actor(:id))
end
end
relationships do
many_to_many :users, Ash.Test.Support.PolicySimple.User do
through(Ash.Test.Support.PolicySimple.CarUser)
source_attribute_on_join_resource(:car_id)
destination_attribute_on_join_resource(:user_id)
end
end
end