How to use field policies to show/hide fields in a UI?

I am diving into field policies to make some data available for certain subscription plans. When the field returns %ForbiddenField{}, Phoenix HTML doesn't know how to deal with it. What's the best practice for doing this in the UI? The only thing I can think of is to use is_struct(resource.field, Ash.ForbiddenField everywhere.
2 Replies
ZachDaniel
ZachDaniel•4mo ago
Hmm...that is pretty much the way We could add a helper for it maybe
Chaz Watkins
Chaz WatkinsOP•4mo ago
That's what I did when playing around. I'll submit a PR for a helper soon once I settle on a good api for it. Would you like it in Ash or AshPhoenix? I could see it as Ash.field_accessible? and Ash.fields_accessible? or Ash.can_access_field?. Something like that or maybe the helper returns nil if it's forbidden and the value if not hence why I need to think on it a bit 🙂

Did you find this page helpful?