kaffy
kaffy copied to clipboard
[FEATURE-REQUEST] Way to access the conn inside form_fields function
Describe the problem you're proposing to solve Essentially what I want to do is add authorization to different form fields. The current idea is this: There is a way to select user roles and permissions inside kaffy for the User resource. I do not want an admin to be able to alter their own roles or permissions.
So what I would like to do is something like:
def form_fields(conn) do
entry = Map.get(conn.assigns, :entry)
if !is_nil(entry) && conn.assigns.current_user.id == entry.id
[
roles: %{create: :readonly, update: :readonly}
]
else
[
roles: nil # I'd be setting other things but just for example
]
end
end
Describe the solution you'd like conn in the form_fields is easiest. Perhaps there is a cleaner or already implemented way to do this?
Describe alternatives you've considered
I currently block from saving or updating with this check in before_insert
and before_update
, so the actual problem is solved, but this would provide a nicer UI and experience for an admin.
Additional context Really enjoying Kaffy ;)
Hey @pjo336
Thanks for taking the time to submit your feedback and I'm glad you're enjoying Kaffy.
I agree with you that this will provide a better experience for both the admin and for you as a developer.
Work is already being done to include conn
everywhere where it makes sense or could be useful.
I'll leave this open for the time being since it provides good description and workarounds 👍🏼
Will close once this is done and shipped.
I was playing around with this in a fork specifically for the form_fields
function, I think it makes a lot of sense to add it to a lot of places just for additional usefulness. If you'd like any help I could open a PR with the fork and we could discuss where else to add it.
I noticed that conn
is not added in the index/1
function. Is this still in the works to add to various places? I am hoping to get the user off the conn when rendering the index view but perhaps there's a different way to do this