ash-project / ash-project/ash

Support methods around field policies

Open
#918 6 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Elixir
Stars
2.5k
Forks
422
Avg merge
23h 26m
Merged PRs (30d)
46

Description

**Is your feature request related to a problem? Please describe.**

I think we discussed this a while ago but I couldn't find a record of an issue I'd created to track it. So here it is!

It would be awesome if there was some support functionality around field policies, to make them really usable within an application.

The scenario I was thinking of was -

eg. I have a resource like `Album` and a user is allowed to edit the album, but not the `cover_image_url` field.

So ideally I could -

- show the form to edit the resource, but wrap individual field rendering in a `can?` check to only show the field if the user is allowed to edit it

- have some kind of helper either before/after form submission, that strips fields that the user can't edit if they happen to be present? At the moment, field policies don't seem to do anything here, I did some quick testing with a field policy setup like this -

```elixir
field_policies do
field_policy :* do
authorize_if always()
end

field_policy :cover_image_url do
authorize_unless action_type(:update)
end
end
```

And my user was still able to submit a form to update the album, including updating the `cover_image_url` field.

Alternatively, returning a forbidden error in this scenario would be okay I think.

Contributor guide

Open the contributing guide

Research direction

No file or test entry point is named. Start by tracing how the `field_policies` DSL handles update submissions and how field authorization is evaluated for the `Album` example. Done should mean an unauthorized `cover_image_url` update is prevented, either by stripping it or returning a forbidden error, while permitted fields still update.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
authorization, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.