ash icon indicating copy to clipboard operation
ash copied to clipboard

Allow to read applying another non-read policy

Open pierrelegall opened this issue 2 years ago • 1 comments

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.

pierrelegall avatar Oct 10 '23 11:10 pierrelegall

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

zachdaniel avatar Oct 10 '23 11:10 zachdaniel