aesmail / aesmail/kaffy

[FEATURE-REQUEST] Way to access the conn inside form_fields function

Aperta
#158 3 commenti 2 reazioni 1 assegnatario Rivendicata da @aesmail Vedi su GitHub
enhancement
Lingua principale
Elixir
Stelle
1.4k
Fork
171
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

**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:

```elixir
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 ;)

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.