You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a handle_authorize hook which is executed on all actions (before anything).
This way I can simply add authorization on the record that's properly
loaded and scoped by ja_resource for all routes at once.
Show, delete and update will call the method with the actual model to be
operated on (but before anything is done to the model!). index and create
actions will pass in the model() module instead (since we're operating
on a collection/adding a record not yet in the db).
This was intended for integration with bodyguard. I had to do the
following:
def records(conn) do
scope(conn, model())
end
# this solves the auth for show, update and delete (but not index or create)
def record(conn, id) do
r = super(conn, id)
authorize!(conn, r, policy: Midori.Bot.Policy)
r
end
def handle_index(conn, attributes) do
authorize!(conn, Bot)
super(conn, attributes)
end
def handle_create(conn, attributes) do
authorize!(conn, Bot)
super(conn, attributes)
end
I wanted a solution that would take care of index and create as well,
because having to do it manually action by action is error-prone.
0 commit comments