ash-project / ash

A declarative, extensible framework for building Elixir applications.
https://www.ash-hq.org
MIT License
1.63k stars 216 forks source link

Allow to read applying another non-read policy #729

Open pierrelegall opened 1 year ago

pierrelegall commented 1 year ago

Problem

Sometimes, we want to read data applying another non-read policy, e.g. to read posts updatable by an actor.

For now, we have to create a special read action (e.g. :read_updatable) and copy the policy of the corresponding action (e.g. of the :update here).

Solution

This could be solved by adding a policy option to the reads function (Api.read, Api.exists?, Api.sum, etc.) to apply a specific policy.

And using it like:

MyResource
|> Api.read!(actor: actor, policy: :update)

Alternative

Won't do, to complicate to propagate a different non-read policy and suggest the workaround above.

zachdaniel commented 1 year ago

When we add bulk destroys this will likely be implementable as a modification of that.